Skip to content

Commit

Permalink
Rename the attribute to __fully_qualified_name__
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Nov 16, 2023
1 parent 82dd956 commit 76dcfd5
Show file tree
Hide file tree
Showing 29 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Type Objects
.. c:function:: PyObject* PyType_GetFullyQualifiedName(PyTypeObject *type)
Return the type's fully qualified name. Equivalent to getting the
type's :attr:`__fullyqualname__ <class.__fullyqualname__>` attribute.
type's :attr:`__fully_qualified_name__ <class.__fully_qualified_name__>` attribute.
.. versionadded:: 3.13
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5496,7 +5496,7 @@ types, where they are relevant. Some of these are not reported by the
.. versionadded:: 3.3


.. attribute:: class.__fullyqualname__
.. attribute:: class.__fully_qualified_name__

The fully qualified name of the class instance:
``f"{class.__module__}.{class.__qualname__}"``, or ``class.__qualname__`` if
Expand Down
4 changes: 2 additions & 2 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Other Language Changes
equivalent of the :option:`-X frozen_modules <-X>` command-line option.
(Contributed by Yilei Yang in :gh:`111374`.)

* Add :attr:`__fullyqualname__ <class.__fullyqualname__>` read-only attribute
* Add :attr:`__fully_qualified_name__ <class.__fully_qualified_name__>` read-only attribute
to types: the fully qualified type name.
(Contributed by Victor Stinner in :gh:`111696`.)

Expand Down Expand Up @@ -1188,7 +1188,7 @@ New Features

* Add :c:func:`PyType_GetFullyQualifiedName` function: get the type's fully
qualified name. It is equivalent to getting the type's
:attr:`__fullyqualname__ <class.__fullyqualname__>` attribute.
:attr:`__fully_qualified_name__ <class.__fully_qualified_name__>` attribute.
(Contributed by Victor Stinner in :gh:`111696`.)


