Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning attributes to typing.NoDefault raises TypeError, but should raise AttributeError #118895

Closed
AlexWaygood opened this issue May 10, 2024 · 0 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-typing type-bug An unexpected behavior, bug, or error

Comments

@AlexWaygood
Copy link
Member

AlexWaygood commented May 10, 2024

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

Linked PRs

@AlexWaygood AlexWaygood added type-bug An unexpected behavior, bug, or error topic-typing 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels May 10, 2024
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue May 10, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 10, 2024
…8897)

(cherry picked from commit 13d7cf9)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
JelleZijlstra added a commit that referenced this issue May 10, 2024
…#118914)

(cherry picked from commit 13d7cf9)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant