summaryrefslogtreecommitdiff
path: root/Doc/reference/datamodel.rst
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-09-08 20:50:03 -0700
committerYury Selivanov <yury@magic.io>2016-09-08 20:50:03 -0700
commitb164476aaf77ceffac36ddbbdc7f4df90fbfebd3 (patch)
tree0a744472fe547a36f970c59528e48aebd01de75e /Doc/reference/datamodel.rst
parent61f296e12ff25b48169250d726b92d589e0221af (diff)
downloadcpython-b164476aaf77ceffac36ddbbdc7f4df90fbfebd3.tar.gz
Issue #27985: Implement PEP 526 -- Syntax for Variable Annotations.
Patch by Ivan Levkivskyi.
Diffstat (limited to 'Doc/reference/datamodel.rst')
-rw-r--r--Doc/reference/datamodel.rst35
1 files changed, 21 insertions, 14 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index a0755039f7..3d581a5496 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -686,33 +686,36 @@ Modules
Attribute assignment updates the module's namespace dictionary, e.g.,
``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.
- .. index:: single: __dict__ (module attribute)
-
- Special read-only attribute: :attr:`~object.__dict__` is the module's namespace as a
- dictionary object.
-
- .. impl-detail::
-
- Because of the way CPython clears module dictionaries, the module
- dictionary will be cleared when the module falls out of scope even if the
- dictionary still has live references. To avoid this, copy the dictionary
- or keep the module around while using its dictionary directly.
-
.. index::
single: __name__ (module attribute)
single: __doc__ (module attribute)
single: __file__ (module attribute)
+ single: __annotations__ (module attribute)
pair: module; namespace
Predefined (writable) attributes: :attr:`__name__` is the module's name;
:attr:`__doc__` is the module's documentation string, or ``None`` if
- unavailable; :attr:`__file__` is the pathname of the file from which the
+ unavailable; :attr:`__annotations__` (optional) is a dictionary containing
+ :term:`variable annotations <variable annotation>` collected during module
+ body execution; :attr:`__file__` is the pathname of the file from which the
module was loaded, if it was loaded from a file. The :attr:`__file__`
attribute may be missing for certain types of modules, such as C modules
that are statically linked into the interpreter; for extension modules
loaded dynamically from a shared library, it is the pathname of the shared
library file.
+ .. index:: single: __dict__ (module attribute)
+
+ Special read-only attribute: :attr:`~object.__dict__` is the module's
+ namespace as a dictionary object.
+
+ .. impl-detail::
+
+ Because of the way CPython clears module dictionaries, the module
+ dictionary will be cleared when the module falls out of scope even if the
+ dictionary still has live references. To avoid this, copy the dictionary
+ or keep the module around while using its dictionary directly.
+
Custom classes
Custom class types are typically created by class definitions (see section
:ref:`class`). A class has a namespace implemented by a dictionary object.
@@ -761,13 +764,17 @@ Custom classes
single: __dict__ (class attribute)
single: __bases__ (class attribute)
single: __doc__ (class attribute)
+ single: __annotations__ (class attribute)
Special attributes: :attr:`~definition.__name__` is the class name; :attr:`__module__` is
the module name in which the class was defined; :attr:`~object.__dict__` is the
dictionary containing the class's namespace; :attr:`~class.__bases__` is a
tuple (possibly empty or a singleton) containing the base classes, in the
order of their occurrence in the base class list; :attr:`__doc__` is the
- class's documentation string, or None if undefined.
+ class's documentation string, or None if undefined;
+ :attr:`__annotations__` (optional) is a dictionary containing
+ :term:`variable annotations <variable annotation>` collected during
+ class body execution.
Class instances
.. index::