From 55747ced8d9d6ba91ecc907b53b895551297fe64 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Mon, 9 Nov 2026 09:12:24 +0000 Subject: [PATCH] Doc: Correct FAQ explanations and extension debugging instructions --- Doc/faq/design.rst | 2 +- Doc/faq/extending.rst | 25 ++++++++++--------------- Doc/faq/programming.rst | 33 ++++----------------------------- 3 files changed, 15 insertions(+), 45 deletions(-) diff --git a/Doc/faq/design.rst b/Doc/faq/design.rst index 3a3e16b3bcf3db..ca5fcc154f7312 100644 --- a/Doc/faq/design.rst +++ b/Doc/faq/design.rst @@ -401,7 +401,7 @@ library that are impossible to free (e.g. a tool like Purify will complain about these). Python is, however, aggressive about cleaning up memory on exit and does try to destroy every single object. -If you want to force Python to delete certain things on deallocation use the +If you want to force Python to delete certain things when Python exits, use the :mod:`atexit` module to run a function that will force those deletions. diff --git a/Doc/faq/extending.rst b/Doc/faq/extending.rst index e0e6ddd04af76d..555c312b913769 100644 --- a/Doc/faq/extending.rst +++ b/Doc/faq/extending.rst @@ -209,25 +209,20 @@ minor that it doesn't seem worth the effort.) How do I debug an extension? ---------------------------- -When using GDB with dynamically loaded extensions, you can't set a breakpoint in -your extension until your extension is loaded. - -In your ``.gdbinit`` file (or interactively), add the command: - -.. code-block:: none - - br _PyImport_LoadDynamicModule - -Then, when you run GDB: +When using GDB with dynamically loaded extensions, enable pending breakpoints +to set a breakpoint before the extension is loaded. For example, to stop in +a function named ``myfunction``: .. code-block:: shell-session $ gdb /local/bin/python - gdb) run myscript.py - gdb) continue # repeat until your extension is loaded - gdb) finish # so that your extension is loaded - gdb) br myfunction.c:50 - gdb) continue + (gdb) set breakpoint pending on + (gdb) break myfunction + (gdb) run myscript.py + +GDB resolves the breakpoint when the extension is loaded and stops when the +function is called. You can also set a pending breakpoint directly in your +extension's source code, for example with ``break myfunction.c:50``. I want to compile a Python module on my Linux system, but some files are missing. Why? -------------------------------------------------------------------------------------- diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst index 5eb8dff1ee8052..fe2e8587eb201b 100644 --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -1198,8 +1198,7 @@ Use the :func:`reversed` built-in function:: for x in reversed(sequence): ... # do something with x ... -This won't touch your original sequence, but build a new copy with reversed -order to iterate over. +This returns a reverse iterator without modifying your original sequence. How do you remove duplicates from a list? @@ -1642,8 +1641,8 @@ Use the built-in :func:`super` function:: In the example, :func:`super` will automatically determine the instance from which it was called (the ``self`` value), look up the :term:`method resolution -order` (MRO) with ``type(self).__mro__``, and return the next in line after -``Derived`` in the MRO: ``Base``. +order` (MRO) with ``type(self).__mro__``, and return a proxy that searches for +methods starting with the next class after ``Derived`` in the MRO: ``Base``. How can I organize my code to make it easier to change the base class? @@ -1686,7 +1685,7 @@ C)`` holds, unless overridden by ``c`` itself or by some class on the base-class search path from ``c.__class__`` back to ``C``. Caution: within a method of C, an assignment like ``self.count = 42`` creates a -new and unrelated instance named "count" in ``self``'s own dict. Rebinding of a +new and unrelated attribute named "count" in ``self``'s own dict. Rebinding of a class-static data name must always specify the class whether inside a method or not:: @@ -2055,30 +2054,6 @@ relevant instance attributes are mutable, the ``cached_property`` approach can't be made to work because it cannot detect changes to the attributes. -To make the ``lru_cache`` approach work when the *station_id* is mutable, -the class needs to define the :meth:`~object.__eq__` and :meth:`~object.__hash__` -methods so that the cache can detect relevant attribute updates:: - - class Weather: - "Example with a mutable station identifier" - - def __init__(self, station_id): - self.station_id = station_id - - def change_station(self, station_id): - self.station_id = station_id - - def __eq__(self, other): - return self.station_id == other.station_id - - def __hash__(self): - return hash(self.station_id) - - @lru_cache(maxsize=20) - def historic_rainfall(self, date, units='cm'): - 'Rainfall on a given date' - # Depends on the station_id, date, and units. - Modules =======