Skip to content

Commit 081a228

Browse files
Merge branch 'main' into docs/dbmdumb/reword
2 parents 0845fb6 + 65cf5dc commit 081a228

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3741
-274
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ Lib/test/test_type_*.py @JelleZijlstra
4242
Lib/test/test_capi/test_misc.py @markshannon @gvanrossum
4343
Tools/c-analyzer/ @ericsnowcurrently
4444

45+
# dbm
46+
**/*dbm* @corona10 @erlend-aasland @serhiy-storchaka
47+
4548
# Exceptions
4649
Lib/traceback.py @iritkatriel
4750
Lib/test/test_except*.py @iritkatriel

Doc/c-api/file.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ the :mod:`io` APIs instead.
6565
Overrides the normal behavior of :func:`io.open_code` to pass its parameter
6666
through the provided handler.
6767
68-
The handler is a function of type :c:expr:`PyObject *(\*)(PyObject *path,
69-
void *userData)`, where *path* is guaranteed to be :c:type:`PyUnicodeObject`.
68+
The handler is a function of type:
69+
70+
.. c:type:: Py_OpenCodeHookFunction
71+
72+
Equivalent of :c:expr:`PyObject *(\*)(PyObject *path,
73+
void *userData)`, where *path* is guaranteed to be
74+
:c:type:`PyUnicodeObject`.
7075
7176
The *userData* pointer is passed into the hook function. Since hook
7277
functions may be called from different runtimes, this pointer should not

Doc/c-api/object.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ Object Protocol
1919
to NotImplemented and return it).
2020

2121

22+
.. c:macro:: Py_PRINT_RAW
23+
24+
Flag to be used with multiple functions that print the object (like
25+
:c:func:`PyObject_Print` and :c:func:`PyFile_WriteObject`).
26+
If passed, these function would use the :func:`str` of the object
27+
instead of the :func:`repr`.
28+
29+
2230
.. c:function:: int PyObject_Print(PyObject *o, FILE *fp, int flags)
2331
2432
Print an object *o*, on file *fp*. Returns ``-1`` on error. The flags argument

Doc/library/dbm.rst

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ the Oracle Berkeley DB.
2828
available --- :mod:`dbm.gnu`, :mod:`dbm.ndbm` or :mod:`dbm.dumb` --- should
2929
be used to open a given file.
3030

31-
Returns one of the following values: ``None`` if the file can't be opened
32-
because it's unreadable or doesn't exist; the empty string (``''``) if the
33-
file's format can't be guessed; or a string containing the required module
34-
name, such as ``'dbm.ndbm'`` or ``'dbm.gnu'``.
31+
Return one of the following values:
32+
33+
* ``None`` if the file can't be opened because it's unreadable or doesn't exist
34+
* the empty string (``''``) if the file's format can't be guessed
35+
* a string containing the required module name, such as ``'dbm.ndbm'`` or ``'dbm.gnu'``
3536

3637
.. versionchanged:: 3.11
3738
Accepts :term:`path-like object` for filename.
@@ -74,13 +75,13 @@ the Oracle Berkeley DB.
7475
modified by the prevailing umask).
7576

7677

77-
The object returned by :func:`.open` supports the same basic functionality as
78-
dictionaries; keys and their corresponding values can be stored, retrieved, and
79-
deleted, and the :keyword:`in` operator and the :meth:`keys` method are
80-
available, as well as :meth:`get` and :meth:`setdefault`.
78+
The object returned by :func:`open` supports the same basic functionality as a
79+
:class:`dict`; keys and their corresponding values can be stored, retrieved, and
80+
deleted, and the :keyword:`in` operator and the :meth:`!keys` method are
81+
available, as well as :meth:`!get` and :meth:`!setdefault`.
8182

8283
.. versionchanged:: 3.2
83-
:meth:`get` and :meth:`setdefault` are now available in all database modules.
84+
:meth:`!get` and :meth:`!setdefault` are now available in all database modules.
8485

8586
.. versionchanged:: 3.8
8687
Deleting a key from a read-only database raises database module specific error
@@ -89,7 +90,7 @@ available, as well as :meth:`get` and :meth:`setdefault`.
8990
.. versionchanged:: 3.11
9091
Accepts :term:`path-like object` for file.
9192

92-
Key and values are always stored as bytes. This means that when
93+
Key and values are always stored as :class:`bytes`. This means that when
9394
strings are used they are implicitly converted to the default encoding before
9495
being stored.
9596

@@ -137,37 +138,38 @@ then prints out the contents of the database::
137138
The individual submodules are described in the following sections.
138139

139140

140-
:mod:`dbm.gnu` --- GNU's reinterpretation of dbm
141-
------------------------------------------------
141+
:mod:`dbm.gnu` --- GNU database manager
142+
---------------------------------------
142143

143144
.. module:: dbm.gnu
144145
:platform: Unix
145-
:synopsis: GNU's reinterpretation of dbm.
146+
:synopsis: GNU database manager
146147

147148
**Source code:** :source:`Lib/dbm/gnu.py`
148149

149150
--------------
150151

151-
This module is quite similar to the :mod:`dbm` module, but uses the GNU library
152-
``gdbm`` instead to provide some additional functionality. Please note that the
153-
file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible.
152+
The :mod:`dbm.gnu` module provides an interface to the :abbr:`GDBM (GNU dbm)`
153+
library, similar to the :mod:`dbm.ndbm` module, but with additional
154+
functionality like crash tolerance.
155+
156+
:class:`!gdbm` objects behave similar to :term:`mappings <mapping>`,
157+
except that keys and values are always converted to :class:`bytes` before storing,
158+
and the :meth:`!items` and :meth:`!values` methods are not supported.
154159

155-
The :mod:`dbm.gnu` module provides an interface to the GNU DBM library.
156-
``dbm.gnu.gdbm`` objects behave like mappings (dictionaries), except that keys and
157-
values are always converted to bytes before storing. Printing a ``gdbm``
158-
object doesn't print the
159-
keys and values, and the :meth:`items` and :meth:`values` methods are not
160-
supported.
160+
.. note::
161+
The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are
162+
incompatible and can not be used interchangeably.
161163

162164
.. exception:: error
163165

164166
Raised on :mod:`dbm.gnu`-specific errors, such as I/O errors. :exc:`KeyError` is
165167
raised for general mapping errors like specifying an incorrect key.
166168

167169

168-
.. function:: open(filename[, flag[, mode]])
170+
.. function:: open(filename, flag="r", mode=0o666, /)
169171

170-
Open a ``gdbm`` database and return a :class:`gdbm` object. The *filename*
172+
Open a GDBM database and return a :class:`!gdbm` object. The *filename*
171173
argument is the name of the database file.
172174

173175
The optional *flag* argument can be:
@@ -196,14 +198,14 @@ supported.
196198
| ``'u'`` | Do not lock database. |
197199
+---------+--------------------------------------------+
198200

199-
Not all flags are valid for all versions of ``gdbm``. The module constant
201+
Not all flags are valid for all versions of GDBM. The module constant
200202
:const:`open_flags` is a string of supported flag characters. The exception
201203
:exc:`error` is raised if an invalid flag is specified.
202204

203205
The optional *mode* argument is the Unix mode of the file, used only when the
204206
database has to be created. It defaults to octal ``0o666``.
205207

206-
In addition to the dictionary-like methods, ``gdbm`` objects have the
208+
In addition to the dictionary-like methods, :class:`gdbm` objects have the
207209
following methods:
208210

209211
.. versionchanged:: 3.11
@@ -212,7 +214,7 @@ supported.
212214
.. method:: gdbm.firstkey()
213215

214216
It's possible to loop over every key in the database using this method and the
215-
:meth:`nextkey` method. The traversal is ordered by ``gdbm``'s internal
217+
:meth:`nextkey` method. The traversal is ordered by GDBM's internal
216218
hash values, and won't be sorted by the key values. This method returns
217219
the starting key.
218220

@@ -230,7 +232,7 @@ supported.
230232
.. method:: gdbm.reorganize()
231233

232234
If you have carried out a lot of deletions and would like to shrink the space
233-
used by the ``gdbm`` file, this routine will reorganize the database. ``gdbm``
235+
used by the GDBM file, this routine will reorganize the database. :class:`!gdbm`
234236
objects will not shorten the length of a database file except by using this
235237
reorganization; otherwise, deleted file space will be kept and reused as new
236238
(key, value) pairs are added.
@@ -242,11 +244,11 @@ supported.
242244

243245
.. method:: gdbm.close()
244246

245-
Close the ``gdbm`` database.
247+
Close the GDBM database.
246248

247249
.. method:: gdbm.clear()
248250

249-
Remove all items from the ``gdbm`` database.
251+
Remove all items from the GDBM database.
250252

251253
.. versionadded:: 3.13
252254

Doc/library/glob.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ The :mod:`glob` module defines the following functions:
147147

148148
.. seealso::
149149

150-
:meth:`pathlib.PurePath.match` and :meth:`pathlib.Path.glob` methods,
151-
which call this function to implement pattern matching and globbing.
150+
:meth:`pathlib.PurePath.full_match` and :meth:`pathlib.Path.glob`
151+
methods, which call this function to implement pattern matching and
152+
globbing.
152153

153154
.. versionadded:: 3.13
154155

Doc/library/pathlib.rst

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -559,55 +559,55 @@ Pure paths provide the following methods and properties:
559559
PureWindowsPath('c:/Program Files')
560560

561561

562-
.. method:: PurePath.match(pattern, *, case_sensitive=None)
562+
.. method:: PurePath.full_match(pattern, *, case_sensitive=None)
563563

564564
Match this path against the provided glob-style pattern. Return ``True``
565-
if matching is successful, ``False`` otherwise.
566-
567-
If *pattern* is relative, the path can be either relative or absolute,
568-
and matching is done from the right::
565+
if matching is successful, ``False`` otherwise. For example::
569566

570-
>>> PurePath('a/b.py').match('*.py')
571-
True
572-
>>> PurePath('/a/b/c.py').match('b/*.py')
567+
>>> PurePath('a/b.py').full_match('a/*.py')
573568
True
574-
>>> PurePath('/a/b/c.py').match('a/*.py')
569+
>>> PurePath('a/b.py').full_match('*.py')
575570
False
571+
>>> PurePath('/a/b/c.py').full_match('/a/**')
572+
True
573+
>>> PurePath('/a/b/c.py').full_match('**/*.py')
574+
True
576575

