Skip to content

Commit 82dd956

Browse files
committed
Use type.__fullyqualname__ attribute
1 parent d5e8a37 commit 82dd956

21 files changed

+35
-46
lines changed

Lib/_collections_abc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,7 @@ def _type_repr(obj):
528528
(Keep this roughly in sync with the typing version.)
529529
"""
530530
if isinstance(obj, type):
531-
if obj.__module__ == 'builtins':
532-
return obj.__qualname__
533-
return f'{obj.__module__}.{obj.__qualname__}'
531+
return obj.__fullyqualname__
534532
if obj is Ellipsis:
535533
return '...'
536534
if isinstance(obj, FunctionType):

Lib/_py_abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def register(cls, subclass):
7171

7272
def _dump_registry(cls, file=None):
7373
"""Debug helper to print the ABC registry."""
74-
print(f"Class: {cls.__module__}.{cls.__qualname__}", file=file)
74+
print(f"Class: {cls.__fullyqualname__}", file=file)
7575
print(f"Inv. counter: {get_cache_token()}", file=file)
7676
for name in cls.__dict__:
7777
if name.startswith("_abc_"):

Lib/abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __subclasscheck__(cls, subclass):
124124

125125
def _dump_registry(cls, file=None):
126126
"""Debug helper to print the ABC registry."""
127-
print(f"Class: {cls.__module__}.{cls.__qualname__}", file=file)
127+
print(f"Class: {cls.__fullyqualname__}", file=file)
128128
print(f"Inv. counter: {get_cache_token()}", file=file)
129129
(_abc_registry, _abc_cache, _abc_negative_cache,
130130
_abc_negative_cache_version) = _get_dump(cls)

Lib/codecs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def __new__(cls, encode, decode, streamreader=None, streamwriter=None,
107107
return self
108108

109109
def __repr__(self):
110-
return "<%s.%s object for encoding %s at %#x>" % \
111-
(self.__class__.__module__, self.__class__.__qualname__,
110+
return "<%s object for encoding %s at %#x>" % \
111+
(self.__class__.__fullyqualname__,
112112
self.name, id(self))
113113

114114
def __getnewargs__(self):

Lib/contextlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def enter_context(self, cm):
525525
_enter = cls.__enter__
526526
_exit = cls.__exit__
527527
except AttributeError:
528-
raise TypeError(f"'{cls.__module__}.{cls.__qualname__}' object does "
528+
raise TypeError(f"'{cls.__fullyqualname__}' object does "
529529
f"not support the context manager protocol") from None
530530
result = _enter(cm)
531531
self._push_cm_exit(cm, _exit)
@@ -662,7 +662,7 @@ async def enter_async_context(self, cm):
662662
_enter = cls.__aenter__
663663
_exit = cls.__aexit__
664664
except AttributeError:
665-
raise TypeError(f"'{cls.__module__}.{cls.__qualname__}' object does "
665+
raise TypeError(f"'{cls.__fullyqualname__}' object does "
666666
f"not support the asynchronous context manager protocol"
667667
) from None
668668
result = await _enter(cm)

Lib/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ def __run(self, test, compileflags, out):
14011401
# They start with `SyntaxError:` (or any other class name)
14021402
exception_line_prefixes = (
14031403
f"{exception[0].__qualname__}:",
1404-
f"{exception[0].__module__}.{exception[0].__qualname__}:",
1404+
f"{exception[0].__fullyqualname__}:",
14051405
)
14061406
exc_msg_index = next(
14071407
index

Lib/inspect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,9 +1501,9 @@ def repl(match):
15011501
if isinstance(annotation, types.GenericAlias):
15021502
return str(annotation)
15031503
if isinstance(annotation, type):
1504-
if annotation.__module__ in ('builtins', base_module):
1504+
if annotation.__module__ == base_module:
15051505
return annotation.__qualname__
1506-
return annotation.__module__+'.'+annotation.__qualname__
1506+
return annotation.__fullyqualname__
15071507
return repr(annotation)
15081508

15091509
def formatannotationrelativeto(object):

Lib/multiprocessing/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def __del__(self, _warn=warnings.warn, RUN=RUN):
272272

273273
def __repr__(self):
274274
cls = self.__class__
275-
return (f'<{cls.__module__}.{cls.__qualname__} '
275+
return (f'<{cls.__fullyqualname__} '
276276
f'state={self._state} '
277277
f'pool_size={len(self._pool)}>')
278278

Lib/pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ def do_whatis(self, arg):
17261726
return
17271727
# Is it a class?
17281728
if value.__class__ is type:
1729-
self.message('Class %s.%s' % (value.__module__, value.__qualname__))
1729+
self.message(f'Class {value.__fullyqualname__}')
17301730
return
17311731
# None of the above...
17321732
self.message(type(value))

Lib/test/support/asyncore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def __init__(self, sock=None, map=None):
256256
self.socket = None
257257

258258
def __repr__(self):
259-
status = [self.__class__.__module__+"."+self.__class__.__qualname__]
259+
status = [self.__class__.__fullyqualname__]
260260
if self.accepting and self.addr:
261261
status.append('listening')
262262
elif self.connected:

0 commit comments

Comments
 (0)