[issue28702] Confusing error message when None used in expressions, eg. "'NoneType' object has no attribute 'foo'"

Terry J. Reedy report at bugs.python.org
Fri Nov 18 14:42:22 EST 2016


Terry J. Reedy added the comment:

I have doubts also.

The issue is the same for NotImplemented, though the occurrence is much rarer, and similar for Ellipsis.

>>> NotImplemented.foo
Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    NotImplemented.foo
AttributeError: 'NotImplementedType' object has no attribute 'foo'
>>> Ellipsis.foo
Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    Ellipsis.foo
AttributeError: 'ellipsis' object has no attribute 'foo'

Replacing the type name with the object name works for this message, but not for the type errors.
  TypeError: unsupported operand type(s) for +: 'None' and 'int'
is wrong.

Replacing 'NoneType' with 'None' in error messages will break code that does something like "if 'NoneType' in err.args[0]" in an exception message.  The same replacement would have to be make in user code.  Fortunately, it would continue to work with older versions.

----------
nosy: +terry.reedy
stage:  -> test needed
versions: +Python 3.7 -Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28702>
_______________________________________


More information about the Python-bugs-list mailing list