Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bae5d81

Browse files
committed
Issue #24314: Fix doc links for general attributes like __name__, __dict__
1 parent 886a5f3 commit bae5d81

14 files changed

Lines changed: 69 additions & 64 deletions

File tree

Doc/c-api/module.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ Module Objects
5959
.. index:: single: __dict__ (module attribute)
6060
6161
Return the dictionary object that implements *module*'s namespace; this object
62-
is the same as the :attr:`__dict__` attribute of the module object. This
62+
is the same as the :attr:`~object.__dict__` attribute of the module object. This
6363
function never fails. It is recommended extensions use other
6464
:c:func:`PyModule_\*` and :c:func:`PyObject_\*` functions rather than directly
65-
manipulate a module's :attr:`__dict__`.
65+
manipulate a module's :attr:`~object.__dict__`.
6666
6767
6868
.. c:function:: PyObject* PyModule_GetNameObject(PyObject *module)

Doc/c-api/typeobj.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ type objects) *must* have the :attr:`ob_size` field.
111111
For statically allocated type objects, the tp_name field should contain a dot.
112112
Everything before the last dot is made accessible as the :attr:`__module__`
113113
attribute, and everything after the last dot is made accessible as the
114-
:attr:`__name__` attribute.
114+
:attr:`~definition.__name__` attribute.
115115

116116
If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the
117-
:attr:`__name__` attribute, and the :attr:`__module__` attribute is undefined
117+
:attr:`~definition.__name__` attribute, and the :attr:`__module__` attribute is undefined
118118
(unless explicitly set in the dictionary, as explained above). This means your
119119
type will be impossible to pickle.
120120

Doc/library/builtins.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ that wants to implement an :func:`open` function that wraps the built-in
3737

3838
As an implementation detail, most modules have the name ``__builtins__`` made
3939
available as part of their globals. The value of ``__builtins__`` is normally
40-
either this module or the value of this module's :attr:`__dict__` attribute.
40+
either this module or the value of this module's :attr:`~object.__dict__` attribute.
4141
Since this is an implementation detail, it may not be used by alternate
4242
implementations of Python.

Doc/library/enum.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ The solution is to specify the module name explicitly as follows::
431431
the source, pickling will be disabled.
432432

433433
The new pickle protocol 4 also, in some circumstances, relies on
434-
:attr:`__qualname__` being set to the location where pickle will be able
434+
:attr:`~definition.__qualname__` being set to the location where pickle will be able
435435
to find the class. For example, if the class was made available in class
436436
SomeData in the global scope::
437437

Doc/library/functions.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ are always available. They are listed here in alphabetical order.
304304
:func:`dir` reports their attributes.
305305

306306
If the object does not provide :meth:`__dir__`, the function tries its best to
307-
gather information from the object's :attr:`__dict__` attribute, if defined, and
307+
gather information from the object's :attr:`~object.__dict__` attribute, if defined, and
308308
from its type object. The resulting list is not necessarily complete, and may
309309
be inaccurate when the object has a custom :func:`__getattr__`.
310310

@@ -1446,7 +1446,7 @@ are always available. They are listed here in alphabetical order.
14461446

14471447
With three arguments, return a new type object. This is essentially a
14481448
dynamic form of the :keyword:`class` statement. The *name* string is the
1449-
class name and becomes the :attr:`~class.__name__` attribute; the *bases*
1449+
class name and becomes the :attr:`~definition.__name__` attribute; the *bases*
14501450
tuple itemizes the base classes and becomes the :attr:`~class.__bases__`
14511451
attribute; and the *dict* dictionary is the namespace containing definitions
14521452
for class body and is copied to a standard dictionary to become the
@@ -1464,11 +1464,11 @@ are always available. They are listed here in alphabetical order.
14641464
.. function:: vars([object])
14651465

14661466
Return the :attr:`~object.__dict__` attribute for a module, class, instance,
1467-
or any other object with a :attr:`__dict__` attribute.
1467+
or any other object with a :attr:`~object.__dict__` attribute.
14681468

1469-
Objects such as modules and instances have an updateable :attr:`__dict__`
1469+
Objects such as modules and instances have an updateable :attr:`~object.__dict__`
14701470
attribute; however, other objects may have write restrictions on their
1471-
:attr:`__dict__` attributes (for example, classes use a
1471+
:attr:`~object.__dict__` attributes (for example, classes use a
14721472
dictproxy to prevent direct dictionary updates).
14731473

14741474
Without an argument, :func:`vars` acts like :func:`locals`. Note, the

Doc/library/functools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ have three read-only attributes:
474474

475475
:class:`partial` objects are like :class:`function` objects in that they are
476476
callable, weak referencable, and can have attributes. There are some important
477-
differences. For instance, the :attr:`__name__` and :attr:`__doc__` attributes
477+
differences. For instance, the :attr:`~definition.__name__` and :attr:`__doc__` attributes
478478
are not created automatically. Also, :class:`partial` objects defined in
479479
classes behave like static methods and do not transform into bound methods
480480
during instance attribute look-up.

Doc/library/inspect.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ attributes:
374374
are true.
375375

376376
This, for example, is true of ``int.__add__``. An object passing this test
377-
has a :attr:`__get__` attribute but not a :attr:`__set__` attribute, but
378-
beyond that the set of attributes varies. :attr:`__name__` is usually
377+
has a :meth:`~object.__get__` method but not a :meth:`~object.__set__`
378+
method, but beyond that the set of attributes varies. A
379+
:attr:`~definition.__name__` attribute is usually
379380
sensible, and :attr:`__doc__` often is.
380381

381382
Methods implemented via descriptors that also pass one of the other tests
@@ -388,11 +389,11 @@ attributes:
388389

389390
Return true if the object is a data descriptor.
390391

391-
Data descriptors have both a :attr:`__get__` and a :attr:`__set__` attribute.
392+
Data descriptors have both a :attr:`~object.__get__` and a :attr:`~object.__set__` method.
392393
Examples are properties (defined in Python), getsets, and members. The
393394
latter two are defined in C and there are more specific tests available for
394395
those types, which is robust across Python implementations. Typically, data
395-
descriptors will also have :attr:`__name__` and :attr:`__doc__` attributes
396+
descriptors will also have :attr:`~definition.__name__` and :attr:`__doc__` attributes
396397
(properties, getsets, and members have both of these attributes), but this is
397398
not guaranteed.
398399

Doc/library/stdtypes.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4360,9 +4360,10 @@ an (external) *definition* for a module named *foo* somewhere.)
43604360
A special attribute of every module is :attr:`~object.__dict__`. This is the
43614361
dictionary containing the module's symbol table. Modifying this dictionary will
43624362
actually change the module's symbol table, but direct assignment to the
4363-
:attr:`__dict__` attribute is not possible (you can write
4363+
:attr:`~object.__dict__` attribute is not possible (you can write
43644364
``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but you can't write
4365-
``m.__dict__ = {}``). Modifying :attr:`__dict__` directly is not recommended.
4365+
``m.__dict__ = {}``). Modifying :attr:`~object.__dict__` directly is
4366+
not recommended.
43664367

43674368
Modules built into the interpreter are written like this: ``<module 'sys'
43684369
(built-in)>``. If loaded from a file, they are written as ``<module 'os' from
@@ -4575,14 +4576,16 @@ types, where they are relevant. Some of these are not reported by the
45754576
The tuple of base classes of a class object.
45764577

45774578

4578-
.. attribute:: class.__name__
4579+
.. attribute:: definition.__name__
45794580

4580-
The name of the class or type.
4581+
The name of the class, function, method, descriptor, or
4582+
generator instance.
45814583

45824584

4583-
.. attribute:: class.__qualname__
4585+
.. attribute:: definition.__qualname__
45844586

4585-
The :term:`qualified name` of the class or type.
4587+
The :term:`qualified name` of the class, function, method, descriptor,
4588+
or generator instance.
45864589

45874590
.. versionadded:: 3.3
45884591

Doc/reference/datamodel.rst

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,19 @@ Callable types
454454

455455
.. tabularcolumns:: |l|L|l|
456456

457+
.. index::
458+
single: __doc__ (function attribute)
459+
single: __name__ (function attribute)
460+
single: __module__ (function attribute)
461+
single: __dict__ (function attribute)
462+
single: __defaults__ (function attribute)
463+
single: __closure__ (function attribute)
464+
single: __code__ (function attribute)
465+
single: __globals__ (function attribute)
466+
single: __annotations__ (function attribute)
467+
single: __kwdefaults__ (function attribute)
468+
pair: global; namespace
469+
457470
+-------------------------+-------------------------------+-----------+
458471
| Attribute | Meaning | |
459472
+=========================+===============================+===========+
@@ -462,10 +475,11 @@ Callable types
462475
| | unavailable; not inherited by | |
463476
| | subclasses | |
464477
+-------------------------+-------------------------------+-----------+
465-
| :attr:`__name__` | The function's name | Writable |
478+
| :attr:`~definition.\ | The function's name | Writable |
479+
| __name__` | | |
466480
+-------------------------+-------------------------------+-----------+
467-
| :attr:`__qualname__` | The function's | Writable |
468-
| | :term:`qualified name` | |
481+
| :attr:`~definition.\ | The function's | Writable |
482+
| __qualname__` | :term:`qualified name` | |
469483
| | | |
470484
| | .. versionadded:: 3.3 | |
471485
+-------------------------+-------------------------------+-----------+
@@ -489,7 +503,7 @@ Callable types
489503
| | module in which the function | |
490504
| | was defined. | |
491505
+-------------------------+-------------------------------+-----------+
492-
| :attr:`__dict__` | The namespace supporting | Writable |
506+
| :attr:`~object.__dict__`| The namespace supporting | Writable |
493507
| | arbitrary function | |
494508
| | attributes. | |
495509
+-------------------------+-------------------------------+-----------+
@@ -519,19 +533,6 @@ Callable types
519533
Additional information about a function's definition can be retrieved from its
520534
code object; see the description of internal types below.
521535

