[Python-checkins] gh-99433: Fix `doctest` failure on `types.MethodWrapperType` (GH-99434)

miss-islington webhook-mailer at python.org
Fri Dec 30 07:19:00 EST 2022


https://github.com/python/cpython/commit/c88a83e7d81fbf394bbdebe0f453bb64bdf33ba6
commit: c88a83e7d81fbf394bbdebe0f453bb64bdf33ba6
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-12-30T04:18:54-08:00
summary:

gh-99433: Fix `doctest` failure on `types.MethodWrapperType` (GH-99434)

(cherry picked from commit 79c10b7da84f52999dc483fc62c8e758ad3eff23)

Co-authored-by: Nikita Sobolev <mail at sobolevn.me>

files:
A Misc/NEWS.d/next/Library/2022-11-13-15-32-19.gh-issue-99433.Ys6y0A.rst
M Lib/doctest.py
M Lib/test/doctest_lineno.py

diff --git a/Lib/doctest.py b/Lib/doctest.py
index b2ef2ce63672..dafad505ef0e 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -956,7 +956,8 @@ def _from_module(self, module, object):
             return module is inspect.getmodule(object)
         elif inspect.isfunction(object):
             return module.__dict__ is object.__globals__
-        elif inspect.ismethoddescriptor(object):
+        elif (inspect.ismethoddescriptor(object) or
+              inspect.ismethodwrapper(object)):
             if hasattr(object, '__objclass__'):
                 obj_mod = object.__objclass__.__module__
             elif hasattr(object, '__module__'):
diff --git a/Lib/test/doctest_lineno.py b/Lib/test/doctest_lineno.py
index be198513a150..729a68aceaa9 100644
--- a/Lib/test/doctest_lineno.py
+++ b/Lib/test/doctest_lineno.py
@@ -48,3 +48,6 @@ def method_with_doctest(self):
         >>> MethodWrapper.method_with_doctest.__name__
         'method_with_doctest'
         """
+
+# https://github.com/python/cpython/issues/99433
+str_wrapper = object().__str__
diff --git a/Misc/NEWS.d/next/Library/2022-11-13-15-32-19.gh-issue-99433.Ys6y0A.rst b/Misc/NEWS.d/next/Library/2022-11-13-15-32-19.gh-issue-99433.Ys6y0A.rst
new file mode 100644
index 000000000000..8e13a9a66a7e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-11-13-15-32-19.gh-issue-99433.Ys6y0A.rst
@@ -0,0 +1 @@
+Fix :mod:`doctest` failure on :class:`types.MethodWrapperType` in modules.



More information about the Python-checkins mailing list