[Python-ideas] accurate errors for "magic" methods

Georg Brandl g.brandl at gmx.net
Thu Apr 9 19:56:16 CEST 2009

spir schrieb:

> Actually, I'm wrong: it's perfectly clear as long as the programmer is able
> to follow all the necessary reflexion path; then probably also able to solve
> the problem without any help from python.
> The issue here is that a very specific (and meaningful) case (dict-like
> behaviour missing) is adressed using a very generic (and thus helpless)
> message (attributeError).
> I think error cases about "magic" methods, that implement conceptually
> meaningful behaviours, should have appropriate messages. In the case above,
> maybe something like: "Values instance is not an item container (no
> __getitem__ method found)."

The time machine strikes again:

>>> class A(object): pass
>>> A()['a']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'A' object is unsubscriptable

(the difference being that A is new-style, while Values is old-style.)


More information about the Python-ideas mailing list