summaryrefslogtreecommitdiffstats
path: root/Misc
diff options
context:
space:
mode:
authorCarl Friedrich Bolz-Tereick <cfbolz@gmx.de>2020-01-29 15:43:37 (GMT)
committerGitHub <noreply@github.com>2020-01-29 15:43:37 (GMT)
commita327677905956ae0b239ff430a1346dfe265709e (patch)
tree761a01408b75c8900ca38b7cc86e0a49a50b27bb /Misc
parent3cb49b62e61208efcefbc04414e769fc173f205d (diff)
downloadcpython-a327677905956ae0b239ff430a1346dfe265709e.zip
cpython-a327677905956ae0b239ff430a1346dfe265709e.tar.gz
cpython-a327677905956ae0b239ff430a1346dfe265709e.tar.bz2
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.
Diffstat (limited to 'Misc')
-rw-r--r--Misc/NEWS.d/next/Library/2020-01-29-14-58-27.bpo-39485.Zy3ot6.rst3
1 files changed, 3 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Library/2020-01-29-14-58-27.bpo-39485.Zy3ot6.rst b/Misc/NEWS.d/next/Library/2020-01-29-14-58-27.bpo-39485.Zy3ot6.rst
new file mode 100644
index 0000000..f62c31f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-01-29-14-58-27.bpo-39485.Zy3ot6.rst
@@ -0,0 +1,3 @@
+Fix a bug in :func:`unittest.mock.create_autospec` that would complain about
+the wrong number of arguments for custom descriptors defined in an extension
+module returning functions.