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

bpo-39485: fix corner-case in method-detection of mock #18252

Merged
merged 1 commit into from Jan 29, 2020

Conversation

@cfbolz
Copy link
Contributor

cfbolz commented Jan 29, 2020

As described in the issue, replace check for whether something is a method in the mock module. The
previous version fails on PyPy, because there no method wrappers exist (everything looks like a regular Python-defined function). Thus the isinstance(getattr(result, '__get__', None), MethodWrapperTypes) check returns True for any descriptor, not just methods.

This condition could also return erronously True in CPython for C-defined descriptors.

Instead to decide whether something is a method, just check directly whether it's a function defined on the class. This passes all tests on CPython and fixes the bug on PyPy.

/cc @cjw296

https://bugs.python.org/issue39485

@vstinner

This comment has been minimized.

Copy link
Member

vstinner commented Jan 29, 2020

@cfbolz cfbolz force-pushed the cfbolz:bpo-39485 branch from 7510431 to 8fdd90a Jan 29, 2020
@cfbolz

This comment has been minimized.

Copy link
Contributor Author

cfbolz commented Jan 29, 2020

woops, messed something up, fixing...

Replace check for whether something is a method in the mock module. The
previous version fails on PyPy, because there no method wrappers exist
(everything looks like a regular Python-defined function). Thus the
isinstance(getattr(result, '__get__', None), MethodWrapperTypes) check
returns True for any descriptor, not just methods.

This condition could also return erroneously True in CPython for
C-defined descriptors.

Instead to decide whether something is a method, just check directly
whether it's a function defined on the class. This passes all tests on
CPython and fixes the bug on PyPy.
@cfbolz cfbolz force-pushed the cfbolz:bpo-39485 branch from 8fdd90a to 321f848 Jan 29, 2020
@cfbolz

This comment has been minimized.

Copy link
Contributor Author

cfbolz commented Jan 29, 2020

better now

@cjw296 cjw296 self-assigned this Jan 29, 2020
@cjw296 cjw296 self-requested a review Jan 29, 2020
@cjw296
cjw296 approved these changes Jan 29, 2020
@cjw296 cjw296 merged commit a327677 into python:master Jan 29, 2020
9 checks passed
9 checks passed
Docs
Details
Windows (x86)
Details
Windows (x64)
Details
macOS
Details
Ubuntu
Details
Azure Pipelines PR #20200129.31 succeeded
Details
bedevere/issue-number Issue number 39485 found
Details
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Jan 29, 2020

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

miss-islington added a commit to miss-islington/cpython that referenced this pull request Jan 29, 2020
Replace check for whether something is a method in the mock module. The
previous version fails on PyPy, because there no method wrappers exist
(everything looks like a regular Python-defined function). Thus the
isinstance(getattr(result, '__get__', None), MethodWrapperTypes) check
returns True for any descriptor, not just methods.

This condition could also return erroneously True in CPython for
C-defined descriptors.

Instead to decide whether something is a method, just check directly
whether it's a function defined on the class. This passes all tests on
CPython and fixes the bug on PyPy.
(cherry picked from commit a327677)

Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Jan 29, 2020

GH-18255 is a backport of this pull request to the 3.8 branch.

@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Jan 29, 2020

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

miss-islington added a commit to miss-islington/cpython that referenced this pull request Jan 29, 2020
Replace check for whether something is a method in the mock module. The
previous version fails on PyPy, because there no method wrappers exist
(everything looks like a regular Python-defined function). Thus the
isinstance(getattr(result, '__get__', None), MethodWrapperTypes) check
returns True for any descriptor, not just methods.

This condition could also return erroneously True in CPython for
C-defined descriptors.

Instead to decide whether something is a method, just check directly
whether it's a function defined on the class. This passes all tests on
CPython and fixes the bug on PyPy.
(cherry picked from commit a327677)

Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Jan 29, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.