8000 Fix more warnings · python/cpython@3919a2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3919a2e

Browse files
committed
Fix more warnings
1 parent 15e7d84 commit 3919a2e

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

Doc/c-api/module.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ An alternate way to specify extensions is to request "multi-phase initialization
282282
Extension modules created this way behave more like Python modules: the
283283
initialization is split between the *creation phase*, when the module object
284284
is created, and the *execution phase*, when it is populated.
285-
The distinction is similar to the :py:meth:`__new__` and :py:meth:`__init__` methods
285+
The distinction is similar to the :py:meth:`!__new__` and :py:meth:`!__init__` methods
286286
of classes.
287287
288288
Unlike modules created using single-phase initialization, these modules are not
@@ -293,7 +293,7 @@ By default, multiple modules created from the same definition should be
293293
independent: changes to one should not affect the others.
294294
This means that all state should be specific to the module object (using e.g.
295295
using :c:func:`PyModule_GetState`), or its contents (such as the module's
296-
:attr:`__dict__` or individual classes created with :c:func:`PyType_FromSpec`).
296+
:attr:`~object.__dict__` or individual classes created with :c:func:`PyType_FromSpec`).
297297
298298
All modules created using multi-phase initialization are expected to support
299299
:ref:`sub-interpreters <sub-interpreter-support>`. Making sure multiple modules

Doc/c-api/set.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ or :class:`frozenset` or instances of their subtypes.
122122
.. c:function:: int PySet_Contains(PyObject *anyset, PyObject *key)
123123
124124
Return ``1`` if found, ``0`` if not found, and ``-1`` if an error is encountered. Unlike
125-
the Python :meth:`__contains__` method, this function does not automatically
125+
the Python :meth:`~object.__contains__` method, this function does not automatically
126126
convert unhashable sets into temporary frozensets. Raise a :exc:`TypeError` if
127127
the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
128128
:class:`set`, :class:`frozenset`, or an instance of a subtype.

Doc/c-api/structures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ definition with the same method name.
393393
*METH_COEXIST*, the default is to skip repeated definitions. Since slot
394394
wrappers are loaded before the method table, the existence of a
395395
*sq_contains* slot, for example, would generate a wrapped method named
396-
:meth:`__contains__` and preclude the loading of a corresponding
396+
:meth:`~object.__contains__` and preclude the loading of a corresponding
397397
PyCFunction with the same name. With the flag defined, the PyCFunction
398398
will be loaded in place of the wrapper object and will co-exist with the
399399
slot. This is helpful because calls to PyCFunctions are optimized more

Doc/c-api/sys.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ Process Control
363363
This function should only be invoked when a condition is detected that would
364364
make it dangerous to continue using the Python interpreter; e.g., when the
365365
object administration appears to be corrupted. On Unix, the standard C library
366-
function :c:func:`abort` is called which will attempt to produce a :file:`core`
366+
function :c:func:`!abort` is called which will attempt to produce a :file:`core`
367367
file.
368368
369369
The ``Py_FatalError()`` function is replaced with a macro which logs

Doc/c-api/typeobj.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
579579
name, followed by a dot, followed by the type name; for built-in types, it
580580
should be just the type name. If the module is a submodule of a package, the
581581
full package name is part of the full module name. For example, a type named
582-
:class:`T` defined in module :mod:`!M` in subpackage :mod:`!Q` in package :mod:`!P`
582+
:class:`!T` defined in module :mod:`!M` in subpackage :mod:`!Q` in package :mod:`!P`
583583
should have the :c:member:`~PyTypeObject.tp_name` initializer ``"P.Q.M.T"``.
584584

585585
For :ref:`dynamically allocated type objects <heap-types>`,

Doc/extending/extending.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ with an exception object::
230230
return m;
231231
}
232232

