You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Insert method in class MetadataList results in an extra None Value in its metadata list
The insert method of MetadataList Class inserts an extra None value into its metadatalists, when e == i. This results in unequal length of metadata and list. Note, when the insert occurs at the end of the iterable, no extra None is inserted.
Bug found while writing 1,000 test cases for a Masters course I'm undertaking, let me know if you want all the tests. :)
Steps to Reproduce (for bugs)
Use the insert method of class MetadataList with a non-zero length MetadataList and insert the item not with the length of the iterable.
Expected Behavior
Only add the metadata for the item being inserted and both lists (metadata and __list) maintain equal length.
Current Behavior
File location is in the root of the project, name doesn't matter for testing purposes.
Initialization
This section is setting up testing that shows the bug.
When the index is 0 (mdl.insert(0, insert_song, insert_song.metadata)), the None Value is at index 1. The inserted object and metadata is in the correct location but the metadata after index 0 is 1 position out.
When the index i is less than the length of the list, i.e. being inserted, the else clause is used; both e and i are set equal e = i.
The line self[i:e] = [item] goes directly into the __setitem__ method and the value is of type list.
This means that metadata = [None] * len(value) line will get hit generating a [None] value.
As the index is a slice object of two equal integers, it will insert the unpacked version of [None] into this list similar to adding two lists but will insert at the given location; the None value is inserted; self.metadata.__setitem__(i, metadata) sets the None value in the Metadata.
When the index is 2 (mdl.insert(2, insert_song, insert_song.metadata)), the None Value is now at index 3. The inserted object is in the correct location but the metadata is 1 position out after index 2. Caused by the same bug as above.
As the metadata list has increased in size by the MetadataList.__setitem__ method being called with self[i:e] = [item], a value of None is in the correct position. It is safe to just use the index value i to change the None to the desired value.
Insert method in class MetadataList results in an extra None Value in its metadata list
The
insert
method of MetadataList Class inserts an extraNone
value into its metadatalists, whene == i
. This results in unequal length of metadata and list. Note, when the insert occurs at the end of the iterable, no extraNone
is inserted.Bug found while writing 1,000 test cases for a Masters course I'm undertaking, let me know if you want all the tests. :)
Steps to Reproduce (for bugs)
Expected Behavior
metadata
and__list
) maintain equal length.Current Behavior
Initialization
This section is setting up testing that shows the bug.
Insert at Beginning
When the index is 0 (
mdl.insert(0, insert_song, insert_song.metadata)
), the None Value is at index 1. The inserted object and metadata is in the correct location but the metadata after index 0 is 1 position out.For reference:
Explanation
The bug is in
self.metadata[i:e] = [metadata]
.When the index
i
is less than the length of the list, i.e. being inserted, the else clause is used; bothe
andi
are set equale = i
.The line
self[i:e] = [item]
goes directly into the__setitem__
method and the value is of type list.This means that
metadata = [None] * len(value)
line will get hit generating a[None]
value.As the index is a slice object of two equal integers, it will insert the unpacked version of
[None]
into this list similar to adding two lists but will insert at the given location; theNone
value is inserted;self.metadata.__setitem__(i, metadata)
sets theNone
value in the Metadata.Return to the
insert
method, again a slice is used to insert the actual metadata value, resulting in:Example Code for Beggining
Insert in the Middle
When the index is 2 (
mdl.insert(2, insert_song, insert_song.metadata)
), the None Value is now at index 3. The inserted object is in the correct location but the metadata is 1 position out after index 2. Caused by the same bug as above.Example Code for Middle
Insert at the End
When the object is inserted at the end i.e. appended, the list is correct.
Possible Solution
As the metadata list has increased in size by the
MetadataList.__setitem__
method being called withself[i:e] = [item]
, a value of None is in the correct position. It is safe to just use the index valuei
to change theNone
to the desired value.Original
Proposed change
Environment
The text was updated successfully, but these errors were encountered: