-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-35357: Add _mock_ prefix to mangle _Call/_MagicProxy attributes #10873
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
13152f5
to
76a1da6
Compare
Lib/unittest/mock.py
Outdated
self.name = name | ||
self.parent = parent | ||
self._mock_name = name | ||
self._mock_parent = parent |
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.
Not sure this is related. Please can you add a unit test to show why it's needed?
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.
I've just did a deeper check and it looks like leaving it as it was before doesn't break anything - it's just a matter of conforming to the naming. So I believe we can leave it as it is.
Lib/unittest/mock.py
Outdated
entry = self.name | ||
parent = self.parent | ||
entry = self._mock_name | ||
parent = self._mock_parent |
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.
Please can you add a unit test to show why this is needed?
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.
(Removed, see above)
self.from_kall = from_kall | ||
self._mock_name = name | ||
self._mock_parent = parent | ||
self._mock_from_kall = from_kall |
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.
This is the fix I had in mind, but it needs unit tests to show why it's needed.
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.
Done.
@@ -0,0 +1,3 @@ | |||
Internal attributes' names of unittest.mock._Call and | |||
unittest.mock.MagicProxy (name, parent & from_kall) are now prefixed by | |||
_mock_ |
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.
This should describe the why of the change not just the what (in this case, because of the potential name clash)
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.
Done.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
76a1da6
to
8d4390a
Compare
I have made the requested changes; please review again. |
Thanks for making the requested changes! @cjw296: please review the changes made to this pull request. |
@bedevere-bot I knew I heard your name somewhere. |
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.
I'm afraid it looks like you've ended up with some infinite recursion.
I'd suggest rebasing on master and trying the whole test suite for mock.
The test you've added would be better split into a couple of simpler cases; for loops in tests aren't usually a good sign!
@@ -128,7 +128,7 @@ class Multi(SomeClass, Sub): | |||
result.foo.assert_called_once_with(3, 2, 1) | |||
|
|||
|
|||
def test_create_autopsec(self): | |||
def test_create_autospec(self): |
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.
👍
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
…Call/_MagicProxy. Fix minor typo in test function name.
8d4390a
to
e4cd309
Compare
@cjw296 My bad - seems like the upstream has just introduced some code that breaks my fix. I've updated my branch and fixed the naming. Edit: and, yes, I forgot: I have made the requested changes; please review again. |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @cjw296: please review the changes made to this pull request. |
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.
Nice, thanks!
@cjw296: Please replace |
GH-10887 is a backport of this pull request to the 3.7 branch. |
…Call/_MagicProxy. (pythonGH-10873) Fix minor typo in test function name. (cherry picked from commit e63e617) Co-authored-by: Andrew Dunai <andunai@gmail.com>
GH-10888 is a backport of this pull request to the 3.6 branch. |
…Call/_MagicProxy. (pythonGH-10873) Fix minor typo in test function name. (cherry picked from commit e63e617) Co-authored-by: Andrew Dunai <andunai@gmail.com>
@cjw296 Thank you for taking your time! |
No problem, thanks for the contribution :-) |
In python 3.6.8, 3.7.2, and in python-next, some attributes on the unittest.mock.call object were renamed from things like `name` and `parent` to `_mock_name` and `_mock_parent`. resolves simplistix#102 Python bug: * bpo-35357 (https://bugs.python.org/issue35357) pull requests which added this change: * python/cpython#10873 * python/cpython#10887 * python/cpython#10888
As suggested by Chris Withers (cjw296) in https://bugs.python.org/issue35357
Renaming them in MagicProxy didn't seem necessary, but I found it better & less error-prone to make them conform to the
_mock_*
naming style.EDIT: Reverted renames in MagicProxy as they don't need to conform to _Call & Mock namings because they are different things.
https://bugs.python.org/issue35357