[Python-checkins] bpo-38291: Fix a spurious warning when using help(object) (#27039)

gvanrossum webhook-mailer at python.org
Tue Jul 6 11:01:20 EDT 2021


https://github.com/python/cpython/commit/8b849ea0f3482ad834e7989ff474dd5db2f295c8
commit: 8b849ea0f3482ad834e7989ff474dd5db2f295c8
branch: main
author: Sebastian Rittau <srittau at rittau.biz>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2021-07-06T08:01:15-07:00
summary:

bpo-38291: Fix a spurious warning when using help(object) (#27039)

help(object) via pydoc.TextDoc.docclass(object) iterates over the
subclasses of object, which includes typing.io and typing.re if typing
is imported. It tries to access cls.__module__ for each of those
sub-classes. This change suppresses warnings when accessing
cls.__module__.

files:
M Lib/typing.py

diff --git a/Lib/typing.py b/Lib/typing.py
index 2287f0521a364..ca05fb54bf428 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -2512,7 +2512,7 @@ def __enter__(self) -> 'TextIO':
 
 class _DeprecatedType(type):
     def __getattribute__(cls, name):
-        if name != "__dict__" and name in cls.__dict__:
+        if name not in ("__dict__", "__module__") and name in cls.__dict__:
             warnings.warn(
                 f"{cls.__name__} is deprecated, import directly "
                 f"from typing instead. {cls.__name__} will be removed "



More information about the Python-checkins mailing list