From 65a5bf9d37a3b29eb394f560b9a09318196c40e8 Mon Sep 17 00:00:00 2001 From: shadchin <shadchin@yandex-team.com> Date: Mon, 23 Dec 2024 19:39:02 +0300 Subject: Update Python 3 to 3.12.8 commit_hash:c20045b8a987d8720e1f3328270357491d5530f3 --- contrib/tools/python3/Lib/reprlib.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'contrib/tools/python3/Lib/reprlib.py') diff --git a/contrib/tools/python3/Lib/reprlib.py b/contrib/tools/python3/Lib/reprlib.py index a7b37630a4..85c1b94a0e 100644 --- a/contrib/tools/python3/Lib/reprlib.py +++ b/contrib/tools/python3/Lib/reprlib.py @@ -35,6 +35,17 @@ def recursive_repr(fillvalue='...'): return decorating_function class Repr: + _lookup = { + 'tuple': 'builtins', + 'list': 'builtins', + 'array': 'array', + 'set': 'builtins', + 'frozenset': 'builtins', + 'deque': 'collections', + 'dict': 'builtins', + 'str': 'builtins', + 'int': 'builtins' + } def __init__( self, *, maxlevel=6, maxtuple=6, maxlist=6, maxarray=5, maxdict=4, @@ -59,14 +70,24 @@ class Repr: return self.repr1(x, self.maxlevel) def repr1(self, x, level): - typename = type(x).__name__ + cls = type(x) + typename = cls.__name__ + if ' ' in typename: parts = typename.split() typename = '_'.join(parts) - if hasattr(self, 'repr_' + typename): - return getattr(self, 'repr_' + typename)(x, level) - else: - return self.repr_instance(x, level) + + method = getattr(self, 'repr_' + typename, None) + if method: + # not defined in this class + if typename not in self._lookup: + return method(x, level) + module = getattr(cls, '__module__', None) + # defined in this class and is the module intended + if module == self._lookup[typename]: + return method(x, level) + + return self.repr_instance(x, level) def _join(self, pieces, level): if self.indent is None: -- cgit v1.2.3