.. c:var:: PyObject* Py_False
The Python ``False`` object. This object has no methods and is
- `immortal <https://peps.python.org/pep-0683/>`_.
+ :term:`immortal`.
-.. versionchanged:: 3.12
- :c:data:`Py_False` is immortal.
+ .. versionchanged:: 3.12
+ :c:data:`Py_False` is :term:`immortal`.
.. c:var:: PyObject* Py_True
The Python ``True`` object. This object has no methods and is
- `immortal <https://peps.python.org/pep-0683/>`_.
+ :term:`immortal`.
-.. versionchanged:: 3.12
- :c:data:`Py_True` is immortal.
+ .. versionchanged:: 3.12
+ :c:data:`Py_True` is :term:`immortal`.
.. c:macro:: Py_RETURN_FALSE
because of the refcount. One simple but less-efficient approach around
this is to use a global lock around all use of some state (or object).
Alternately, effectively immutable objects (like integers or strings)
-can be made safe in spite of their refcounts by making them "immortal".
+can be made safe in spite of their refcounts by making them :term:`immortal`.
In fact, this has been done for the builtin singletons, small integers,
and a number of other builtin objects.
.. c:member:: int show_ref_count
- Show total reference count at exit (excluding immortal objects)?
+ Show total reference count at exit (excluding :term:`immortal` objects)?
Set to ``1`` by :option:`-X showrefcount <-X>` command line option.
.. c:var:: PyObject* Py_None
The Python ``None`` object, denoting lack of value. This object has no methods
- and is `immortal <https://peps.python.org/pep-0683/>`_.
+ and is :term:`immortal`.
-.. versionchanged:: 3.12
- :c:data:`Py_None` is immortal.
+ .. versionchanged:: 3.12
+ :c:data:`Py_None` is :term:`immortal`.
.. c:macro:: Py_RETURN_NONE
Note that the returned value may not actually reflect how many
references to the object are actually held. For example, some
- objects are "immortal" and have a very high refcount that does not
+ objects are :term:`immortal` and have a very high refcount that does not
reflect the actual number of references. Consequently, do not rely
on the returned value to be accurate, other than a value of 0 or 1.
Set the object *o* reference counter to *refcnt*.
- Note that this function has no effect on
- `immortal <https://peps.python.org/pep-0683/>`_
- objects.
+ This function has no effect on :term:`immortal` objects.
.. versionadded:: 3.9
Indicate taking a new :term:`strong reference` to object *o*,
indicating it is in use and should not be destroyed.
+ This function has no effect on :term:`immortal` objects.
+
This function is usually used to convert a :term:`borrowed reference` to a
:term:`strong reference` in-place. The :c:func:`Py_NewRef` function can be
used to create a new :term:`strong reference`.
Release a :term:`strong reference` to object *o*, indicating the
reference is no longer used.
+ This function has no effect on :term:`immortal` objects.
+
Once the last :term:`strong reference` is released
(i.e. the object's reference count reaches 0),
the object's type's deallocation
.. c:var:: PyObject *Py_Ellipsis
The Python ``Ellipsis`` object. This object has no methods. Like
- :c:data:`Py_None`, it is an `immortal <https://peps.python.org/pep-0683/>`_.
- singleton object.
+ :c:data:`Py_None`, it is an :term:`immortal` singleton object.
.. versionchanged:: 3.12
:c:data:`Py_Ellipsis` is immortal.
:ref:`idle` is a basic editor and interpreter environment
which ships with the standard distribution of Python.
+ immortal
+ If an object is immortal, its reference count is never modified, and
+ therefore it is never deallocated.
+
+ Built-in strings and singletons are immortal objects. For example,
+ :const:`True` and :const:`None` singletons are immmortal.
+
+ See `PEP 683 – Immortal Objects, Using a Fixed Refcount
+ <https://peps.python.org/pep-0683/>`_ for more information.
+
immutable
An object with a fixed value. Immutable objects include numbers, strings and
tuples. Such an object cannot be altered. A new object has to
reference count
The number of references to an object. When the reference count of an
object drops to zero, it is deallocated. Some objects are
- "immortal" and have reference counts that are never modified, and
+ :term:`immortal` and have reference counts that are never modified, and
therefore the objects are never deallocated. Reference counting is
generally not visible to Python code, but it is a key element of the
:term:`CPython` implementation. Programmers can call the
Note that the returned value may not actually reflect how many
references to the object are actually held. For example, some
- objects are "immortal" and have a very high refcount that does not
+ objects are :term:`immortal` and have a very high refcount that does not
reflect the actual number of references. Consequently, do not rely
on the returned value to be accurate, other than a value of 0 or 1.
names used in Python programs are automatically interned, and the dictionaries
used to hold module, class or instance attributes have interned keys.
- Interned strings are not immortal; you must keep a reference to the return
- value of :func:`intern` around to benefit from it.
+ Interned strings are not :term:`immortal`; you must keep a reference to the
+ return value of :func:`intern` around to benefit from it.
.. function:: is_finalizing()