522-
.. index::
523-
single: __doc__ (function attribute)
524-
single: __name__ (function attribute)
525-
single: __module__ (function attribute)
526-
single: __dict__ (function attribute)
527-
single: __defaults__ (function attribute)
528-
single: __closure__ (function attribute)
529-
single: __code__ (function attribute)
530-
single: __globals__ (function attribute)
531-
single: __annotations__ (function attribute)
532-
single: __kwdefaults__ (function attribute)
533-
pair: global; namespace
534-
535536
Instance methods
536537
.. index::
537538
object: method
@@ -550,7 +551,7 @@ Callable types
550551

551552
Special read-only attributes: :attr:`__self__` is the class instance object,
552553
:attr:`__func__` is the function object; :attr:`__doc__` is the method's
553-
documentation (same as ``__func__.__doc__``); :attr:`__name__` is the
554+
documentation (same as ``__func__.__doc__``); :attr:`~definition.__name__` is the
554555
method name (same as ``__func__.__name__``); :attr:`__module__` is the
555556
name of the module the method was defined in, or ``None`` if unavailable.
556557

@@ -637,7 +638,7 @@ Callable types
637638
standard built-in module). The number and type of the arguments are
638639
determined by the C function. Special read-only attributes:
639640
:attr:`__doc__` is the function's documentation string, or ``None`` if
640-
unavailable; :attr:`__name__` is the function's name; :attr:`__self__` is
641+
unavailable; :attr:`~definition.__name__` is the function's name; :attr:`__self__` is
641642
set to ``None`` (but see the next item); :attr:`__module__` is the name of
642643
the module the function was defined in or ``None`` if unavailable.
643644

@@ -687,7 +688,7 @@ Modules
687688

688689
.. index:: single: __dict__ (module attribute)
689690

690-
Special read-only attribute: :attr:`__dict__` is the module's namespace as a
691+
Special read-only attribute: :attr:`~object.__dict__` is the module's namespace as a
691692
dictionary object.
692693

693694
.. impl-detail::
@@ -743,7 +744,7 @@ Custom classes
743744
method object, it is transformed into the object wrapped by the static method
744745
object. See section :ref:`descriptors` for another way in which attributes
745746
retrieved from a class may differ from those actually contained in its
746-
:attr:`__dict__`.
747+
:attr:`~object.__dict__`.
747748

748749
.. index:: triple: class; attribute; assignment
749750

@@ -761,8 +762,8 @@ Custom classes
761762
single: __bases__ (class attribute)
762763
single: __doc__ (class attribute)
763764

764-
Special attributes: :attr:`__name__` is the class name; :attr:`__module__` is
765-
the module name in which the class was defined; :attr:`__dict__` is the
765+
Special attributes: :attr:`~definition.__name__` is the class name; :attr:`__module__` is
766+
the module name in which the class was defined; :attr:`~object.__dict__` is the
766767
dictionary containing the class's namespace; :attr:`~class.__bases__` is a
767768
tuple (possibly empty or a singleton) containing the base classes, in the
768769
order of their occurrence in the base class list; :attr:`__doc__` is the
@@ -785,7 +786,7 @@ Class instances
785786
class method objects are also transformed; see above under "Classes". See
786787
section :ref:`descriptors` for another way in which attributes of a class
787788
retrieved via its instances may differ from the objects actually stored in
788-
the class's :attr:`__dict__`. If no class attribute is found, and the
789+
the class's :attr:`~object.__dict__`. If no class attribute is found, and the
789790
object's class has a :meth:`__getattr__` method, that is called to satisfy
790791
the lookup.
791792

@@ -1466,7 +1467,7 @@ method (a so-called *descriptor* class) appears in an *owner* class (the
14661467
descriptor must be in either the owner's class dictionary or in the class
14671468
dictionary for one of its parents). In the examples below, "the attribute"
14681469
refers to the attribute whose name is the key of the property in the owner
1469-
class' :attr:`__dict__`.
1470+
class' :attr:`~object.__dict__`.
14701471

14711472

14721473
.. method:: object.__get__(self, instance, owner)

Doc/tutorial/classes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ Examples::
951951
.. rubric:: Footnotes
952952

953953
.. [#] Except for one thing. Module objects have a secret read-only attribute called
954-
:attr:`__dict__` which returns the dictionary used to implement the module's
955-
namespace; the name :attr:`__dict__` is an attribute but not a global name.
954+
:attr:`~object.__dict__` which returns the dictionary used to implement the module's
955+
namespace; the name :attr:`~object.__dict__` is an attribute but not a global name.
956956
Obviously, using this violates the abstraction of namespace implementation, and
957957
should be restricted to things like post-mortem debuggers.
958958

0 commit comments

Comments
 (0)