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

[3.7] bpo-39485: fix corner-case in method-detection of mock (GH-18252) #18256

Merged
merged 1 commit into from Jan 29, 2020

Conversation

@miss-islington
Copy link

miss-islington commented 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

https://bugs.python.org/issue39485

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>
@miss-islington

This comment has been minimized.

Copy link
Author

miss-islington commented Jan 29, 2020

@cfbolz and @cjw296: Status check is done, and it's a success .

1 similar comment
@miss-islington

This comment has been minimized.

Copy link
Author

miss-islington commented Jan 29, 2020

@cfbolz and @cjw296: Status check is done, and it's a success .

@cjw296 cjw296 merged commit cf0645a into python:3.7 Jan 29, 2020
10 checks passed
10 checks passed
Docs
Details
Windows (x86)
Details
Windows (x64)
Details
macOS
Details
Ubuntu
Details
Azure Pipelines PR #20200129.35 succeeded
Details
bedevere/issue-number Issue number 39485 found
Details
bedevere/maintenance-branch-pr Valid maintenance branch PR title.
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@miss-islington miss-islington deleted the miss-islington:backport-a327677-3.7 branch Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.