Currently subscriting a attribute that's None reports the following: >>> class Foo: pass >>> Foo.organizer = None >>> Foo.organizer['start'] Traceback (most recent call last): File "", line 1, in TypeError: 'NoneType' object is not subscriptable What would be nice is if it were to report the name of the attribute that is not subscriptable as it would greatly help in the logs, something like: Traceback (most recent call last): File "", line 1, in TypeError: 'NoneType' object of attribute 'organizer' is not subscriptable just a thought. Otherwise one would need to sprinkle their code with asserts, especially if it's a compound statement like: Foo.organizer.blah[0], you wouldn't know which attribute wasn't None
At the point at which that error is raised, Python doesn't know the name of the attribute, nor is attribute access the only place where that particular error report is triggered (it's in a generic subscript-this-object call). So I doubt doing this would be practical. As for Foo.organizer.blah[0], it has to be blah that is None, since '.organizer' is an attribute access and not a subscript operation. The more difficult case is something like getattr(someobject, somevar)[0], where you can't tell what somevar contains just from the traceback. Which is why some value-added systems also dump the locals from the frame in the traceback.
oh for second example I meant something like this: >>> class Foo: pass >>> Foo.organizer = None >>> Foo.blah = Foo >>> Foo.blah.organizer = None >>> Foo.blah.organizer[0] ya this is just a pie in the sky request :)
I agree that a better message would be nice. But compiling 'a.b[c]' breaks the expression apart into the equivalent of 't=a.b; t[c]', where 't' is an anonymous reference, so as David notes, there is no 'name' left to display. We don't have a 'not possible resoluton, so "won't fix (because not possible)" seems closest.