You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[3.12] Behavior change: __getattr__ gets called after property raises NotImplementedError #103551
(Using getattr(1, ...) there just to have an object in-place; in the real code 1 is actually another object, but the outcome is the same).
Running this in Python 3.11.2 (and previous versions), we get this output:
λ py -3.11 --version
Python 3.11.2
λ py -3.11 .tmp\reproducer.py
--> accessing owner
Traceback (most recent call last):
File "e:\projects\pytest\.tmp\reproducer.py", line 12, in <module>
s.owner
File "e:\projects\pytest\.tmp\reproducer.py", line 5, in owner
raise NotImplementedError("owner not implemented")
NotImplementedError: owner not implemented
NotImplementedError is raised from the property access, and __getattr__ is never called.
In Python 3.12.0a7 however we get:
λ py -3.12 --version
Python 3.12.0a7
λ py -3.12 .tmp\reproducer.py
--> accessing owner
Traceback (most recent call last):
File "e:\projects\pytest\.tmp\reproducer.py", line 12, in <module>
s.owner
File "e:\projects\pytest\.tmp\reproducer.py", line 8, in __getattr__
return getattr(1, "foobar")
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'foobar'
The property is still being accessed (as shown by the print call), but NotImplementedError is being swallowed/ignored, and __getattr__ seems to be getting called as a fallback.
In Python 3.11 the behavior stays the same as before, however in Python 3.12 we now get:
λ py -3.12 .tmp\reproducer.py
--> accessing owner
Traceback (most recent call last):
File "e:\projects\pytest\.tmp\reproducer.py", line 5, in owner
raise NotImplementedError("owner not implemented")
NotImplementedError: owner not implemented
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "e:\projects\pytest\.tmp\reproducer.py", line 12, in <module>
s.owner
File "e:\projects\pytest\.tmp\reproducer.py", line 8, in __getattr__
raise AttributeError("foobar")
^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <class 'AttributeError'> returned a result with an exception set
Activity
AlexWaygood commentedon Apr 14, 2023
This may have already been fixed by #103332; it looks quite similar to the regression test that was added in #103336
sobolevn commentedon Apr 15, 2023
Hi, @nicoddemus 👋
Please, try the latest
main. It should be fixed now. If so, please feel free to close this issue :)nicoddemus commentedon Apr 15, 2023
Thanks!
Indeed I tried on the latest main (2b6f5c3) and it now works the same as Python 3.11.
Closing the issue then, thanks!
AlexWaygood commentedon Apr 15, 2023
Great, thanks for confirming!
add test case for pythongh-103551