Commit 4aebd6f4 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue 19195: Improved cross-references in C API documentation.

parent d2951322
...@@ -52,19 +52,19 @@ and *NULL* returned. ...@@ -52,19 +52,19 @@ and *NULL* returned.
.. c:function:: PyObject* PyCodec_IncrementalEncoder(const char *encoding, const char *errors) .. c:function:: PyObject* PyCodec_IncrementalEncoder(const char *encoding, const char *errors)
Get an :class:`IncrementalEncoder` object for the given *encoding*. Get an :class:`~codecs.IncrementalEncoder` object for the given *encoding*.
.. c:function:: PyObject* PyCodec_IncrementalDecoder(const char *encoding, const char *errors) .. c:function:: PyObject* PyCodec_IncrementalDecoder(const char *encoding, const char *errors)
Get an :class:`IncrementalDecoder` object for the given *encoding*. Get an :class:`~codecs.IncrementalDecoder` object for the given *encoding*.
.. c:function:: PyObject* PyCodec_StreamReader(const char *encoding, PyObject *stream, const char *errors) .. c:function:: PyObject* PyCodec_StreamReader(const char *encoding, PyObject *stream, const char *errors)
Get a :class:`StreamReader` factory function for the given *encoding*. Get a :class:`~codecs.StreamReader` factory function for the given *encoding*.
.. c:function:: PyObject* PyCodec_StreamWriter(const char *encoding, PyObject *stream, const char *errors) .. c:function:: PyObject* PyCodec_StreamWriter(const char *encoding, PyObject *stream, const char *errors)
Get a :class:`StreamWriter` factory function for the given *encoding*. Get a :class:`~codecs.StreamWriter` factory function for the given *encoding*.
Registry API for Unicode encoding error handlers Registry API for Unicode encoding error handlers
......
...@@ -40,9 +40,9 @@ the :mod:`io` APIs instead. ...@@ -40,9 +40,9 @@ the :mod:`io` APIs instead.
Return the file descriptor associated with *p* as an :c:type:`int`. If the Return the file descriptor associated with *p* as an :c:type:`int`. If the
object is an integer, its value is returned. If not, the object is an integer, its value is returned. If not, the
object's :meth:`fileno` method is called if it exists; the method must return object's :meth:`~io.IOBase.fileno` method is called if it exists; the
an integer, which is returned as the file descriptor value. Sets an method must return an integer, which is returned as the file descriptor
exception and returns ``-1`` on failure. value. Sets an exception and returns ``-1`` on failure.
.. c:function:: PyObject* PyFile_GetLine(PyObject *p, int n) .. c:function:: PyObject* PyFile_GetLine(PyObject *p, int n)
...@@ -50,7 +50,8 @@ the :mod:`io` APIs instead. ...@@ -50,7 +50,8 @@ the :mod:`io` APIs instead.
.. index:: single: EOFError (built-in exception) .. index:: single: EOFError (built-in exception)
Equivalent to ``p.readline([n])``, this function reads one line from the Equivalent to ``p.readline([n])``, this function reads one line from the
object *p*. *p* may be a file object or any object with a :meth:`readline` object *p*. *p* may be a file object or any object with a
:meth:`~io.IOBase.readline`
method. If *n* is ``0``, exactly one line is read, regardless of the length of method. If *n* is ``0``, exactly one line is read, regardless of the length of
the line. If *n* is greater than ``0``, no more than *n* bytes will be read the line. If *n* is greater than ``0``, no more than *n* bytes will be read
from the file; a partial line can be returned. In both cases, an empty string from the file; a partial line can be returned. In both cases, an empty string
......
...@@ -60,8 +60,8 @@ Object Protocol ...@@ -60,8 +60,8 @@ Object Protocol
Generic attribute getter function that is meant to be put into a type Generic attribute getter function that is meant to be put into a type
object's ``tp_getattro`` slot. It looks for a descriptor in the dictionary object's ``tp_getattro`` slot. It looks for a descriptor in the dictionary
of classes in the object's MRO as well as an attribute in the object's of classes in the object's MRO as well as an attribute in the object's
:attr:`__dict__` (if present). As outlined in :ref:`descriptors`, data :attr:`~object.__dict__` (if present). As outlined in :ref:`descriptors`,
descriptors take preference over instance attributes, while non-data data descriptors take preference over instance attributes, while non-data
descriptors don't. Otherwise, an :exc:`AttributeError` is raised. descriptors don't. Otherwise, an :exc:`AttributeError` is raised.
...@@ -85,8 +85,8 @@ Object Protocol ...@@ -85,8 +85,8 @@ Object Protocol
object's ``tp_setattro`` slot. It looks for a data descriptor in the object's ``tp_setattro`` slot. It looks for a data descriptor in the
dictionary of classes in the object's MRO, and if found it takes preference dictionary of classes in the object's MRO, and if found it takes preference
over setting the attribute in the instance dictionary. Otherwise, the over setting the attribute in the instance dictionary. Otherwise, the
attribute is set in the object's :attr:`__dict__` (if present). Otherwise, attribute is set in the object's :attr:`~object.__dict__` (if present).
an :exc:`AttributeError` is raised and ``-1`` is returned. Otherwise, an :exc:`AttributeError` is raised and ``-1`` is returned.
.. c:function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name) .. c:function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name)
...@@ -189,9 +189,9 @@ Object Protocol ...@@ -189,9 +189,9 @@ Object Protocol
be done against every entry in *cls*. The result will be ``1`` when at least one be done against every entry in *cls*. The result will be ``1`` when at least one
of the checks returns ``1``, otherwise it will be ``0``. If *inst* is not a of the checks returns ``1``, otherwise it will be ``0``. If *inst* is not a
class instance and *cls* is neither a type object, nor a class object, nor a class instance and *cls* is neither a type object, nor a class object, nor a
tuple, *inst* must have a :attr:`__class__` attribute --- the class relationship tuple, *inst* must have a :attr:`~instance.__class__` attribute --- the
of the value of that attribute with *cls* will be used to determine the result class relationship of the value of that attribute with *cls* will be used
of this function. to determine the result of this function.
Subclass determination is done in a fairly straightforward way, but includes a Subclass determination is done in a fairly straightforward way, but includes a
...@@ -201,9 +201,9 @@ of. If :class:`A` and :class:`B` are class objects, :class:`B` is a subclass of ...@@ -201,9 +201,9 @@ of. If :class:`A` and :class:`B` are class objects, :class:`B` is a subclass of
either is not a class object, a more general mechanism is used to determine the either is not a class object, a more general mechanism is used to determine the
class relationship of the two objects. When testing if *B* is a subclass of class relationship of the two objects. When testing if *B* is a subclass of
*A*, if *A* is *B*, :c:func:`PyObject_IsSubclass` returns true. If *A* and *B* *A*, if *A* is *B*, :c:func:`PyObject_IsSubclass` returns true. If *A* and *B*
are different objects, *B*'s :attr:`__bases__` attribute is searched in a are different objects, *B*'s :attr:`~class.__bases__` attribute is searched in
depth-first fashion for *A* --- the presence of the :attr:`__bases__` attribute a depth-first fashion for *A* --- the presence of the :attr:`~class.__bases__`
is considered sufficient for this determination. attribute is considered sufficient for this determination.
.. c:function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls) .. c:function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls)
......
...@@ -140,7 +140,7 @@ subtypes but not for instances of :class:`frozenset` or its subtypes. ...@@ -140,7 +140,7 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
Return 1 if found and removed, 0 if not found (no action taken), and -1 if an Return 1 if found and removed, 0 if not found (no action taken), and -1 if an
error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a
:exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`discard` :exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard`
method, this function does not automatically convert unhashable sets into method, this function does not automatically convert unhashable sets into
temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is an not an temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is an not an
instance of :class:`set` or its subtype. instance of :class:`set` or its subtype.
......
...@@ -502,7 +502,7 @@ type objects) *must* have the :attr:`ob_size` field. ...@@ -502,7 +502,7 @@ type objects) *must* have the :attr:`ob_size` field.
On the other hand, even if you know a member can never be part of a cycle, as a On the other hand, even if you know a member can never be part of a cycle, as a
debugging aid you may want to visit it anyway just so the :mod:`gc` module's debugging aid you may want to visit it anyway just so the :mod:`gc` module's
:func:`get_referents` function will include it. :func:`~gc.get_referents` function will include it.
Note that :c:func:`Py_VISIT` requires the *visit* and *arg* parameters to Note that :c:func:`Py_VISIT` requires the *visit* and *arg* parameters to
:c:func:`local_traverse` to have these specific names; don't name them just :c:func:`local_traverse` to have these specific names; don't name them just
...@@ -627,7 +627,7 @@ type objects) *must* have the :attr:`ob_size` field. ...@@ -627,7 +627,7 @@ type objects) *must* have the :attr:`ob_size` field.
reference list head than the base type. Since the list head is always found via reference list head than the base type. Since the list head is always found via
:c:member:`~PyTypeObject.tp_weaklistoffset`, this should not be a problem. :c:member:`~PyTypeObject.tp_weaklistoffset`, this should not be a problem.
When a type defined by a class statement has no :attr:`__slots__` declaration, When a type defined by a class statement has no :attr:`~object.__slots__` declaration,
and none of its base types are weakly referenceable, the type is made weakly and none of its base types are weakly referenceable, the type is made weakly
referenceable by adding a weak reference list head slot to the instance layout referenceable by adding a weak reference list head slot to the instance layout
and setting the :c:member:`~PyTypeObject.tp_weaklistoffset` of that slot's offset. and setting the :c:member:`~PyTypeObject.tp_weaklistoffset` of that slot's offset.
...@@ -817,7 +817,7 @@ type objects) *must* have the :attr:`ob_size` field. ...@@ -817,7 +817,7 @@ type objects) *must* have the :attr:`ob_size` field.
dictionary at a difference offset than the base type. Since the dictionary is dictionary at a difference offset than the base type. Since the dictionary is
always found via :c:member:`~PyTypeObject.tp_dictoffset`, this should not be a problem. always found via :c:member:`~PyTypeObject.tp_dictoffset`, this should not be a problem.
When a type defined by a class statement has no :attr:`__slots__` declaration, When a type defined by a class statement has no :attr:`~object.__slots__` declaration,
and none of its base types has an instance variable dictionary, a dictionary and none of its base types has an instance variable dictionary, a dictionary
slot is added to the instance layout and the :c:member:`~PyTypeObject.tp_dictoffset` is set to slot is added to the instance layout and the :c:member:`~PyTypeObject.tp_dictoffset` is set to
that slot's offset. that slot's offset.
...@@ -825,7 +825,7 @@ type objects) *must* have the :attr:`ob_size` field. ...@@ -825,7 +825,7 @@ type objects) *must* have the :attr:`ob_size` field.
When a type defined by a class statement has a :attr:`__slots__` declaration, When a type defined by a class statement has a :attr:`__slots__` declaration,
the type inherits its :c:member:`~PyTypeObject.tp_dictoffset` from its base type. the type inherits its :c:member:`~PyTypeObject.tp_dictoffset` from its base type.
(Adding a slot named :attr:`__dict__` to the :attr:`__slots__` declaration does (Adding a slot named :attr:`~object.__dict__` to the :attr:`__slots__` declaration does
not have the expected effect, it just causes confusion. Maybe this should be not have the expected effect, it just causes confusion. Maybe this should be
added as a feature just like :attr:`__weakref__` though.) added as a feature just like :attr:`__weakref__` though.)
......
...@@ -967,7 +967,7 @@ These are the generic codec APIs: ...@@ -967,7 +967,7 @@ These are the generic codec APIs:
Create a Unicode object by decoding *size* bytes of the encoded string *s*. Create a Unicode object by decoding *size* bytes of the encoded string *s*.
*encoding* and *errors* have the same meaning as the parameters of the same name *encoding* and *errors* have the same meaning as the parameters of the same name
in the :func:`unicode` built-in function. The codec to be used is looked up in the :func:`str` built-in function. The codec to be used is looked up
using the Python codec registry. Return *NULL* if an exception was raised by using the Python codec registry. Return *NULL* if an exception was raised by
the codec. the codec.
...@@ -977,7 +977,7 @@ These are the generic codec APIs: ...@@ -977,7 +977,7 @@ These are the generic codec APIs:
Encode a Unicode object and return the result as Python bytes object. Encode a Unicode object and return the result as Python bytes object.
*encoding* and *errors* have the same meaning as the parameters of the same *encoding* and *errors* have the same meaning as the parameters of the same
name in the Unicode :meth:`encode` method. The codec to be used is looked up name in the Unicode :meth:`~str.encode` method. The codec to be used is looked up
using the Python codec registry. Return *NULL* if an exception was raised by using the Python codec registry. Return *NULL* if an exception was raised by
the codec. the codec.
...@@ -987,7 +987,7 @@ These are the generic codec APIs: ...@@ -987,7 +987,7 @@ These are the generic codec APIs:
Encode the :c:type:`Py_UNICODE` buffer *s* of the given *size* and return a Python Encode the :c:type:`Py_UNICODE` buffer *s* of the given *size* and return a Python
bytes object. *encoding* and *errors* have the same meaning as the bytes object. *encoding* and *errors* have the same meaning as the
parameters of the same name in the Unicode :meth:`encode` method. The codec parameters of the same name in the Unicode :meth:`~str.encode` method. The codec
to be used is looked up using the Python codec registry. Return *NULL* if an to be used is looked up using the Python codec registry. Return *NULL* if an
exception was raised by the codec. exception was raised by the codec.
......
...@@ -283,7 +283,7 @@ the same library that the Python runtime is using. ...@@ -283,7 +283,7 @@ the same library that the Python runtime is using.
frame *f* is executed, interpreting bytecode and executing calls as needed. frame *f* is executed, interpreting bytecode and executing calls as needed.
The additional *throwflag* parameter can mostly be ignored - if true, then The additional *throwflag* parameter can mostly be ignored - if true, then
it causes an exception to immediately be thrown; this is used for the it causes an exception to immediately be thrown; this is used for the
:meth:`throw` methods of generator objects. :meth:`~generator.throw` methods of generator objects.
.. c:function:: int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) .. c:function:: int PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
......
...@@ -58,8 +58,9 @@ distutils; this section explains building extension modules only. ...@@ -58,8 +58,9 @@ distutils; this section explains building extension modules only.
It is common to pre-compute arguments to :func:`setup`, to better structure the It is common to pre-compute arguments to :func:`setup`, to better structure the
driver script. In the example above, the\ ``ext_modules`` argument to driver script. In the example above, the\ ``ext_modules`` argument to
:func:`setup` is a list of extension modules, each of which is an instance of :func:`setup` is a list of extension modules, each of which is an instance of
the :class:`Extension`. In the example, the instance defines an extension named the :class:`~distutils.extension.Extension`. In the example, the instance
``demo`` which is build by compiling a single source file, :file:`demo.c`. defines an extension named ``demo`` which is build by compiling a single source
file, :file:`demo.c`.
In many cases, building an extension is more complex, since additional In many cases, building an extension is more complex, since additional
preprocessor defines and libraries may be needed. This is demonstrated in the preprocessor defines and libraries may be needed. This is demonstrated in the
......
...@@ -860,9 +860,9 @@ the cycle itself. ...@@ -860,9 +860,9 @@ the cycle itself.
The cycle detector is able to detect garbage cycles and can reclaim them so long The cycle detector is able to detect garbage cycles and can reclaim them so long
as there are no finalizers implemented in Python (:meth:`__del__` methods). as there are no finalizers implemented in Python (:meth:`__del__` methods).
When there are such finalizers, the detector exposes the cycles through the When there are such finalizers, the detector exposes the cycles through the
:mod:`gc` module (specifically, the :mod:`gc` module (specifically, the :attr:`~gc.garbage` variable in that module).
``garbage`` variable in that module). The :mod:`gc` module also exposes a way The :mod:`gc` module also exposes a way to run the detector (the
to run the detector (the :func:`collect` function), as well as configuration :func:`~gc.collect` function), as well as configuration
interfaces and the ability to disable the detector at runtime. The cycle interfaces and the ability to disable the detector at runtime. The cycle
detector is considered an optional component; though it is included by default, detector is considered an optional component; though it is included by default,
it can be disabled at build time using the :option:`--without-cycle-gc` option it can be disabled at build time using the :option:`--without-cycle-gc` option
......
...@@ -137,7 +137,7 @@ This is so that Python knows how much memory to allocate when you call ...@@ -137,7 +137,7 @@ This is so that Python knows how much memory to allocate when you call
If you want your type to be subclassable from Python, and your type has the same If you want your type to be subclassable from Python, and your type has the same
:c:member:`~PyTypeObject.tp_basicsize` as its base type, you may have problems with multiple :c:member:`~PyTypeObject.tp_basicsize` as its base type, you may have problems with multiple
inheritance. A Python subclass of your type will have to list your type first inheritance. A Python subclass of your type will have to list your type first
in its :attr:`__bases__`, or else it will not be able to call your type's in its :attr:`~class.__bases__`, or else it will not be able to call your type's
:meth:`__new__` method without getting an error. You can avoid this problem by :meth:`__new__` method without getting an error. You can avoid this problem by
ensuring that your type has a larger value for :c:member:`~PyTypeObject.tp_basicsize` than its ensuring that your type has a larger value for :c:member:`~PyTypeObject.tp_basicsize` than its
base type does. Most of the time, this will be true anyway, because either your base type does. Most of the time, this will be true anyway, because either your
......
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