577-
If *pattern* is absolute, the path must be absolute, and the whole path
578-
must match::
576+
As with other methods, case-sensitivity follows platform defaults::
579577

580-
>>> PurePath('/a.py').match('/*.py')
581-
True
582-
>>> PurePath('a/b.py').match('/*.py')
578+
>>> PurePosixPath('b.py').full_match('*.PY')
583579
False
580+
>>> PureWindowsPath('b.py').full_match('*.PY')
581+
True
584582

585-
The *pattern* may be another path object; this speeds up matching the same
586-
pattern against multiple files::
583+
Set *case_sensitive* to ``True`` or ``False`` to override this behaviour.
587584

588-
>>> pattern = PurePath('*.py')
589-
>>> PurePath('a/b.py').match(pattern)
590-
True
585+
.. versionadded:: 3.13
591586

592-
.. versionchanged:: 3.12
593-
Accepts an object implementing the :class:`os.PathLike` interface.
594587

595-
As with other methods, case-sensitivity follows platform defaults::
588+
.. method:: PurePath.match(pattern, *, case_sensitive=None)
596589

597-
>>> PurePosixPath('b.py').match('*.PY')
598-
False
599-
>>> PureWindowsPath('b.py').match('*.PY')
590+
Match this path against the provided non-recursive glob-style pattern.
591+
Return ``True`` if matching is successful, ``False`` otherwise.
592+
593+
This method is similar to :meth:`~PurePath.full_match`, but empty patterns
594+
aren't allowed (:exc:`ValueError` is raised), the recursive wildcard
595+
"``**``" isn't supported (it acts like non-recursive "``*``"), and if a
596+
relative pattern is provided, then matching is done from the right::
597+
598+
>>> PurePath('a/b.py').match('*.py')
599+
True
600+
>>> PurePath('/a/b/c.py').match('b/*.py')
600601
True
602+
>>> PurePath('/a/b/c.py').match('a/*.py')
603+
False
601604

602-
Set *case_sensitive* to ``True`` or ``False`` to override this behaviour.
605+
.. versionchanged:: 3.12
606+
The *pattern* parameter accepts a :term:`path-like object`.
603607

604608
.. versionchanged:: 3.12
605609
The *case_sensitive* parameter was added.
606610

607-
.. versionchanged:: 3.13
608-
Support for the recursive wildcard "``**``" was added. In previous
609-
versions, it acted like the non-recursive wildcard "``*``".
610-
611611

612612
.. method:: PurePath.relative_to(other, walk_up=False)
613613

Doc/library/sys.monitoring.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ following IDs are pre-defined to make co-operation of tools easier::
7575
sys.monitoring.PROFILER_ID = 2
7676
sys.monitoring.OPTIMIZER_ID = 5
7777

78-
There is no obligation to set an ID, nor is there anything preventing a tool
79-
from using an ID even it is already in use.
80-
However, tools are encouraged to use a unique ID and respect other tools.
8178

8279
Events
8380
------

Doc/library/threading.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,10 @@ All methods are executed atomically.
534534
lock, subsequent attempts to acquire it block, until it is released; any
535535
thread may release it.
536536

537-
Note that ``Lock`` is actually a factory function which returns an instance
538-
of the most efficient version of the concrete Lock class that is supported
539-
by the platform.
537+
.. versionchanged:: 3.13
538+
``Lock`` is now a class. In earlier Pythons, ``Lock`` was a factory
539+
function which returned an instance of the underlying private lock
540+
type.
540541

541542

542543
.. method:: acquire(blocking=True, timeout=-1)

Doc/tools/.nitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
Doc/c-api/descriptor.rst
66
Doc/c-api/exceptions.rst
7-
Doc/c-api/file.rst
87
Doc/c-api/float.rst
98
Doc/c-api/gcsupport.rst
109
Doc/c-api/init.rst
1110
Doc/c-api/init_config.rst
1211
Doc/c-api/intro.rst
1312
Doc/c-api/memoryview.rst
1413
Doc/c-api/module.rst
15-
Doc/c-api/object.rst
1614
Doc/c-api/stable.rst
1715
Doc/c-api/sys.rst
1816
Doc/c-api/type.rst

Doc/whatsnew/3.13.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ pathlib
336336
object from a 'file' URI (``file:/``).
337337
(Contributed by Barney Gale in :gh:`107465`.)
338338

339-
* Add support for recursive wildcards in :meth:`pathlib.PurePath.match`.
339+
* Add :meth:`pathlib.PurePath.full_match` for matching paths with
340+
shell-style wildcards, including the recursive wildcard "``**``".
340341
(Contributed by Barney Gale in :gh:`73435`.)
341342

342343
* Add *follow_symlinks* keyword-only argument to :meth:`pathlib.Path.glob`,

Include/cpython/pystats.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,25 @@ typedef struct _optimization_stats {
122122
uint64_t optimized_trace_length_hist[_Py_UOP_HIST_SIZE];
123123
} OptimizationStats;
124124

125+
typedef struct _rare_event_stats {
126+
/* Setting an object's class, obj.__class__ = ... */
127+
uint64_t set_class;
128+
/* Setting the bases of a class, cls.__bases__ = ... */
129+
uint64_t set_bases;
130+
/* Setting the PEP 523 frame eval function, _PyInterpreterState_SetFrameEvalFunc() */
131+
uint64_t set_eval_frame_func;
132+
/* Modifying the builtins, __builtins__.__dict__[var] = ... */
133+
uint64_t builtin_dict;
134+
/* Modifying a function, e.g. func.__defaults__ = ..., etc. */
135+
uint64_t func_modification;
136+
} RareEventStats;
137+
125138
typedef struct _stats {
126139
OpcodeStats opcode_stats[256];
127140
CallStats call_stats;
128141
ObjectStats object_stats;
129142
OptimizationStats optimization_stats;
143+
RareEventStats rare_event_stats;
130144
GCStats *gc_stats;
131145
} PyStats;
132146

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ extern int _PyStaticCode_Init(PyCodeObject *co);
295295
_Py_stats->optimization_stats.name[bucket]++; \
296296
} \
297297
} while (0)
298+
#define RARE_EVENT_STAT_INC(name) do { if (_Py_stats) _Py_stats->rare_event_stats.name++; } while (0)
298299

299300
// Export for '_opcode' shared extension
300301
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
@@ -313,6 +314,7 @@ PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
313314
#define UOP_STAT_INC(opname, name) ((void)0)
314315
#define OPT_UNSUPPORTED_OPCODE(opname) ((void)0)
315316
#define OPT_HIST(length, name) ((void)0)
317+
#define RARE_EVENT_STAT_INC(name) ((void)0)
316318
#endif // !Py_STATS
317319

318320
// Utility functions for reading/writing 32/64-bit values in the inline caches.

0 commit comments

Comments
 (0)