-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bpo-45756: do not execute @property
descrs while creating mock autospecs
#29901
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
Conversation
I am going to friendly ping @serhiy-storchaka to review this 🙂 |
This comment has been minimized.
This comment has been minimized.
CC @corona10 Maybe you will be interested to review this? 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks!
@@ -0,0 +1,2 @@ | |||
We no longer execute ``@property`` descriptors while creating autospecs in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer execute ``@property`` descriptors while creating autospecs in | |
Fixed :class:`property` decorators executing descriptors while creating autospecs in |
@@ -0,0 +1,2 @@ | |||
We no longer execute ``@property`` descriptors while creating autospecs in | |||
``mock.py``. This was not safe and could affect user's code in unknown way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``mock.py``. This was not safe and could affect user's code in unknown way. | |
:mod:`unittest.mock`. This was not safe and could affect user's code in unknown ways. |
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Is this potentially a breaking change (can some mocks be relying on running a property)? In general, it is a good idea to avoid accidentally running code; however, mocks are advanced case where users are already doing something invasive, and properties are also a special case where programmers are intentionally running behavior upon access. Long ago, In a slightly related issue, it was decided that hasattr() would be left as-is rather than making perhap futile efforts to avoid running a descriptor. |
It is possible. However, the execution of properties by specced mocks was introduced relatively recently (3.8) along with The current PR to fix it is #22209. |
In this PR I am trying to solve this corner case with
inspect.getattr_static
, so atrtibutes won't be actually resolved.I guess
@property
is special enough to skip it there.Any other similar cases, that we would need to fix (probably in the upcoming PRs)?
https://bugs.python.org/issue45756
Related: https://bugs.python.org/issue41768