]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-39485: fix corner-case in method-detection of mock (GH-18252)
authorCarl Friedrich Bolz-Tereick <cfbolz@gmx.de>
Wed, 29 Jan 2020 15:43:37 +0000 (16:43 +0100)
committerGitHub <noreply@github.com>
Wed, 29 Jan 2020 15:43:37 +0000 (15:43 +0000)
commita327677905956ae0b239ff430a1346dfe265709e
tree761a01408b75c8900ca38b7cc86e0a49a50b27bb
parent3cb49b62e61208efcefbc04414e769fc173f205d
bpo-39485: fix corner-case in method-detection of mock (GH-18252)

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.
Lib/unittest/mock.py
Misc/NEWS.d/next/Library/2020-01-29-14-58-27.bpo-39485.Zy3ot6.rst [new file with mode: 0644]