233-
Note that the Python name for the exception object is :exc:`spam.error`. The
233+
Note that the Python name for the exception object is :exc:`!spam.error`. The
234234
:c:func:`PyErr_NewException` function may create a class with the base class
235235
being :exc:`Exception` (unless another class is passed in instead of ``NULL``),
236236
described in :ref:`bltin-exceptions`.
@@ -245,7 +245,7 @@ raises the exception could cause a core dump or other unintended side effects.
245245
We discuss the use of ``PyMODINIT_FUNC`` as a function return type later in this
246246
sample.
247247

248-
The :exc:`spam.error` exception can be raised in your extension module using a
248+
The :exc:`!spam.error` exception can be raised in your extension module using a
249249
call to :c:func:`PyErr_SetString` as shown below::
250250

251251
static PyObject *
@@ -315,7 +315,7 @@ contexts, as we have seen.
315315
The Module's Method Table and Initialization Function
316316
=====================================================
317317

318-
I promised to show how :c:func:`spam_system` is called from Python programs.
318+
I promised to show how :c:func:`!spam_system` is called from Python programs.
319319
First, we need to list its name and address in a "method table"::
320320

321321
static PyMethodDef SpamMethods[] = {
@@ -1041,13 +1041,13 @@ Let's follow the control flow into :c:func:`PyList_SetItem`. The list owns
10411041
references to all its items, so when item 1 is replaced, it has to dispose of
10421042
the original item 1. Now let's suppose the original item 1 was an instance of a
10431043
user-defined class, and let's further suppose that the class defined a
1044-
:meth:`__del__` method. If this class instance has a reference count of 1,
1045-
disposing of it will call its :meth:`__del__` method.
1044+
:meth:`!__del__` method. If this class instance has a reference count of 1,
1045+
disposing of it will call its :meth:`!__del__` method.
10461046

1047-
Since it is written in Python, the :meth:`__del__` method can execute arbitrary
1047+
Since it is written in Python, the :meth:`!__del__` method can execute arbitrary
10481048
Python code. Could it perhaps do something to invalidate the reference to
1049-
``item`` in :c:func:`bug`? You bet! Assuming that the list passed into
1050-
:c:func:`bug` is accessible to the :meth:`__del__` method, it could execute a
1049+
``item`` in :c:func:`!bug`? You bet! Assuming that the list passed into
1050+
:c:func:`!bug` is accessible to the :meth:`!__del__` method, it could execute a
10511051
statement to the effect of ``del list[0]``, and assuming this was the last
10521052
reference to that object, it would free the memory associated with it, thereby
10531053
invalidating ``item``.
@@ -1068,7 +1068,7 @@ increment the reference count. The correct version of the function reads::
10681068

10691069
This is a true story. An older version of Python contained variants of this bug
10701070
and someone spent a considerable amount of time in a C debugger to figure out
1071-
why his :meth:`__del__` methods would fail...
1071+
why his :meth:`!__del__` methods would fail...
10721072

10731073
The second case of problems with a borrowed reference is a variant involving
10741074
threads. Normally, multiple threads in the Python interpreter can't get in each
@@ -1235,7 +1235,7 @@ The function :c:func:`PySpam_System` is a plain C function, declared
12351235
return system(command);
12361236
}
12371237

1238-
The function :c:func:`spam_system` is modified in a trivial way::
1238+
The function :c:func:`!spam_system` is modified in a trivial way::
12391239

12401240
static PyObject *
12411241
spam_system(PyObject *self, PyObject *args)

Doc/extending/newtypes_tutorial.rst

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ So, if you want to define a new extension type, you need to create a new type
3636
object.
3737

3838
This sort of thing can only be explained by example, so here's a minimal, but
39-
complete, module that defines a new type named :class:`Custom` inside a C
39+
complete, module that defines a new type named :class:`!Custom` inside a C
4040
extension module :mod:`!custom`:
4141

4242
.. note::
@@ -50,9 +50,9 @@ extension module :mod:`!custom`:
5050
Now that's quite a bit to take in at once, but hopefully bits will seem familiar
5151
from the previous chapter. This file defines three things:
5252

