From 1a4fd9f146ac4416ae7ac5f5d1b74f0d23614941 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 16 Mar 2023 14:20:46 +0300 Subject: [PATCH 1/3] Add comments to `{typing,_collections_abc}._type_repr` abouth each other --- Lib/_collections_abc.py | 5 +++-- Lib/typing.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index c62233b81a5c95..d1216fc4ab5f6b 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -518,8 +518,9 @@ def _type_repr(obj): Copied from :mod:`typing` since collections.abc shouldn't depend on that module. """ - if isinstance(obj, GenericAlias): - return repr(obj) + # When changing this function, don't forget about + # `typing._type_repr` function that does the same thing + # and must be consistent with this one. if isinstance(obj, type): if obj.__module__ == 'builtins': return obj.__qualname__ diff --git a/Lib/typing.py b/Lib/typing.py index ab334395676159..cdadb38ec50c2b 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` function that does the same thing + # and must be consistent with this one. if isinstance(obj, type): if obj.__module__ == 'builtins': return obj.__qualname__ From 1b8faa23f8dc5d9196fdb6d5662c10a925fa73c2 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 16 Mar 2023 14:54:44 +0300 Subject: [PATCH 2/3] Address review --- Lib/_collections_abc.py | 2 +- Lib/typing.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index d1216fc4ab5f6b..c8a27964dc74f9 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -519,7 +519,7 @@ def _type_repr(obj): shouldn't depend on that module. """ # When changing this function, don't forget about - # `typing._type_repr` function that does the same thing + # `typing._type_repr`, which does the same thing # and must be consistent with this one. if isinstance(obj, type): if obj.__module__ == 'builtins': diff --git a/Lib/typing.py b/Lib/typing.py index cdadb38ec50c2b..3ee9679e50c0c4 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -231,7 +231,7 @@ def _type_repr(obj): else, we fall back on repr(obj). """ # When changing this function, don't forget about - # `_collections_abc._type_repr` function that does the same thing + # `_collections_abc._type_repr`, which does the same thing # and must be consistent with this one. if isinstance(obj, type): if obj.__module__ == 'builtins': From 1383fe88e02df88942f90ee34dd612889701c7c0 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 16 Mar 2023 15:32:50 +0300 Subject: [PATCH 3/3] Address review --- Lib/_collections_abc.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index c8a27964dc74f9..f86b91a5e6fb0d 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -517,10 +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.) """ - # When changing this function, don't forget about - # `typing._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__