| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,18 +34,20 @@ There are a few functions specific to Python functions. | |||
| 34 | 34 | Return a new function object associated with the code object *code*. *globals* | |
| 35 | 35 | must be a dictionary with the global variables accessible to the function. | |
| 36 | 36 | ||
| 37 | - The function's docstring and name are retrieved from the code object. *__module__* | ||
| 37 | + The function's docstring and name are retrieved from the code object. | ||
| 38 | + :func:`~function.__module__` | ||
| 38 | 39 | is retrieved from *globals*. The argument defaults, annotations and closure are | |
| 39 | - set to ``NULL``. *__qualname__* is set to the same value as the code object's | ||
| 40 | - :attr:`~codeobject.co_qualname` field. | ||
| 40 | + set to ``NULL``. :attr:`~function.__qualname__` is set to the same value as | ||
| 41 | + the code object's :attr:`~codeobject.co_qualname` field. | ||
| 41 | 42 | ||
| 42 | 43 | ||
| 43 | 44 | .. c:function:: PyObject* PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname) | |
| 44 | 45 | ||
| 45 | 46 | As :c:func:`PyFunction_New`, but also allows setting the function object's | |
| 46 | - ``__qualname__`` attribute. *qualname* should be a unicode object or ``NULL``; | ||
| 47 | - if ``NULL``, the ``__qualname__`` attribute is set to the same value as the | ||
| 48 | - code object's :attr:`~codeobject.co_qualname` field. | ||
| 47 | + :attr:`~function.__qualname__` attribute. | ||
| 48 | + *qualname* should be a unicode object or ``NULL``; | ||
| 49 | + if ``NULL``, the :attr:`!__qualname__` attribute is set to the same value as | ||
| 50 | + the code object's :attr:`~codeobject.co_qualname` field. | ||
| 49 | 51 | ||
| 50 | 52 | .. versionadded:: 3.3 | |
| 51 | 53 | ||
@@ -62,11 +64,12 @@ There are a few functions specific to Python functions. | |||
| 62 | 64 | ||
| 63 | 65 | .. c:function:: PyObject* PyFunction_GetModule(PyObject *op) | |
| 64 | 66 | ||
| 65 | - Return a :term:`borrowed reference` to the *__module__* attribute of the | ||
| 66 | - function object *op*. It can be *NULL*. | ||
| 67 | + Return a :term:`borrowed reference` to the :attr:`~function.__module__` | ||
| 68 | + attribute of the :ref:`function object <user-defined-funcs>` *op*. | ||
| 69 | + It can be *NULL*. | ||
| 67 | 70 | ||
| 68 | - This is normally a string containing the module name, but can be set to any | ||
| 69 | - other object by Python code. | ||
| 71 | + This is normally a :class:`string <str>` containing the module name, | ||
| 72 | + but can be set to any other object by Python code. | ||
| 70 | 73 | ||
| 71 | 74 | ||
| 72 | 75 | .. c:function:: PyObject* PyFunction_GetDefaults(PyObject *op) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -153,7 +153,8 @@ on an arbitrary object ``o``: | |||
| 153 | 153 | unwrap it by accessing either ``o.__wrapped__`` or ``o.func`` as | |
| 154 | 154 | appropriate, until you have found the root unwrapped function. | |
| 155 | 155 | * If ``o`` is a callable (but not a class), use | |
| 156 | - ``o.__globals__`` as the globals when calling :func:`eval`. | ||
| 156 | + :attr:`o.__globals__ <function.__globals__>` as the globals when calling | ||
| 157 | + :func:`eval`. | ||
| 157 | 158 | ||
| 158 | 159 | However, not all string values used as annotations can | |
| 159 | 160 | be successfully turned into Python values by :func:`eval`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1332,7 +1332,8 @@ Using the non-data descriptor protocol, a pure Python version of | |||
| 1332 | 1332 | The :func:`functools.update_wrapper` call adds a ``__wrapped__`` attribute | |
| 1333 | 1333 | that refers to the underlying function. Also it carries forward | |
| 1334 | 1334 | the attributes necessary to make the wrapper look like the wrapped | |
| 1335 | - function: ``__name__``, ``__qualname__``, ``__doc__``, and ``__annotations__``. | ||
| 1335 | + function: :attr:`~function.__name__`, :attr:`~function.__qualname__`, | ||
| 1336 | + :attr:`~function.__doc__`, and :attr:`~function.__annotations__`. | ||
| 1336 | 1337 | ||
| 1337 | 1338 | .. testcode:: | |
| 1338 | 1339 | :hide: | |
@@ -1543,8 +1544,9 @@ chained together. In Python 3.11, this functionality was deprecated. | |||
| 1543 | 1544 | The :func:`functools.update_wrapper` call in ``ClassMethod`` adds a | |
| 1544 | 1545 | ``__wrapped__`` attribute that refers to the underlying function. Also | |
| 1545 | 1546 | it carries forward the attributes necessary to make the wrapper look | |
| 1546 | - like the wrapped function: ``__name__``, ``__qualname__``, ``__doc__``, | ||
| 1547 | - and ``__annotations__``. | ||
| 1547 | + like the wrapped function: :attr:`~function.__name__`, | ||
| 1548 | + :attr:`~function.__qualname__`, :attr:`~function.__doc__`, | ||
| 1549 | + and :attr:`~function.__annotations__`. | ||
| 1548 | 1550 | ||
| 1549 | 1551 | ||
| 1550 | 1552 | Member objects and __slots__ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1208,9 +1208,10 @@ Classes and functions | |||
| 1208 | 1208 | * If ``obj`` is a class, ``globals`` defaults to | |
| 1209 | 1209 | ``sys.modules[obj.__module__].__dict__`` and ``locals`` defaults | |
| 1210 | 1210 | to the ``obj`` class namespace. | |
| 1211 | - * If ``obj`` is a callable, ``globals`` defaults to ``obj.__globals__``, | ||
| 1211 | + * If ``obj`` is a callable, ``globals`` defaults to | ||
| 1212 | + :attr:`obj.__globals__ <function.__globals__>`, | ||
| 1212 | 1213 | although if ``obj`` is a wrapped function (using | |
| 1213 | - ``functools.update_wrapper()``) it is first unwrapped. | ||
| 1214 | + :func:`functools.update_wrapper`) it is first unwrapped. | ||
| 1214 | 1215 | ||
| 1215 | 1216 | Calling ``get_annotations`` is best practice for accessing the | |
| 1216 | 1217 | annotations dict of any object. See :ref:`annotations-howto` for | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5381,10 +5381,10 @@ Code objects are used by the implementation to represent "pseudo-compiled" | |||
| 5381 | 5381 | executable Python code such as a function body. They differ from function | |
| 5382 | 5382 | objects because they don't contain a reference to their global execution | |
| 5383 | 5383 | environment. Code objects are returned by the built-in :func:`compile` function | |
| 5384 | - and can be extracted from function objects through their :attr:`__code__` | ||
| 5385 | - attribute. See also the :mod:`code` module. | ||
| 5384 | + and can be extracted from function objects through their | ||
| 5385 | + :attr:`~function.__code__` attribute. See also the :mod:`code` module. | ||
| 5386 | 5386 | ||
| 5387 | - Accessing ``__code__`` raises an :ref:`auditing event <auditing>` | ||
| 5387 | + Accessing :attr:`~function.__code__` raises an :ref:`auditing event <auditing>` | ||
| 5388 | 5388 | ``object.__getattr__`` with arguments ``obj`` and ``"__code__"``. | |
| 5389 | 5389 | ||
| 5390 | 5390 | .. index:: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,12 +84,12 @@ alone XML-RPC servers. | |||
| 84 | 84 | ||
| 85 | 85 | Register a function that can respond to XML-RPC requests. If *name* is given, | |
| 86 | 86 | it will be the method name associated with *function*, otherwise | |
| 87 | - ``function.__name__`` will be used. *name* is a string, and may contain | ||
| 87 | + :attr:`function.__name__` will be used. *name* is a string, and may contain | ||
| 88 | 88 | characters not legal in Python identifiers, including the period character. | |
| 89 | 89 | ||
| 90 | 90 | This method can also be used as a decorator. When used as a decorator, | |
| 91 | 91 | *name* can only be given as a keyword argument to register *function* under | |
| 92 | - *name*. If no *name* is given, ``function.__name__`` will be used. | ||
| 92 | + *name*. If no *name* is given, :attr:`function.__name__` will be used. | ||
| 93 | 93 | ||
| 94 | 94 | .. versionchanged:: 3.7 | |
| 95 | 95 | :meth:`register_function` can be used as a decorator. | |
@@ -298,12 +298,12 @@ requests sent to Python CGI scripts. | |||
| 298 | 298 | ||
| 299 | 299 | Register a function that can respond to XML-RPC requests. If *name* is given, | |
| 300 | 300 | it will be the method name associated with *function*, otherwise | |
| 301 | - ``function.__name__`` will be used. *name* is a string, and may contain | ||
| 301 | + :attr:`function.__name__` will be used. *name* is a string, and may contain | ||
| 302 | 302 | characters not legal in Python identifiers, including the period character. | |
| 303 | 303 | ||
| 304 | 304 | This method can also be used as a decorator. When used as a decorator, | |
| 305 | 305 | *name* can only be given as a keyword argument to register *function* under | |
| 306 | - *name*. If no *name* is given, ``function.__name__`` will be used. | ||
| 306 | + *name*. If no *name* is given, :attr:`function.__name__` will be used. | ||
| 307 | 307 | ||
| 308 | 308 | .. versionchanged:: 3.7 | |
| 309 | 309 | :meth:`register_function` can be used as a decorator. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1261,7 +1261,8 @@ except that the original function is not temporarily bound to the name ``func``. | |||
| 1261 | 1261 | A list of :ref:`type parameters <type-params>` may be given in square brackets | |
| 1262 | 1262 | between the function's name and the opening parenthesis for its parameter list. | |
| 1263 | 1263 | This indicates to static type checkers that the function is generic. At runtime, | |
| 1264 | - the type parameters can be retrieved from the function's ``__type_params__`` | ||
| 1264 | + the type parameters can be retrieved from the function's | ||
| 1265 | + :attr:`~function.__type_params__` | ||
| 1265 | 1266 | attribute. See :ref:`generic-functions` for more. | |
| 1266 | 1267 | ||
| 1267 | 1268 | .. versionchanged:: 3.12 | |
@@ -1868,8 +1869,8 @@ like ``TYPE_PARAMS_OF_ListOrSet`` are not actually bound at runtime. | |||
| 1868 | 1869 | are mappings. | |
| 1869 | 1870 | ||
| 1870 | 1871 | .. [#] A string literal appearing as the first statement in the function body is | |
| 1871 | - transformed into the function's ``__doc__`` attribute and therefore the | ||
| 1872 | - function's :term:`docstring`. | ||
| 1872 | + transformed into the function's :attr:`~function.__doc__` attribute and | ||
| 1873 | + therefore the function's :term:`docstring`. | ||
| 1873 | 1874 | ||
| 1874 | 1875 | .. [#] A string literal appearing as the first statement in the class body is | |
| 1875 | 1876 | transformed into the namespace's ``__doc__`` item and therefore the class's | |
| Back | FazBrowse Home | New Git URL |
0 commit comments