[Python-checkins] Add comments to `{typing, _collections_abc}._type_repr` about each other (#102752)
AlexWaygood
webhook-mailer at python.org
Thu Mar 16 09:05:50 EDT 2023
https://github.com/python/cpython/commit/a297d59609038ccfc3bdf6f350e8401f07b0a931
commit: a297d59609038ccfc3bdf6f350e8401f07b0a931
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2023-03-16T13:05:38Z
summary:
Add comments to `{typing,_collections_abc}._type_repr` about each other (#102752)
Remove `if` condition in `_collections_abc._type_repr` that's no longer needed, bringing it in sync with `typing._type_repr`.
files:
M Lib/_collections_abc.py
M Lib/typing.py
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index c62233b81a5c..f86b91a5e6fb 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -517,9 +517,8 @@ def _type_repr(obj):
Copied from :mod:`typing` since collections.abc
shouldn't depend on that module.
+ (Keep this roughly in sync with the typing version.)
"""
- if isinstance(obj, GenericAlias):
- return repr(obj)
if isinstance(obj, type):
if obj.__module__ == 'builtins':
return obj.__qualname__
diff --git a/Lib/typing.py b/Lib/typing.py
index ab3343956761..3ee9679e50c0 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -230,6 +230,9 @@ def _type_repr(obj):
typically enough to uniquely identify a type. For everything
else, we fall back on repr(obj).
"""
+ # When changing this function, don't forget about
+ # `_collections_abc._type_repr`, which does the same thing
+ # and must be consistent with this one.
if isinstance(obj, type):
if obj.__module__ == 'builtins':
return obj.__qualname__
More information about the Python-checkins
mailing list