53-
#. What a :class:`Custom` **object** contains: this is the ``CustomObject``
54-
struct, which is allocated once for each :class:`Custom` instance.
55-
#. How the :class:`Custom` **type** behaves: this is the ``CustomType`` struct,
53+
#. What a :class:`!Custom` **object** contains: this is the ``CustomObject``
54+
struct, which is allocated once for each :class:`!Custom` instance.
55+
#. How the :class:`!Custom` **type** behaves: this is the ``CustomType`` struct,
5656
which defines a set of flags and function pointers that the interpreter
5757
inspects when specific operations are requested.
5858
#. How to initialize the :mod:`!custom` module: this is the ``PyInit_custom``
@@ -128,15 +128,15 @@ our objects and in some error messages, for example:
128128
129129
Note that the name is a dotted name that includes both the module name and the
130130
name of the type within the module. The module in this case is :mod:`!custom` and
131-
the type is :class:`Custom`, so we set the type name to :class:`custom.Custom`.
131+
the type is :class:`!Custom`, so we set the type name to :class:`custom.Custom`.
132132
Using the real dotted import path is important to make your type compatible
133133
with the :mod:`pydoc` and :mod:`pickle` modules. ::
134134

135135
.tp_basicsize = sizeof(CustomObject),
136136
.tp_itemsize = 0,
137137

138138
This is so that Python knows how much memory to allocate when creating
139-
new :class:`Custom` instances. :c:member:`~PyTypeObject.tp_itemsize` is
139+
new :class:`!Custom` instances. :c:member:`~PyTypeObject.tp_itemsize` is
140140
only used for variable-sized objects and should otherwise be zero.
141141

142142
.. note::
@@ -176,7 +176,7 @@ Everything else in the file should be familiar, except for some code in
176176
if (PyType_Ready(&CustomType) < 0)
177177
return;
178178

179-
This initializes the :class:`Custom` type, filling in a number of members
179+
This initializes the :class:`!Custom` type, filling in a number of members
180180
to the appropriate default values, including :attr:`ob_type` that we initially
181181
set to ``NULL``. ::
182182

@@ -186,7 +186,7 @@ set to ``NULL``. ::
186186
}
187187

188188
This adds the type to the module dictionary. This allows us to create
189-
:class:`Custom` instances by calling the :class:`Custom` class:
189+
:class:`!Custom` instances by calling the :class:`!Custom` class:
190190

191191
.. code-block:: pycon
192192
@@ -237,7 +237,7 @@ adds these capabilities:
237237

238238
This version of the module has a number of changes.
239239

240-
The :class:`Custom` type now has three data attributes in its C struct,
240+
The :class:`!Custom` type now has three data attributes in its C struct,
241241
*first*, *last*, and *number*. The *first* and *last* variables are Python
242242
strings containing first and last names. The *number* attribute is a C integer.
243243

@@ -312,7 +312,7 @@ The ``tp_new`` handler is responsible for creating (as opposed to initializing)
312312
objects of the type. It is exposed in Python as the :meth:`__new__` method.
313313
It is not required to define a ``tp_new`` member, and indeed many extension
314314
types will simply reuse :c:func:`PyType_GenericNew` as done in the first
315-
version of the ``Custom`` type above. In this case, we use the ``tp_new``
315+
version of the :class:`!Custom` type above. In this case, we use the ``tp_new``
316316
handler to initialize the ``first`` and ``last`` attributes to non-``NULL``
317317
default values.
318318

@@ -468,8 +468,8 @@ concatenation of the first and last names. ::
468468
return PyUnicode_FromFormat("%S %S", self->first, self->last);
469469
}
470470

