Commit ad16b725 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #19190: Improve cross-references in builtin types and functions documentation.

parent 99a196fc
...@@ -563,7 +563,7 @@ Glossary ...@@ -563,7 +563,7 @@ Glossary
new-style class new-style class
Any class which inherits from :class:`object`. This includes all built-in Any class which inherits from :class:`object`. This includes all built-in
types like :class:`list` and :class:`dict`. Only new-style classes can types like :class:`list` and :class:`dict`. Only new-style classes can
use Python's newer, versatile features like :attr:`__slots__`, use Python's newer, versatile features like :attr:`~object.__slots__`,
descriptors, properties, and :meth:`__getattribute__`. descriptors, properties, and :meth:`__getattribute__`.
More information can be found in :ref:`newstyle`. More information can be found in :ref:`newstyle`.
...@@ -703,7 +703,8 @@ Glossary ...@@ -703,7 +703,8 @@ Glossary
type type
The type of a Python object determines what kind of object it is; every The type of a Python object determines what kind of object it is; every
object has a type. An object's type is accessible as its object has a type. An object's type is accessible as its
:attr:`__class__` attribute or can be retrieved with ``type(obj)``. :attr:`~instance.__class__` attribute or can be retrieved with
``type(obj)``.
universal newlines universal newlines
A manner of interpreting text streams in which all of the following are A manner of interpreting text streams in which all of the following are
......
...@@ -226,8 +226,8 @@ available. They are listed here in alphabetical order. ...@@ -226,8 +226,8 @@ available. They are listed here in alphabetical order.
Future statements are specified by bits which can be bitwise ORed together to Future statements are specified by bits which can be bitwise ORed together to
specify multiple statements. The bitfield required to specify a given feature specify multiple statements. The bitfield required to specify a given feature
can be found as the :attr:`compiler_flag` attribute on the :class:`_Feature` can be found as the :attr:`~__future__._Feature.compiler_flag` attribute on
instance in the :mod:`__future__` module. the :class:`~__future__._Feature` instance in the :mod:`__future__` module.
This function raises :exc:`SyntaxError` if the compiled source is invalid, This function raises :exc:`SyntaxError` if the compiled source is invalid,
and :exc:`TypeError` if the source contains null bytes. and :exc:`TypeError` if the source contains null bytes.
...@@ -701,7 +701,7 @@ available. They are listed here in alphabetical order. ...@@ -701,7 +701,7 @@ available. They are listed here in alphabetical order.
One useful application of the second form of :func:`iter` is to read lines of One useful application of the second form of :func:`iter` is to read lines of
a file until a certain line is reached. The following example reads a file a file until a certain line is reached. The following example reads a file
until the :meth:`readline` method returns an empty string:: until the :meth:`~io.TextIOBase.readline` method returns an empty string::
with open('mydata.txt') as fp: with open('mydata.txt') as fp:
for line in iter(fp.readline, ''): for line in iter(fp.readline, ''):
...@@ -1013,10 +1013,10 @@ available. They are listed here in alphabetical order. ...@@ -1013,10 +1013,10 @@ available. They are listed here in alphabetical order.
turns the :meth:`voltage` method into a "getter" for a read-only attribute turns the :meth:`voltage` method into a "getter" for a read-only attribute
with the same name. with the same name.
A property object has :attr:`getter`, :attr:`setter`, and :attr:`deleter` A property object has :attr:`~property.getter`, :attr:`~property.setter`,
methods usable as decorators that create a copy of the property with the and :attr:`~property.deleter` methods usable as decorators that create a
corresponding accessor function set to the decorated function. This is copy of the property with the corresponding accessor function set to the
best explained with an example:: decorated function. This is best explained with an example::
class C(object): class C(object):
def __init__(self): def __init__(self):
...@@ -1259,13 +1259,13 @@ available. They are listed here in alphabetical order. ...@@ -1259,13 +1259,13 @@ available. They are listed here in alphabetical order.
Return a :term:`slice` object representing the set of indices specified by Return a :term:`slice` object representing the set of indices specified by
``range(start, stop, step)``. The *start* and *step* arguments default to ``range(start, stop, step)``. The *start* and *step* arguments default to
``None``. Slice objects have read-only data attributes :attr:`start`, ``None``. Slice objects have read-only data attributes :attr:`~slice.start`,
:attr:`stop` and :attr:`step` which merely return the argument values (or their :attr:`~slice.stop` and :attr:`~slice.step` which merely return the argument
default). They have no other explicit functionality; however they are used by values (or their default). They have no other explicit functionality;
Numerical Python and other third party extensions. Slice objects are also however they are used by Numerical Python and other third party extensions.
generated when extended indexing syntax is used. For example: Slice objects are also generated when extended indexing syntax is used. For
``a[start:stop:step]`` or ``a[start:stop, i]``. See :func:`itertools.islice` example: ``a[start:stop:step]`` or ``a[start:stop, i]``. See
for an alternate version that returns an iterator. :func:`itertools.islice` for an alternate version that returns an iterator.
.. function:: sorted(iterable[, cmp[, key[, reverse]]]) .. function:: sorted(iterable[, cmp[, key[, reverse]]])
...@@ -1370,9 +1370,10 @@ available. They are listed here in alphabetical order. ...@@ -1370,9 +1370,10 @@ available. They are listed here in alphabetical order.
been overridden in a class. The search order is same as that used by been overridden in a class. The search order is same as that used by
:func:`getattr` except that the *type* itself is skipped. :func:`getattr` except that the *type* itself is skipped.
The :attr:`__mro__` attribute of the *type* lists the method resolution The :attr:`~class.__mro__` attribute of the *type* lists the method
search order used by both :func:`getattr` and :func:`super`. The attribute resolution search order used by both :func:`getattr` and :func:`super`. The
is dynamic and can change whenever the inheritance hierarchy is updated. attribute is dynamic and can change whenever the inheritance hierarchy is
updated.
If the second argument is omitted, the super object returned is unbound. If If the second argument is omitted, the super object returned is unbound. If
the second argument is an object, ``isinstance(obj, type)`` must be true. If the second argument is an object, ``isinstance(obj, type)`` must be true. If
...@@ -1446,10 +1447,10 @@ available. They are listed here in alphabetical order. ...@@ -1446,10 +1447,10 @@ available. They are listed here in alphabetical order.
With three arguments, return a new type object. This is essentially a With three arguments, return a new type object. This is essentially a
dynamic form of the :keyword:`class` statement. The *name* string is the dynamic form of the :keyword:`class` statement. The *name* string is the
class name and becomes the :attr:`__name__` attribute; the *bases* tuple class name and becomes the :attr:`~class.__name__` attribute; the *bases* tuple
itemizes the base classes and becomes the :attr:`__bases__` attribute; itemizes the base classes and becomes the :attr:`~class.__bases__` attribute;
and the *dict* dictionary is the namespace containing definitions for class and the *dict* dictionary is the namespace containing definitions for class
body and becomes the :attr:`__dict__` attribute. For example, the body and becomes the :attr:`~object.__dict__` attribute. For example, the
following two statements create identical :class:`type` objects: following two statements create identical :class:`type` objects:
>>> class X(object): >>> class X(object):
...@@ -1513,7 +1514,7 @@ available. They are listed here in alphabetical order. ...@@ -1513,7 +1514,7 @@ available. They are listed here in alphabetical order.
.. function:: vars([object]) .. function:: vars([object])
Return the :attr:`__dict__` attribute for a module, class, instance, Return the :attr:`~object.__dict__` attribute for a module, class, instance,
or any other object with a :attr:`__dict__` attribute. or any other object with a :attr:`__dict__` attribute.
Objects such as modules and instances have an updateable :attr:`__dict__` Objects such as modules and instances have an updateable :attr:`__dict__`
......
...@@ -1734,11 +1734,11 @@ other sequence-like behavior. ...@@ -1734,11 +1734,11 @@ other sequence-like behavior.
There are currently two built-in set types, :class:`set` and :class:`frozenset`. There are currently two built-in set types, :class:`set` and :class:`frozenset`.
The :class:`set` type is mutable --- the contents can be changed using methods The :class:`set` type is mutable --- the contents can be changed using methods
like :meth:`add` and :meth:`remove`. Since it is mutable, it has no hash value like :meth:`~set.add` and :meth:`~set.remove`. Since it is mutable, it has no
and cannot be used as either a dictionary key or as an element of another set. hash value and cannot be used as either a dictionary key or as an element of
The :class:`frozenset` type is immutable and :term:`hashable` --- its contents another set. The :class:`frozenset` type is immutable and :term:`hashable` ---
cannot be altered after it is created; it can therefore be used as a dictionary its contents cannot be altered after it is created; it can therefore be used as
key or as an element of another set. a dictionary key or as an element of another set.
As of Python 2.7, non-empty sets (not frozensets) can be created by placing a As of Python 2.7, non-empty sets (not frozensets) can be created by placing a
comma-separated list of elements within braces, for example: ``{'jack', comma-separated list of elements within braces, for example: ``{'jack',
...@@ -2828,12 +2828,12 @@ statement is not, strictly speaking, an operation on a module object; ``import ...@@ -2828,12 +2828,12 @@ statement is not, strictly speaking, an operation on a module object; ``import
foo`` does not require a module object named *foo* to exist, rather it requires foo`` does not require a module object named *foo* to exist, rather it requires
an (external) *definition* for a module named *foo* somewhere.) an (external) *definition* for a module named *foo* somewhere.)
A special attribute of every module is :attr:`__dict__`. This is the dictionary A special attribute of every module is :attr:`~object.__dict__`. This is the
containing the module's symbol table. Modifying this dictionary will actually dictionary containing the module's symbol table. Modifying this dictionary will
change the module's symbol table, but direct assignment to the :attr:`__dict__` actually change the module's symbol table, but direct assignment to the
attribute is not possible (you can write ``m.__dict__['a'] = 1``, which defines :attr:`__dict__` attribute is not possible (you can write
``m.a`` to be ``1``, but you can't write ``m.__dict__ = {}``). Modifying ``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but you can't write
:attr:`__dict__` directly is not recommended. ``m.__dict__ = {}``). Modifying :attr:`__dict__` directly is not recommended.
Modules built into the interpreter are written like this: ``<module 'sys' Modules built into the interpreter are written like this: ``<module 'sys'
(built-in)>``. If loaded from a file, they are written as ``<module 'os' from (built-in)>``. If loaded from a file, they are written as ``<module 'os' from
...@@ -3077,7 +3077,7 @@ The following attributes are only supported by :term:`new-style class`\ es. ...@@ -3077,7 +3077,7 @@ The following attributes are only supported by :term:`new-style class`\ es.
This method can be overridden by a metaclass to customize the method This method can be overridden by a metaclass to customize the method
resolution order for its instances. It is called at class instantiation, and resolution order for its instances. It is called at class instantiation, and
its result is stored in :attr:`__mro__`. its result is stored in :attr:`~class.__mro__`.
.. method:: class.__subclasses__ .. method:: class.__subclasses__
......
...@@ -411,7 +411,7 @@ Set types ...@@ -411,7 +411,7 @@ Set types
These represent a mutable set. They are created by the built-in :func:`set` These represent a mutable set. They are created by the built-in :func:`set`
constructor and can be modified afterwards by several methods, such as constructor and can be modified afterwards by several methods, such as
:meth:`add`. :meth:`~set.add`.
Frozen sets Frozen sets
.. index:: object: frozenset .. index:: object: frozenset
...@@ -661,7 +661,8 @@ Callable types ...@@ -661,7 +661,8 @@ Callable types
:ref:`yield`) is called a :dfn:`generator :ref:`yield`) is called a :dfn:`generator
function`. Such a function, when called, always returns an iterator object function`. Such a function, when called, always returns an iterator object
which can be used to execute the body of the function: calling the iterator's which can be used to execute the body of the function: calling the iterator's
:meth:`next` method will cause the function to execute until it provides a value :meth:`~iterator.next` method will cause the function to execute until
it provides a value
using the :keyword:`yield` statement. When the function executes a using the :keyword:`yield` statement. When the function executes a
:keyword:`return` statement or falls off the end, a :exc:`StopIteration` :keyword:`return` statement or falls off the end, a :exc:`StopIteration`
exception is raised and the iterator will have reached the end of the set of exception is raised and the iterator will have reached the end of the set of
...@@ -821,10 +822,10 @@ Classes ...@@ -821,10 +822,10 @@ Classes
Special attributes: :attr:`__name__` is the class name; :attr:`__module__` is Special attributes: :attr:`__name__` is the class name; :attr:`__module__` is
the module name in which the class was defined; :attr:`__dict__` is the the module name in which the class was defined; :attr:`__dict__` is the
dictionary containing the class's namespace; :attr:`__bases__` is a tuple dictionary containing the class's namespace; :attr:`~class.__bases__` is a
(possibly empty or a singleton) containing the base classes, in the order of tuple (possibly empty or a singleton) containing the base classes, in the
their occurrence in the base class list; :attr:`__doc__` is the class's order of their occurrence in the base class list; :attr:`__doc__` is the
documentation string, or None if undefined. class's documentation string, or None if undefined.
Class instances Class instances
.. index:: .. index::
...@@ -869,8 +870,8 @@ Class instances ...@@ -869,8 +870,8 @@ Class instances
single: __dict__ (instance attribute) single: __dict__ (instance attribute)
single: __class__ (instance attribute) single: __class__ (instance attribute)
Special attributes: :attr:`__dict__` is the attribute dictionary; Special attributes: :attr:`~object.__dict__` is the attribute dictionary;
:attr:`__class__` is the instance's class. :attr:`~instance.__class__` is the instance's class.
Files Files
.. index:: .. index::
...@@ -1069,9 +1070,9 @@ Internal types ...@@ -1069,9 +1070,9 @@ Internal types
single: stop (slice object attribute) single: stop (slice object attribute)
single: step (slice object attribute) single: step (slice object attribute)
Special read-only attributes: :attr:`start` is the lower bound; :attr:`stop` is Special read-only attributes: :attr:`~slice.start` is the lower bound;
the upper bound; :attr:`step` is the step value; each is ``None`` if omitted. :attr:`~slice.stop` is the upper bound; :attr:`~slice.step` is the step
These attributes can have any type. value; each is ``None`` if omitted. These attributes can have any type.
Slice objects support one method: Slice objects support one method:
...@@ -1178,7 +1179,8 @@ When implementing a class that emulates any built-in type, it is important that ...@@ -1178,7 +1179,8 @@ When implementing a class that emulates any built-in type, it is important that
the emulation only be implemented to the degree that it makes sense for the the emulation only be implemented to the degree that it makes sense for the
object being modelled. For example, some sequences may work well with retrieval object being modelled. For example, some sequences may work well with retrieval
of individual elements, but extracting a slice may not make sense. (One example of individual elements, but extracting a slice may not make sense. (One example
of this is the :class:`NodeList` interface in the W3C's Document Object Model.) of this is the :class:`~xml.dom.NodeList` interface in the W3C's Document
Object Model.)
.. _customization: .. _customization:
...@@ -1810,10 +1812,10 @@ case the instance is itself a class. ...@@ -1810,10 +1812,10 @@ case the instance is itself a class.
:pep:`3119` - Introducing Abstract Base Classes :pep:`3119` - Introducing Abstract Base Classes
Includes the specification for customizing :func:`isinstance` and Includes the specification for customizing :func:`isinstance` and
:func:`issubclass` behavior through :meth:`__instancecheck__` and :func:`issubclass` behavior through :meth:`~class.__instancecheck__` and
:meth:`__subclasscheck__`, with motivation for this functionality in the :meth:`~class.__subclasscheck__`, with motivation for this functionality
context of adding Abstract Base Classes (see the :mod:`abc` module) to the in the context of adding Abstract Base Classes (see the :mod:`abc`
language. module) to the language.
.. _callable-types: .. _callable-types:
...@@ -1846,7 +1848,7 @@ range of items. (For backwards compatibility, the method :meth:`__getslice__` ...@@ -1846,7 +1848,7 @@ range of items. (For backwards compatibility, the method :meth:`__getslice__`
is also recommended that mappings provide the methods :meth:`keys`, is also recommended that mappings provide the methods :meth:`keys`,
:meth:`values`, :meth:`items`, :meth:`has_key`, :meth:`get`, :meth:`clear`, :meth:`values`, :meth:`items`, :meth:`has_key`, :meth:`get`, :meth:`clear`,
:meth:`setdefault`, :meth:`iterkeys`, :meth:`itervalues`, :meth:`iteritems`, :meth:`setdefault`, :meth:`iterkeys`, :meth:`itervalues`, :meth:`iteritems`,
:meth:`pop`, :meth:`popitem`, :meth:`copy`, and :meth:`update` behaving similar :meth:`pop`, :meth:`popitem`, :meth:`!copy`, and :meth:`update` behaving similar
to those for Python's standard dictionary objects. The :mod:`UserDict` module to those for Python's standard dictionary objects. The :mod:`UserDict` module
provides a :class:`DictMixin` class to help create those methods from a base set provides a :class:`DictMixin` class to help create those methods from a base set
of :meth:`__getitem__`, :meth:`__setitem__`, :meth:`__delitem__`, and of :meth:`__getitem__`, :meth:`__setitem__`, :meth:`__delitem__`, and
......
...@@ -431,6 +431,7 @@ Note that calling any of the generator methods below when the generator ...@@ -431,6 +431,7 @@ Note that calling any of the generator methods below when the generator
is already executing raises a :exc:`ValueError` exception. is already executing raises a :exc:`ValueError` exception.
.. index:: exception: StopIteration .. index:: exception: StopIteration
.. class:: generator
.. method:: generator.next() .. method:: generator.next()
...@@ -444,6 +445,7 @@ is already executing raises a :exc:`ValueError` exception. ...@@ -444,6 +445,7 @@ is already executing raises a :exc:`ValueError` exception.
exits without yielding another value, a :exc:`StopIteration` exception is exits without yielding another value, a :exc:`StopIteration` exception is
raised. raised.
.. class:: .
.. method:: generator.send(value) .. method:: generator.send(value)
...@@ -660,10 +662,10 @@ is a tuple containing the conversion of the slice items; otherwise, the ...@@ -660,10 +662,10 @@ is a tuple containing the conversion of the slice items; otherwise, the
conversion of the lone slice item is the key. The conversion of a slice item conversion of the lone slice item is the key. The conversion of a slice item
that is an expression is that expression. The conversion of an ellipsis slice that is an expression is that expression. The conversion of an ellipsis slice
item is the built-in ``Ellipsis`` object. The conversion of a proper slice is a item is the built-in ``Ellipsis`` object. The conversion of a proper slice is a
slice object (see section :ref:`types`) whose :attr:`start`, :attr:`stop` and slice object (see section :ref:`types`) whose :attr:`~slice.start`,
:attr:`step` attributes are the values of the expressions given as lower bound, :attr:`~slice.stop` and :attr:`~slice.step` attributes are the values of the
upper bound and stride, respectively, substituting ``None`` for missing expressions given as lower bound, upper bound and stride, respectively,
expressions. substituting ``None`` for missing expressions.
.. index:: .. index::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment