Skip to content

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

Merged
merged 1 commit into from
Dec 4, 2018

Conversation

and3rson
Copy link
Contributor

@and3rson and3rson commented Dec 3, 2018

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

self.name = name
self.parent = parent
self._mock_name = name
self._mock_parent = parent
Copy link
Contributor

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?

Copy link
Contributor Author

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.

entry = self.name
parent = self.parent
entry = self._mock_name
parent = self._mock_parent
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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_
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@and3rson
Copy link
Contributor Author

and3rson commented Dec 3, 2018

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@cjw296: please review the changes made to this pull request.

@and3rson
Copy link
Contributor Author

and3rson commented Dec 3, 2018

@bedevere-bot I knew I heard your name somewhere.

Copy link
Contributor

@cjw296 cjw296 left a 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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

…Call/_MagicProxy.

Fix minor typo in test function name.
@and3rson and3rson force-pushed the 35357-mock-name-collision branch from 8d4390a to e4cd309 Compare December 3, 2018 23:20
@and3rson
Copy link
Contributor Author

and3rson commented Dec 3, 2018

@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.

@and3rson
Copy link
Contributor Author

and3rson commented Dec 4, 2018

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@cjw296: please review the changes made to this pull request.

Copy link
Contributor

@cjw296 cjw296 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@cjw296 cjw296 merged commit e63e617 into python:master Dec 4, 2018
@bedevere-bot
Copy link

@cjw296: Please replace # with GH- in the commit message next time. Thanks!

@miss-islington
Copy link
Contributor

Thanks @and3rson for the PR, and @cjw296 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington
Copy link
Contributor

Thanks @and3rson for the PR, and @cjw296 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-10887 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 4, 2018
…Call/_MagicProxy. (pythonGH-10873)

Fix minor typo in test function name.
(cherry picked from commit e63e617)

Co-authored-by: Andrew Dunai <andunai@gmail.com>
@bedevere-bot
Copy link

GH-10888 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 4, 2018
…Call/_MagicProxy. (pythonGH-10873)

Fix minor typo in test function name.
(cherry picked from commit e63e617)

Co-authored-by: Andrew Dunai <andunai@gmail.com>
@and3rson
Copy link
Contributor Author

and3rson commented Dec 4, 2018

@cjw296 Thank you for taking your time!

cjw296 pushed a commit that referenced this pull request Dec 4, 2018
…Call/_MagicProxy. (GH-10873) (#10887)

Fix minor typo in test function name.
(cherry picked from commit e63e617)

Co-authored-by: Andrew Dunai <andunai@gmail.com>
cjw296 pushed a commit that referenced this pull request Dec 4, 2018
…Call/_MagicProxy. (GH-10873)

Fix minor typo in test function name.
(cherry picked from commit e63e617)

Co-authored-by: Andrew Dunai <andunai@gmail.com>
@cjw296
Copy link
Contributor

cjw296 commented Dec 4, 2018

No problem, thanks for the contribution :-)

dsalisbury added a commit to dsalisbury/testfixtures that referenced this pull request Jan 2, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants