leosongwei / mutagen

Automatically exported from code.google.com/p/mutagen
GNU General Public License v2.0
0 stars 0 forks source link

ID3: Incorrect __eq__ method in TextFrame class #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is not really causing me any problems, just found this 
while messing with the code.

TextFrame class defines both __str__ and __unicode__ methods.
When compared for equality (using __eq__(self, other) method):
In case other is string:
  It converts itself with str(self) for comparison
In case other is unicode:
  It creates a unicode literal u'\u0000'.join(self.text)
  and uses that for comparison. This identical to what the __unicode__
  method returns and at this point is just a slight code duplication.

But there's trouble when a subclass redefines __unicode__,
which is what TimeStampTextFrame does.

What's even more, because TimeStampTextFrame's text attribute is a list
of ID3TimeStamp objects, it actually raises an exception because join()
expects a list of string or unicode literals.

In effect, comparing an instance of TimeStampTextFrame class or it's
subclasses to a unicode literal raises a TypeError, while comparing
to a string does not.

I've attached an obvious solution of just using unicode(self). Don't
really know how to go about tests, so just added a simple TestCase
subclass, also included in the diff. Should I've incorporated it into a
previous test (perhaps somewhere in TestReadTags?), or maybe was it not
necessary at all?

Original issue reported on code.google.com by nanik...@gmail.com on 19 Dec 2009 at 12:48

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r68.

Original comment by joe.wreschnig@gmail.com on 19 Dec 2009 at 10:06