leosongwei / mutagen

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

easyid3.py module raises ValueError instead of KeyError #48

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
https://bugs.launchpad.net/ubuntu/+source/mutagen/+bug/498610

The module/usr/share/pyshared/mutagen/easyid3.py raises the ValueError
exception instead of the proper KeyError.

Here's an example:
>>> m = EasyID3('Reencarnación - Reencarnación.mp3')
>>> m
{'album': [u'888 Metal'], 'date': [u'1988'], 'artist':
[u'Reencarnaci\xf3n'], 'tracknumber': [u'01'], 'title': [u'Reencarnaci\xf3n
(888 Metal)']}
>>> m['date']
[u'1988']
>>> m['year']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/dist-packages/mutagen/easyid3.py", line 94, in
__getitem__
    else: raise ValueError("%r is not a valid key" % key)
ValueError: 'year' is not a valid key

Original issue reported on code.google.com by JT.doppl...@gmail.com on 1 Jan 2010 at 10:55

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
What you propose would make it nearly impossible for a program to determine if 
a key
was rejected for being missing or for being unsupported. Support varies for keys
across different versions of mutagen.

The current state of play is...

KeyError indicates data not present (read).
ValueError indicates feature not present (read/write).

Original comment by nondicti...@gmail.com on 6 Jan 2010 at 4:01

GoogleCodeExporter commented 9 years ago
I think __getitem__ (and __delitem__) should never be raising a ValueError. A 
missing
key and an unsupported key are identical from the perspective of the getter, 
since an
unsupported key is always missing.

__setitem__ should probably throw a custom subclass of both KeyError and 
ValueError,
for compatibility.

Original comment by joe.wreschnig@gmail.com on 6 Jan 2010 at 4:52

GoogleCodeExporter commented 9 years ago

Original comment by joe.wreschnig@gmail.com on 8 Jan 2010 at 11:16

GoogleCodeExporter commented 9 years ago
In fact my idea was so good I implemented it months ago. The current EasyID3 
module
raises a subclass of KeyError and ValueError, and mutagen.id3.error, for all the
reasons described above.

Original comment by joe.wreschnig@gmail.com on 8 Jan 2010 at 11:20