Closed
Description
Bug report
Bug description:
Most sentinels in Python raise AttributeError
if you try to assign attributes to them, but typing.NoDefault
raises TypeError
instead. I think this should be AttributeError
, for consistency with other similar objects:
(main) % ./python.exe ~/dev/cpython
Python 3.14.0a0 (heads/main:66f8bb76a1, May 8 2024, 17:00:15) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> None.foo = 'bar'
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
None.foo = 'bar'
^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'foo' and no __dict__ for setting new attributes
>>> NotImplemented.foo = 'bar'
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
NotImplemented.foo = 'bar'
^^^^^^^^^^^^^^^^^^
AttributeError: 'NotImplementedType' object has no attribute 'foo' and no __dict__ for setting new attributes
>>> from typing import NoDefault
>>> NoDefault.foo = 'bar'
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
NoDefault.foo = 'bar'
^^^^^^^^^^^^^
TypeError: 'NoDefaultType' object has no attributes (assign to .foo)
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS