Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/faq/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
25 changes: 10 additions & 15 deletions Doc/faq/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
--------------------------------------------------------------------------------------
Expand Down
33 changes: 4 additions & 29 deletions Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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::

Expand Down Expand Up @@ -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
=======
Expand Down
Loading