Skip to content

Conversation

@cfbolz
Copy link
Contributor

@cfbolz 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
Copy link
Member

@cfbolz
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
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 January 29, 2020 15:37
@miss-islington
Copy link
Contributor

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

miss-islington pushed 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
Copy link

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

@miss-islington
Copy link
Contributor

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

miss-islington pushed 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
Copy link

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

shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants