mirror of https://github.com/python/cpython
Issue #22032: __qualname__ instead of __name__ is now always used to format
fully qualified class names of Python implemented classes.
This commit is contained in:
parent
c09e9752c6
commit
521e5860a5
|
@ -168,7 +168,7 @@ class ABCMeta(type):
|
||||||
|
|
||||||
def _dump_registry(cls, file=None):
|
def _dump_registry(cls, file=None):
|
||||||
"""Debug helper to print the ABC registry."""
|
"""Debug helper to print the ABC registry."""
|
||||||
print("Class: %s.%s" % (cls.__module__, cls.__name__), file=file)
|
print("Class: %s.%s" % (cls.__module__, cls.__qualname__), file=file)
|
||||||
print("Inv.counter: %s" % ABCMeta._abc_invalidation_counter, file=file)
|
print("Inv.counter: %s" % ABCMeta._abc_invalidation_counter, file=file)
|
||||||
for name in sorted(cls.__dict__.keys()):
|
for name in sorted(cls.__dict__.keys()):
|
||||||
if name.startswith("_abc_"):
|
if name.startswith("_abc_"):
|
||||||
|
|
|
@ -255,7 +255,7 @@ class dispatcher:
|
||||||
self.socket = None
|
self.socket = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
status = [self.__class__.__module__+"."+self.__class__.__name__]
|
status = [self.__class__.__module__+"."+self.__class__.__qualname__]
|
||||||
if self.accepting and self.addr:
|
if self.accepting and self.addr:
|
||||||
status.append('listening')
|
status.append('listening')
|
||||||
elif self.connected:
|
elif self.connected:
|
||||||
|
|
|
@ -99,8 +99,8 @@ class CodecInfo(tuple):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s.%s object for encoding %s at 0x%x>" % \
|
return "<%s.%s object for encoding %s at %#x>" % \
|
||||||
(self.__class__.__module__, self.__class__.__name__,
|
(self.__class__.__module__, self.__class__.__qualname__,
|
||||||
self.name, id(self))
|
self.name, id(self))
|
||||||
|
|
||||||
class Codec:
|
class Codec:
|
||||||
|
|
|
@ -134,7 +134,7 @@ class Extension:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s.%s(%r) at %#x>' % (
|
return '<%s.%s(%r) at %#x>' % (
|
||||||
self.__class__.__module__,
|
self.__class__.__module__,
|
||||||
self.__class__.__name__,
|
self.__class__.__qualname__,
|
||||||
self.name,
|
self.name,
|
||||||
id(self))
|
id(self))
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,7 @@ class partialmethod(object):
|
||||||
for k, v in self.keywords.items())
|
for k, v in self.keywords.items())
|
||||||
format_string = "{module}.{cls}({func}, {args}, {keywords})"
|
format_string = "{module}.{cls}({func}, {args}, {keywords})"
|
||||||
return format_string.format(module=self.__class__.__module__,
|
return format_string.format(module=self.__class__.__module__,
|
||||||
cls=self.__class__.__name__,
|
cls=self.__class__.__qualname__,
|
||||||
func=self.func,
|
func=self.func,
|
||||||
args=args,
|
args=args,
|
||||||
keywords=keywords)
|
keywords=keywords)
|
||||||
|
|
|
@ -1038,8 +1038,8 @@ def getargvalues(frame):
|
||||||
def formatannotation(annotation, base_module=None):
|
def formatannotation(annotation, base_module=None):
|
||||||
if isinstance(annotation, type):
|
if isinstance(annotation, type):
|
||||||
if annotation.__module__ in ('builtins', base_module):
|
if annotation.__module__ in ('builtins', base_module):
|
||||||
return annotation.__name__
|
return annotation.__qualname__
|
||||||
return annotation.__module__+'.'+annotation.__name__
|
return annotation.__module__+'.'+annotation.__qualname__
|
||||||
return repr(annotation)
|
return repr(annotation)
|
||||||
|
|
||||||
def formatannotationrelativeto(object):
|
def formatannotationrelativeto(object):
|
||||||
|
|
|
@ -1316,7 +1316,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
return
|
return
|
||||||
# Is it a class?
|
# Is it a class?
|
||||||
if value.__class__ is type:
|
if value.__class__ is type:
|
||||||
self.message('Class %s.%s' % (value.__module__, value.__name__))
|
self.message('Class %s.%s' % (value.__module__, value.__qualname__))
|
||||||
return
|
return
|
||||||
# None of the above...
|
# None of the above...
|
||||||
self.message(type(value))
|
self.message(type(value))
|
||||||
|
|
|
@ -141,7 +141,7 @@ class socket(_socket.socket):
|
||||||
closed = getattr(self, '_closed', False)
|
closed = getattr(self, '_closed', False)
|
||||||
s = "<%s.%s%s fd=%i, family=%s, type=%s, proto=%i" \
|
s = "<%s.%s%s fd=%i, family=%s, type=%s, proto=%i" \
|
||||||
% (self.__class__.__module__,
|
% (self.__class__.__module__,
|
||||||
self.__class__.__name__,
|
self.__class__.__qualname__,
|
||||||
" [closed]" if closed else "",
|
" [closed]" if closed else "",
|
||||||
self.fileno(),
|
self.fileno(),
|
||||||
self.family,
|
self.family,
|
||||||
|
|
|
@ -579,7 +579,7 @@ boolean {0[0]} NO
|
||||||
return e
|
return e
|
||||||
else:
|
else:
|
||||||
self.fail("expected exception type %s.%s"
|
self.fail("expected exception type %s.%s"
|
||||||
% (exc.__module__, exc.__name__))
|
% (exc.__module__, exc.__qualname__))
|
||||||
|
|
||||||
def test_boolean(self):
|
def test_boolean(self):
|
||||||
cf = self.fromstring(
|
cf = self.fromstring(
|
||||||
|
|
|
@ -778,7 +778,7 @@ class CommonBufferedTests:
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
raw = self.MockRawIO()
|
raw = self.MockRawIO()
|
||||||
b = self.tp(raw)
|
b = self.tp(raw)
|
||||||
clsname = "%s.%s" % (self.tp.__module__, self.tp.__name__)
|
clsname = "%s.%s" % (self.tp.__module__, self.tp.__qualname__)
|
||||||
self.assertEqual(repr(b), "<%s>" % clsname)
|
self.assertEqual(repr(b), "<%s>" % clsname)
|
||||||
raw.name = "dummy"
|
raw.name = "dummy"
|
||||||
self.assertEqual(repr(b), "<%s name='dummy'>" % clsname)
|
self.assertEqual(repr(b), "<%s name='dummy'>" % clsname)
|
||||||
|
|
|
@ -92,9 +92,9 @@ class SyntaxTracebackCases(unittest.TestCase):
|
||||||
self.assertEqual(len(err), 1)
|
self.assertEqual(len(err), 1)
|
||||||
str_value = '<unprintable %s object>' % X.__name__
|
str_value = '<unprintable %s object>' % X.__name__
|
||||||
if X.__module__ in ('__main__', 'builtins'):
|
if X.__module__ in ('__main__', 'builtins'):
|
||||||
str_name = X.__name__
|
str_name = X.__qualname__
|
||||||
else:
|
else:
|
||||||
str_name = '.'.join([X.__module__, X.__name__])
|
str_name = '.'.join([X.__module__, X.__qualname__])
|
||||||
self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value))
|
self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value))
|
||||||
|
|
||||||
def test_without_exception(self):
|
def test_without_exception(self):
|
||||||
|
|
|
@ -39,7 +39,7 @@ def _run_object_doctest(obj, module):
|
||||||
# Use the object's fully qualified name if it has one
|
# Use the object's fully qualified name if it has one
|
||||||
# Otherwise, use the module's name
|
# Otherwise, use the module's name
|
||||||
try:
|
try:
|
||||||
name = "%s.%s" % (obj.__module__, obj.__name__)
|
name = "%s.%s" % (obj.__module__, obj.__qualname__)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
name = module.__name__
|
name = module.__name__
|
||||||
for example in finder.find(obj, name, module):
|
for example in finder.find(obj, name, module):
|
||||||
|
|
|
@ -205,7 +205,7 @@ def _format_exception_only_iter(etype, value):
|
||||||
yield _format_final_exc_line(etype, value)
|
yield _format_final_exc_line(etype, value)
|
||||||
return
|
return
|
||||||
|
|
||||||
stype = etype.__name__
|
stype = etype.__qualname__
|
||||||
smod = etype.__module__
|
smod = etype.__module__
|
||||||
if smod not in ("__main__", "builtins"):
|
if smod not in ("__main__", "builtins"):
|
||||||
stype = smod + '.' + stype
|
stype = smod + '.' + stype
|
||||||
|
|
|
@ -111,7 +111,7 @@ class TestSetups(unittest.TestCase):
|
||||||
self.assertEqual(len(result.errors), 1)
|
self.assertEqual(len(result.errors), 1)
|
||||||
error, _ = result.errors[0]
|
error, _ = result.errors[0]
|
||||||
self.assertEqual(str(error),
|
self.assertEqual(str(error),
|
||||||
'setUpClass (%s.BrokenTest)' % __name__)
|
'setUpClass (%s.%s)' % (__name__, BrokenTest.__qualname__))
|
||||||
|
|
||||||
def test_error_in_teardown_class(self):
|
def test_error_in_teardown_class(self):
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
@ -144,7 +144,7 @@ class TestSetups(unittest.TestCase):
|
||||||
|
|
||||||
error, _ = result.errors[0]
|
error, _ = result.errors[0]
|
||||||
self.assertEqual(str(error),
|
self.assertEqual(str(error),
|
||||||
'tearDownClass (%s.Test)' % __name__)
|
'tearDownClass (%s.%s)' % (__name__, Test.__qualname__))
|
||||||
|
|
||||||
def test_class_not_torndown_when_setup_fails(self):
|
def test_class_not_torndown_when_setup_fails(self):
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
@ -414,7 +414,8 @@ class TestSetups(unittest.TestCase):
|
||||||
self.assertEqual(len(result.errors), 0)
|
self.assertEqual(len(result.errors), 0)
|
||||||
self.assertEqual(len(result.skipped), 1)
|
self.assertEqual(len(result.skipped), 1)
|
||||||
skipped = result.skipped[0][0]
|
skipped = result.skipped[0][0]
|
||||||
self.assertEqual(str(skipped), 'setUpClass (%s.Test)' % __name__)
|
self.assertEqual(str(skipped),
|
||||||
|
'setUpClass (%s.%s)' % (__name__, Test.__qualname__))
|
||||||
|
|
||||||
def test_skiptest_in_setupmodule(self):
|
def test_skiptest_in_setupmodule(self):
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
|
|
@ -52,7 +52,7 @@ def safe_repr(obj, short=False):
|
||||||
return result[:_MAX_LENGTH] + ' [truncated]...'
|
return result[:_MAX_LENGTH] + ' [truncated]...'
|
||||||
|
|
||||||
def strclass(cls):
|
def strclass(cls):
|
||||||
return "%s.%s" % (cls.__module__, cls.__name__)
|
return "%s.%s" % (cls.__module__, cls.__qualname__)
|
||||||
|
|
||||||
def sorted_list_difference(expected, actual):
|
def sorted_list_difference(expected, actual):
|
||||||
"""Finds elements in only one or the other of two, sorted input lists.
|
"""Finds elements in only one or the other of two, sorted input lists.
|
||||||
|
|
|
@ -108,6 +108,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #22032: __qualname__ instead of __name__ is now always used to format
|
||||||
|
fully qualified class names of Python implemented classes.
|
||||||
|
|
||||||
- Issue #22031: Reprs now always use hexadecimal format with the "0x" prefix
|
- Issue #22031: Reprs now always use hexadecimal format with the "0x" prefix
|
||||||
when contain an id in form " at 0x...".
|
when contain an id in form " at 0x...".
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue