[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

bpo-39485: fix corner-case in method-detection of mock by cfbolz · Pull Request #18252 · python/cpython

the-knights-who-say-ni

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.

cjw296 merged commit a327677 into python:master

Jan 29, 2020

9 checks passed

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

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>

shihai1991 added 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.