471-
The method is implemented as a C function that takes a :class:`Custom` (or
472-
:class:`Custom` subclass) instance as the first argument. Methods always take an
471+
The method is implemented as a C function that takes a :class:`!Custom` (or
472+
:class:`!Custom` subclass) instance as the first argument. Methods always take an
473473
instance as the first argument. Methods often take positional and keyword
474474
arguments as well, but in this case we don't take any and don't need to accept
475475
a positional argument tuple or keyword argument dictionary. This method is
@@ -530,7 +530,7 @@ Providing finer control over data attributes
530530
============================================
531531

532532
In this section, we'll provide finer control over how the :attr:`first` and
533-
:attr:`last` attributes are set in the :class:`Custom` example. In the previous
533+
:attr:`last` attributes are set in the :class:`!Custom` example. In the previous
534534
version of our module, the instance variables :attr:`first` and :attr:`last`
535535
could be set to non-string values or even deleted. We want to make sure that
536536
these attributes always contain strings.
@@ -569,13 +569,13 @@ getting and setting the :attr:`first` attribute::
569569
return 0;
570570
}
571571

572-
The getter function is passed a :class:`Custom` object and a "closure", which is
572+
The getter function is passed a :class:`!Custom` object and a "closure", which is
573573
a void pointer. In this case, the closure is ignored. (The closure supports an
574574
advanced usage in which definition data is passed to the getter and setter. This
575575
could, for example, be used to allow a single set of getter and setter functions
576576
that decide the attribute to get or set based on data in the closure.)
577577

578-
The setter function is passed the :class:`Custom` object, the new value, and the
578+
The setter function is passed the :class:`!Custom` object, the new value, and the
579579
closure. The new value may be ``NULL``, in which case the attribute is being
580580
deleted. In our setter, we raise an error if the attribute is deleted or if its
581581
new value is not a string.
@@ -664,11 +664,11 @@ still has a reference from itself. Its reference count doesn't drop to zero.
664664
Fortunately, Python's cyclic garbage collector will eventually figure out that
665665
the list is garbage and free it.
666666

667-
In the second version of the :class:`Custom` example, we allowed any kind of
667+
In the second version of the :class:`!Custom` example, we allowed any kind of
668668
object to be stored in the :attr:`first` or :attr:`last` attributes [#]_.
669669
Besides, in the second and third versions, we allowed subclassing
670-
:class:`Custom`, and subclasses may add arbitrary attributes. For any of
671-
those two reasons, :class:`Custom` objects can participate in cycles:
670+
:class:`!Custom`, and subclasses may add arbitrary attributes. For any of
671+
those two reasons, :class:`!Custom` objects can participate in cycles:
672672

673673
.. code-block:: pycon
674674
@@ -678,8 +678,8 @@ those two reasons, :class:`Custom` objects can participate in cycles:
678678
>>> n = Derived()
679679
>>> n.some_attribute = n
680680
681-
To allow a :class:`Custom` instance participating in a reference cycle to
682-
be properly detected and collected by the cyclic GC, our :class:`Custom` type
681+
To allow a :class:`!Custom` instance participating in a reference cycle to
682+
be properly detected and collected by the cyclic GC, our :class:`!Custom` type
683683
needs to fill two additional slots and to enable a flag that enables these slots:
684684

685685
.. literalinclude:: ../includes/custom4.c
@@ -809,7 +809,7 @@ increases an internal counter:
809809
.. literalinclude:: ../includes/sublist.c
810810

811811

812-
As you can see, the source code closely resembles the :class:`Custom` examples in
812+
As you can see, the source code closely resembles the :class:`!Custom` examples in
813813
previous sections. We will break down the main differences between them. ::
814814

815815
typedef struct {
@@ -875,7 +875,7 @@ slot with :c:func:`PyType_GenericNew` -- the allocation function from the base
875875
type will be inherited.
876876

877877
After that, calling :c:func:`PyType_Ready` and adding the type object to the
878-
module is the same as with the basic :class:`Custom` examples.
878+
module is the same as with the basic :class:`!Custom` examples.
879879

880880

881881
.. rubric:: Footnotes

0 commit comments

Comments
 (0)
0