Expand Down
2 changes: 1 addition & 1 deletion Lib/_collections_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def _type_repr(obj):
(Keep this roughly in sync with the typing version.)
"""
if isinstance(obj, type):
return obj.__fullyqualname__
return obj.__fully_qualified_name__
if obj is Ellipsis:
return '...'
if isinstance(obj, FunctionType):
Expand Down
2 changes: 1 addition & 1 deletion Lib/_py_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def register(cls, subclass):

def _dump_registry(cls, file=None):
"""Debug helper to print the ABC registry."""
print(f"Class: {cls.__fullyqualname__}", file=file)
print(f"Class: {cls.__fully_qualified_name__}", file=file)
print(f"Inv. counter: {get_cache_token()}", file=file)
for name in cls.__dict__:
if name.startswith("_abc_"):
Expand Down
2 changes: 1 addition & 1 deletion Lib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __subclasscheck__(cls, subclass):

def _dump_registry(cls, file=None):
"""Debug helper to print the ABC registry."""
print(f"Class: {cls.__fullyqualname__}", file=file)
print(f"Class: {cls.__fully_qualified_name__}", file=file)
print(f"Inv. counter: {get_cache_token()}", file=file)
(_abc_registry, _abc_cache, _abc_negative_cache,
_abc_negative_cache_version) = _get_dump(cls)
Expand Down
2 changes: 1 addition & 1 deletion Lib/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __new__(cls, encode, decode, streamreader=None, streamwriter=None,

def __repr__(self):
return "<%s object for encoding %s at %#x>" % \
(self.__class__.__fullyqualname__,
(self.__class__.__fully_qualified_name__,
self.name, id(self))

def __getnewargs__(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/contextlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def enter_context(self, cm):
_enter = cls.__enter__
_exit = cls.__exit__
except AttributeError:
raise TypeError(f"'{cls.__fullyqualname__}' object does "
raise TypeError(f"'{cls.__fully_qualified_name__}' object does "
f"not support the context manager protocol") from None
result = _enter(cm)
self._push_cm_exit(cm, _exit)
Expand Down Expand Up @@ -662,7 +662,7 @@ async def enter_async_context(self, cm):
_enter = cls.__aenter__
_exit = cls.__aexit__
except AttributeError:
raise TypeError(f"'{cls.__fullyqualname__}' object does "
raise TypeError(f"'{cls.__fully_qualified_name__}' object does "
f"not support the asynchronous context manager protocol"
) from None
result = await _enter(cm)
Expand Down
2 changes: 1 addition & 1 deletion Lib/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ def __run(self, test, compileflags, out):
# They start with `SyntaxError:` (or any other class name)
exception_line_prefixes = (
f"{exception[0].__qualname__}:",
f"{exception[0].__fullyqualname__}:",
f"{exception[0].__fully_qualified_name__}:",
)
exc_msg_index = next(
index
Expand Down
2 changes: 1 addition & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ def repl(match):
if isinstance(annotation, type):
if annotation.__module__ == base_module:
return annotation.__qualname__
return annotation.__fullyqualname__
return annotation.__fully_qualified_name__
return repr(annotation)

def formatannotationrelativeto(object):
Expand Down
2 changes: 1 addition & 1 deletion Lib/multiprocessing/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def __del__(self, _warn=warnings.warn, RUN=RUN):

def __repr__(self):
cls = self.__class__
return (f'<{cls.__fullyqualname__} '
return (f'<{cls.__fully_qualified_name__} '
f'state={self._state} '
f'pool_size={len(self._pool)}>')

Expand Down
2 changes: 1 addition & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ def do_whatis(self, arg):
return
# Is it a class?
if value.__class__ is type:
self.message(f'Class {value.__fullyqualname__}')
self.message(f'Class {value.__fully_qualified_name__}')
return
# None of the above...
self.message(type(value))
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def __init__(self, sock=None, map=None):
self.socket = None

def __repr__(self):
status = [self.__class__.__fullyqualname__]
status = [self.__class__.__fully_qualified_name__]
if self.accepting and self.addr:
status.append('listening')
elif self.connected:
Expand Down
16 changes: 8 additions & 8 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,7 @@ def test_new_type(self):
self.assertEqual(A.__name__, 'A')
self.assertEqual(A.__qualname__, 'A')
self.assertEqual(A.__module__, __name__)
self.assertEqual(A.__fullyqualname__, f'{__name__}.A')
self.assertEqual(A.__fully_qualified_name__, f'{__name__}.A')
self.assertEqual(A.__bases__, (object,))
self.assertIs(A.__base__, object)
x = A()
Expand All @@ -2444,7 +2444,7 @@ def ham(self):
self.assertEqual(C.__name__, 'C')
self.assertEqual(C.__qualname__, 'C')
self.assertEqual(C.__module__, __name__)
self.assertEqual(C.__fullyqualname__, f'{__name__}.C')
self.assertEqual(C.__fully_qualified_name__, f'{__name__}.C')
self.assertEqual(C.__bases__, (B, int))
self.assertIs(C.__base__, int)
self.assertIn('spam', C.__dict__)
Expand All @@ -2470,7 +2470,7 @@ def test_type_name(self):
self.assertEqual(A.__name__, name)
self.assertEqual(A.__qualname__, f"Test.{name}")
self.assertEqual(A.__module__, __name__)
self.assertEqual(A.__fullyqualname__, f'{__name__}.Test.{name}')
self.assertEqual(A.__fully_qualified_name__, f'{__name__}.Test.{name}')
with self.assertRaises(ValueError):
type('A\x00B', (), {})
with self.assertRaises(UnicodeEncodeError):
Expand All @@ -2485,7 +2485,7 @@ def test_type_name(self):
self.assertEqual(C.__name__, name)
self.assertEqual(C.__qualname__, 'C')
self.assertEqual(C.__module__, __name__)
self.assertEqual(C.__fullyqualname__, f'{__name__}.C')
self.assertEqual(C.__fully_qualified_name__, f'{__name__}.C')

A = type('C', (), {})
with self.assertRaises(ValueError):
Expand All @@ -2501,24 +2501,24 @@ def test_type_name(self):
# if __module__ is not a string, ignore it silently
class D:
pass
self.assertEqual(D.__fullyqualname__, f'{__name__}.{D.__qualname__}')
self.assertEqual(D.__fully_qualified_name__, f'{__name__}.{D.__qualname__}')
D.__module__ = 123
self.assertEqual(D.__fullyqualname__, D.__qualname__)
self.assertEqual(D.__fully_qualified_name__, D.__qualname__)

def test_type_qualname(self):
A = type('A', (), {'__qualname__': 'B.C'})
self.assertEqual(A.__name__, 'A')
self.assertEqual(A.__qualname__, 'B.C')
self.assertEqual(A.__module__, __name__)
self.assertEqual(A.__fullyqualname__, f'{__name__}.B.C')
self.assertEqual(A.__fully_qualified_name__, f'{__name__}.B.C')
with self.assertRaises(TypeError):
type('A', (), {'__qualname__': b'B'})
self.assertEqual(A.__qualname__, 'B.C')

A.__qualname__ = 'D.E'
self.assertEqual(A.__name__, 'A')
self.assertEqual(A.__qualname__, 'D.E')
self.assertEqual(A.__fullyqualname__, f'{__name__}.D.E')
self.assertEqual(A.__fully_qualified_name__, f'{__name__}.D.E')
with self.assertRaises(TypeError):
A.__qualname__ = b'B'
self.assertEqual(A.__qualname__, 'D.E')
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def get_error(self, cf, exc, section, option):
except exc as e:
return e
else:
self.fail(f"expected exception type {exc.__fullyqualname__}")
self.fail(f"expected exception type {exc.__fully_qualified_name__}")

def test_boolean(self):
cf = self.fromstring(
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def __str__(self):
if X.__module__ == '__main__':
str_name = X.__qualname__
else:
str_name = X.__fullyqualname__
str_name = X.__fully_qualified_name__
self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value))

def test_format_exception_group_without_show_group(self):
Expand Down Expand Up @@ -1875,7 +1875,7 @@ def __str__(self):

err = self.get_report(A.B.X())
str_value = 'I am X'
str_name = A.B.X.__fullyqualname__
str_name = A.B.X.__fully_qualified_name__
exp = "%s: %s\n" % (str_name, str_value)
self.assertEqual(exp, MODULE_PREFIX + err)

Expand All @@ -1892,7 +1892,7 @@ def __str__(self):
if modulename == '__main__':
str_name = X.__qualname__
else:
str_name = X.__fullyqualname__
str_name = X.__fully_qualified_name__
exp = "%s: %s\n" % (str_name, str_value)
self.assertEqual(exp, err)

Expand Down Expand Up @@ -1928,7 +1928,7 @@ def __str__(self):
1/0
err = self.get_report(X())
str_value = '<exception str() failed>'
str_name = X.__fullyqualname__
str_name = X.__fully_qualified_name__
self.assertEqual(MODULE_PREFIX + err, f"{str_name}: {str_value}\n")


Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_zipimport_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _run_object_doctest(obj, module):
# Use the object's fully qualified name if it has one
# Otherwise, use the module's name
try:
name = obj.__fullyqualname__
name = obj.__fully_qualified_name__
except AttributeError:
name = module.__name__
for example in finder.find(obj, name, module):
Expand Down
10 changes: 5 additions & 5 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def __init__(self, value=1):

def __repr__(self):
cls = self.__class__
return (f"<{cls.__fullyqualname__} at {id(self):#x}:"
return (f"<{cls.__fully_qualified_name__} at {id(self):#x}:"
f" value={self._value}>")

def acquire(self, blocking=True, timeout=None):
Expand Down Expand Up @@ -547,7 +547,7 @@ def __init__(self, value=1):

def __repr__(self):
cls = self.__class__
return (f"<{cls.__fullyqualname__} at {id(self):#x}:"
return (f"<{cls.__fully_qualified_name__} at {id(self):#x}:"
f" value={self._value}/{self._initial_value}>")

def release(self, n=1):
Expand Down Expand Up @@ -587,7 +587,7 @@ def __init__(self):
def __repr__(self):
cls = self.__class__
status = 'set' if self._flag else 'unset'
return f"<{cls.__fullyqualname__} at {id(self):#x}: {status}>"
return f"<{cls.__fully_qualified_name__} at {id(self):#x}: {status}>"

def _at_fork_reinit(self):
# Private method called by Thread._after_fork()
Expand Down Expand Up @@ -690,8 +690,8 @@ def __init__(self, parties, action=None, timeout=None):
def __repr__(self):
cls = self.__class__
if self.broken:
return f"<{cls.__fullyqualname__} at {id(self):#x}: broken>"
return (f"<{cls.__fullyqualname__} at {id(self):#x}:"
return f"<{cls.__fully_qualified_name__} at {id(self):#x}: broken>"
return (f"<{cls.__fully_qualified_name__} at {id(self):#x}:"
f" waiters={self.n_waiting}/{self.parties}>")

def wait(self, timeout=None):
Expand Down
2 changes: 1 addition & 1 deletion Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ def __str__(self):
return self._w

def __repr__(self):
return f'<{self.__class__.__fullyqualname__} object {self._w}>'
return f'<{self.__class__.__fully_qualified_name__} object {self._w}>'

# Pack methods that apply to the master
_noarg_ = ['_noarg_']
Expand Down
2 changes: 1 addition & 1 deletion Lib/tkinter/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __str__(self):
return self.name

def __repr__(self):
return (f"<{self.__class__.__fullyqualname__}"
return (f"<{self.__class__.__fully_qualified_name__}"
f" object {self.name!r}>")

def __eq__(self, other):
Expand Down
4 changes: 2 additions & 2 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _type_repr(obj):
# `_collections_abc._type_repr`, which does the same thing
# and must be consistent with this one.
if isinstance(obj, type):
return obj.__fullyqualname__
return obj.__fully_qualified_name__
if obj is ...:
return '...'
if isinstance(obj, types.FunctionType):
Expand Down Expand Up @@ -1400,7 +1400,7 @@ def __init__(self, origin, nparams, *, inst=True, name=None):
name = origin.__name__
super().__init__(origin, inst=inst, name=name)
self._nparams = nparams
self.__doc__ = f'A generic version of {origin.__fullyqualname__}.'
self.__doc__ = f'A generic version of {origin.__fully_qualified_name__}.'

@_tp_cache
def __getitem__(self, params):
Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/async_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def enterAsyncContext(self, cm):
enter = cls.__aenter__
exit = cls.__aexit__
except AttributeError:
raise TypeError(f"'{cls.__fullyqualname__}' object does "
raise TypeError(f"'{cls.__fully_qualified_name__}' object does "
f"not support the asynchronous context manager protocol"
) from None
result = await enter(cm)
Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _enter_context(cm, addcleanup):
enter = cls.__enter__
exit = cls.__exit__
except AttributeError:
raise TypeError(f"'{cls.__fullyqualname__}' object does "
raise TypeError(f"'{cls.__fully_qualified_name__}' object does "
f"not support the context manager protocol") from None
result = enter(cm)
addcleanup(exit, cm, None, None, None)
Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def shouldIncludeMethod(attrname):
testFunc = getattr(testCaseClass, attrname)
if not callable(testFunc):
return False
fullName = f'{testCaseClass.__fullyqualname__}.{attrname}'
fullName = f'{testCaseClass.__fully_qualified_name__}.{attrname}'
return self.testNamePatterns is None or \
any(fnmatchcase(fullName, pattern) for pattern in self.testNamePatterns)
testFnNames = list(filter(shouldIncludeMethod, dir(testCaseClass)))
Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def safe_repr(obj, short=False):
return result[:_MAX_LENGTH] + ' [truncated]...'

def strclass(cls):
return cls.__fullyqualname__
return cls.__fully_qualified_name__

def sorted_list_difference(expected, actual):
"""Finds elements in only one or the other of two, sorted input lists.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Add :c:func:`PyType_GetFullyQualifiedName` function: get the type's fully
qualified name. It is equivalent to getting the type's :attr:`__fullyqualname__
<class.__fullyqualname__>` attribute. Patch by Victor Stinner.
qualified name. It is equivalent to getting the type's :attr:`__fully_qualified_name__
<class.__fully_qualified_name__>` attribute. Patch by Victor Stinner.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Add :attr:`__fullyqualname__ <class.__fullyqualname__>` read-only attribute
Add :attr:`__fully_qualified_name__ <class.__fully_qualified_name__>` read-only attribute
to types: the fully qualified type name. Patch by Victor Stinner.
2 changes: 1 addition & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ test_get_type_fullyqualname(PyObject *self, PyObject *Py_UNUSED(ignored))
}

int res = PyObject_SetAttrString(HeapTypeNameType,
"__fullyqualname__", new_name);
"__fully_qualified_name__", new_name);
Py_DECREF(new_name);
assert(res < 0);
assert(PyErr_ExceptionMatches(PyExc_AttributeError));
Expand Down
2 changes: 1 addition & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ type___subclasscheck___impl(PyTypeObject *self, PyObject *subclass)
static PyGetSetDef type_getsets[] = {
{"__name__", (getter)type_name, (setter)type_set_name, NULL},
{"__qualname__", (getter)type_qualname, (setter)type_set_qualname, NULL},
{"__fullyqualname__", (getter)type_get_fullyqualname, NULL, NULL},
{"__fully_qualified_name__", (getter)type_get_fullyqualname, NULL, NULL},
{"__bases__", (getter)type_get_bases, (setter)type_set_bases, NULL},
{"__mro__", (getter)type_get_mro, NULL, NULL},
{"__module__", (getter)type_module, (setter)type_set_module, NULL},
Expand Down

0 comments on commit 76dcfd5

Please sign in to comment.