Skip to content

Commit d944c4d

Browse files
committed
Merge branch 'master' into ac-decimal/73487-pt4
2 parents b778703 + d22a745 commit d944c4d

26 files changed

+296
-294
lines changed

Doc/c-api/init_config.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,7 @@ If a ``._pth`` file is present:
22582258
* Set :c:member:`~PyConfig.isolated` to ``1``.
22592259
* Set :c:member:`~PyConfig.use_environment` to ``0``.
22602260
* Set :c:member:`~PyConfig.site_import` to ``0``.
2261+
* Set :c:member:`~PyConfig.user_site_directory` to ``0`` (since 3.15).
22612262
* Set :c:member:`~PyConfig.safe_path` to ``1``.
22622263
22632264
If :c:member:`~PyConfig.home` is not set and a ``pyvenv.cfg`` file is present in
@@ -2278,6 +2279,12 @@ The ``__PYVENV_LAUNCHER__`` environment variable is used to set
22782279
therefore affected by :option:`-S`.
22792280
22802281
2282+
.. versionchanged:: 3.15
2283+
2284+
:c:member:`~PyConfig.user_site_directory` is now set to ``0`` when a
2285+
``._pth`` file is present.
2286+
2287+
22812288
Py_GetArgcArgv()
22822289
================
22832290

Doc/library/dbm.rst

Lines changed: 67 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ the Oracle Berkeley DB.
9090
.. versionchanged:: 3.11
9191
*file* accepts a :term:`path-like object`.
9292

93-
The object returned by :func:`~dbm.open` supports the same basic functionality as a
94-
:class:`dict`; keys and their corresponding values can be stored, retrieved, and
95-
deleted, and the :keyword:`in` operator and the :meth:`!keys` method are
96-
available, as well as :meth:`!get` and :meth:`!setdefault` methods.
93+
The object returned by :func:`~dbm.open` supports the basic
94+
functionality of mutable :term:`mappings <mapping>`;
95+
keys and their corresponding values can be stored, retrieved, and
96+
deleted, and iteration, the :keyword:`in` operator and methods :meth:`!keys`,
97+
:meth:`!get`, :meth:`!setdefault` and :meth:`!clear` are available.
98+
The :meth:`!keys` method returns a list instead of a view object.
99+
The :meth:`!setdefault` method requires two arguments.
97100

98101
Key and values are always stored as :class:`bytes`. This means that when
99102
strings are used they are implicitly converted to the default encoding before
@@ -114,6 +117,10 @@ will automatically close them when done.
114117
Deleting a key from a read-only database raises a database module specific exception
115118
instead of :exc:`KeyError`.
116119

120+
.. versionchanged:: 3.13
121+
:meth:`!clear` methods are now available for all :mod:`dbm` backends.
122+
123+
117124
The following example records some hostnames and a corresponding title, and
118125
then prints out the contents of the database::
119126

@@ -173,9 +180,6 @@ or any other SQLite browser, including the SQLite CLI.
173180
.. function:: open(filename, /, flag="r", mode=0o666)
174181

175182
Open an SQLite database.
176-
The returned object behaves like a :term:`mapping`,
177-
implements a :meth:`!close` method,
178-
and supports a "closing" context manager via the :keyword:`with` keyword.
179183

180184
:param filename:
181185
The path to the database to be opened.
@@ -192,6 +196,17 @@ or any other SQLite browser, including the SQLite CLI.
192196
The Unix file access mode of the file (default: octal ``0o666``),
193197
used only when the database has to be created.
194198

199+
The returned database object behaves similar to a mutable :term:`mapping`,
200+
but the :meth:`!keys` method returns a list, and
201+
the :meth:`!setdefault` method requires two arguments.
202+
It also supports a "closing" context manager via the :keyword:`with` keyword.
203+
204+
The following methods are also provided:
205+
206+
.. method:: sqlite3.close()
207+
208+
Close the SQLite database.
209+
195210
.. method:: sqlite3.reorganize()
196211

197212
If you have carried out a lot of deletions and would like to shrink the space
@@ -204,6 +219,7 @@ or any other SQLite browser, including the SQLite CLI.
204219

205220
.. versionadded:: next
206221

222+
207223
:mod:`dbm.gnu` --- GNU database manager
208224
---------------------------------------
209225

@@ -232,6 +248,11 @@ functionality like crash tolerance.
232248
raised for general mapping errors like specifying an incorrect key.
233249

234250

251+
.. data:: open_flags
252+
253+
A string of characters the *flag* parameter of :meth:`~dbm.gnu.open` supports.
254+
255+
235256
.. function:: open(filename, flag="r", mode=0o666, /)
236257

237258
Open a GDBM database and return a :class:`!gdbm` object.
@@ -270,14 +291,25 @@ functionality like crash tolerance.
270291
.. versionchanged:: 3.11
271292
*filename* accepts a :term:`path-like object`.
272293

273-
.. data:: open_flags
294+
:class:`!gdbm` objects behave similar to mutable :term:`mappings <mapping>`,
295+
but methods :meth:`!items`, :meth:`!values`, :meth:`!pop`, :meth:`!popitem`,
296+
and :meth:`!update` are not supported,
297+
the :meth:`!keys` method returns a list, and
298+
the :meth:`!setdefault` method requires two arguments.
299+
It also supports a "closing" context manager via the :keyword:`with` keyword.
300+
301+
.. versionchanged:: 3.2
302+
Added the :meth:`!get` and :meth:`!setdefault` methods.
274303

275-
A string of characters the *flag* parameter of :meth:`~dbm.gnu.open` supports.
304+
.. versionchanged:: 3.13
305+
Added the :meth:`!clear` method.
276306

277-
:class:`!gdbm` objects behave similar to :term:`mappings <mapping>`,
278-
but :meth:`!items` and :meth:`!values` methods are not supported.
279307
The following methods are also provided:
280308

309+
.. method:: gdbm.close()
310+
311+
Close the GDBM database.
312+
281313
.. method:: gdbm.firstkey()
282314

283315
It's possible to loop over every key in the database using this method and the
@@ -313,16 +345,6 @@ functionality like crash tolerance.
313345
When the database has been opened in fast mode, this method forces any
314346
unwritten data to be written to the disk.
315347

316-
.. method:: gdbm.close()
317-
318-
Close the GDBM database.
319-
320-
.. method:: gdbm.clear()
321-
322-
Remove all items from the GDBM database.
323-
324-
.. versionadded:: 3.13
325-
326348

327349
:mod:`dbm.ndbm` --- New Database Manager
328350
----------------------------------------
@@ -383,22 +405,27 @@ This module can be used with the "classic" NDBM interface or the
383405
:param int mode:
384406
|mode_param_doc|
385407

386-
:class:`!ndbm` objects behave similar to :term:`mappings <mapping>`,
387-
but :meth:`!items` and :meth:`!values` methods are not supported.
388-
The following methods are also provided:
389-
390408
.. versionchanged:: 3.11
391409
Accepts :term:`path-like object` for filename.
392410

393-
.. method:: ndbm.close()
411+
:class:`!ndbm` objects behave similar to mutable :term:`mappings <mapping>`,
412+
but methods :meth:`!items`, :meth:`!values`, :meth:`!pop`, :meth:`!popitem`,
413+
and :meth:`!update` are not supported,
414+
the :meth:`!keys` method returns a list, and
415+
the :meth:`!setdefault` method requires two arguments.
416+
It also supports a "closing" context manager via the :keyword:`with` keyword.
394417

395-
Close the NDBM database.
418+
.. versionchanged:: 3.2
419+
Added the :meth:`!get` and :meth:`!setdefault` methods.
396420

397-
.. method:: ndbm.clear()
421+
.. versionchanged:: 3.13
422+
Added the :meth:`!clear` method.
398423

399-
Remove all items from the NDBM database.
424+
The following method is also provided:
400425

401-
.. versionadded:: 3.13
426+
.. method:: ndbm.close()
427+
428+
Close the NDBM database.
402429

403430

404431
:mod:`dbm.dumb` --- Portable DBM implementation
@@ -436,9 +463,6 @@ The :mod:`!dbm.dumb` module defines the following:
436463
.. function:: open(filename, flag="c", mode=0o666)
437464

438465
Open a :mod:`!dbm.dumb` database.
439-
The returned database object behaves similar to a :term:`mapping`,
440-
in addition to providing :meth:`~dumbdbm.sync` and :meth:`~dumbdbm.close`
441-
methods.
442466

443467
:param filename:
444468
The basename of the database file (without extensions).
@@ -477,14 +501,12 @@ The :mod:`!dbm.dumb` module defines the following:
477501
.. versionchanged:: 3.11
478502
*filename* accepts a :term:`path-like object`.
479503

480-
In addition to the methods provided by the
481-
:class:`collections.abc.MutableMapping` class,
482-
the following methods are provided:
504+
The returned database object behaves similar to a mutable :term:`mapping`,
505+
but the :meth:`!keys` and :meth:`!items` methods return lists, and
506+
the :meth:`!setdefault` method requires two arguments.
507+
It also supports a "closing" context manager via the :keyword:`with` keyword.
483508

484-
.. method:: dumbdbm.sync()
485-
486-
Synchronize the on-disk directory and data files. This method is called
487-
by the :meth:`shelve.Shelf.sync` method.
509+
The following methods are also provided:
488510

489511
.. method:: dumbdbm.close()
490512

@@ -501,3 +523,8 @@ The :mod:`!dbm.dumb` module defines the following:
501523
that this factor changes for each :mod:`dbm` submodule.
502524

503525
.. versionadded:: next
526+
527+
.. method:: dumbdbm.sync()
528+
529+
Synchronize the on-disk directory and data files. This method is called
530+
by the :meth:`shelve.Shelf.sync` method.

Doc/library/resource.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ this module for those platforms.
7878

7979
Sets new limits of consumption of *resource*. The *limits* argument must be a
8080
tuple ``(soft, hard)`` of two integers describing the new limits. A value of
81-
:data:`~resource.RLIM_INFINITY` can be used to request a limit that is
81+
:const:`~resource.RLIM_INFINITY` can be used to request a limit that is
8282
unlimited.
8383

8484
Raises :exc:`ValueError` if an invalid resource is specified, if the new soft
8585
limit exceeds the hard limit, or if a process tries to raise its hard limit.
86-
Specifying a limit of :data:`~resource.RLIM_INFINITY` when the hard or
86+
Specifying a limit of :const:`~resource.RLIM_INFINITY` when the hard or
8787
system limit for that resource is not unlimited will result in a
8888
:exc:`ValueError`. A process with the effective UID of super-user can
8989
request any valid limit value, including unlimited, but :exc:`ValueError`
@@ -93,7 +93,7 @@ this module for those platforms.
9393
``setrlimit`` may also raise :exc:`error` if the underlying system call
9494
fails.
9595

96-
VxWorks only supports setting :data:`RLIMIT_NOFILE`.
96+
VxWorks only supports setting :const:`RLIMIT_NOFILE`.
9797

9898
.. audit-event:: resource.setrlimit resource,limits resource.setrlimit
9999

Doc/library/ssl.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,8 +1898,9 @@ to speed up repeated connections from the same clients.
18981898
.. attribute:: SSLContext.sslsocket_class
18991899

19001900
The return type of :meth:`SSLContext.wrap_socket`, defaults to
1901-
:class:`SSLSocket`. The attribute can be overridden on instance of class
1902-
in order to return a custom subclass of :class:`SSLSocket`.
1901+
:class:`SSLSocket`. The attribute can be assigned to on instances of
1902+
:class:`SSLContext` in order to return a custom subclass of
1903+
:class:`SSLSocket`.
19031904

19041905
.. versionadded:: 3.7
19051906

Doc/whatsnew/3.13.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ dbm
834834
(Contributed by Raymond Hettinger and Erlend E. Aasland in :gh:`100414`.)
835835

836836
* Allow removing all items from the database through
837-
the new :meth:`.gdbm.clear` and :meth:`.ndbm.clear` methods.
837+
the new :meth:`!clear` methods of the GDBM and NDBM database objects.
838838
(Contributed by Donghee Na in :gh:`107122`.)
839839

840840

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/_pydatetime.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,6 @@ def _need_normalize_century():
213213
_normalize_century = True
214214
return _normalize_century
215215

216-
_supports_c99 = None
217-
def _can_support_c99():
218-
global _supports_c99
219-
if _supports_c99 is None:
220-
try:
221-
_supports_c99 = (
222-
_time.strftime("%F", (1900, 1, 1, 0, 0, 0, 0, 1, 0)) == "1900-01-01")
223-
except ValueError:
224-
_supports_c99 = False
225-
return _supports_c99
226-
227216
# Correctly substitute for %z and %Z escapes in strftime formats.
228217
def _wrap_strftime(object, format, timetuple):
229218
# Don't call utcoffset() or tzname() unless actually needed.
@@ -283,7 +272,7 @@ def _wrap_strftime(object, format, timetuple):
283272
newformat.append(Zreplace)
284273
# Note that datetime(1000, 1, 1).strftime('%G') == '1000' so
285274
# year 1000 for %G can go on the fast path.
286-
elif ((ch in 'YG' or ch in 'FC' and _can_support_c99()) and
275+
elif ((ch in 'YG' or ch in 'FC') and
287276
object.year < 1000 and _need_normalize_century()):
288277
if ch == 'G':
289278
year = int(_time.strftime("%G", timetuple))

Lib/test/datetimetester.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ def test_bool(self):
18071807
self.assertTrue(self.theclass.min)
18081808
self.assertTrue(self.theclass.max)
18091809

1810-
def test_strftime_y2k(self):
1810+
def check_strftime_y2k(self, specifier):
18111811
# Test that years less than 1000 are 0-padded; note that the beginning
18121812
# of an ISO 8601 year may fall in an ISO week of the year before, and
18131813
# therefore needs an offset of -1 when formatting with '%G'.
@@ -1821,22 +1821,28 @@ def test_strftime_y2k(self):
18211821
(1000, 0),
18221822
(1970, 0),
18231823
)
1824-
specifiers = 'YG'
1825-
if _time.strftime('%F', (1900, 1, 1, 0, 0, 0, 0, 1, 0)) == '1900-01-01':
1826-
specifiers += 'FC'
18271824
for year, g_offset in dataset:
1828-
for specifier in specifiers:
1829-
with self.subTest(year=year, specifier=specifier):
1830-
d = self.theclass(year, 1, 1)
1831-
if specifier == 'G':
1832-
year += g_offset
1833-
if specifier == 'C':
1834-
expected = f"{year // 100:02d}"
1835-
else:
1836-
expected = f"{year:04d}"
1837-
if specifier == 'F':
1838-
expected += f"-01-01"
1839-
self.assertEqual(d.strftime(f"%{specifier}"), expected)
1825+
with self.subTest(year=year, specifier=specifier):
1826+
d = self.theclass(year, 1, 1)
1827+
if specifier == 'G':
1828+
year += g_offset
1829+
if specifier == 'C':
1830+
expected = f"{year // 100:02d}"
1831+
else:
1832+
expected = f"{year:04d}"
1833+
if specifier == 'F':
1834+
expected += f"-01-01"
1835+
self.assertEqual(d.strftime(f"%{specifier}"), expected)
1836+
1837+
def test_strftime_y2k(self):
1838+
self.check_strftime_y2k('Y')
1839+
self.check_strftime_y2k('G')
1840+
1841+
def test_strftime_y2k_c99(self):
1842+
# CPython requires C11; specifiers new in C99 must work.
1843+
# (Other implementations may want to disable this test.)
1844+
self.check_strftime_y2k('F')
1845+
self.check_strftime_y2k('C')
18401846

18411847
def test_replace(self):
18421848
cls = self.theclass

Lib/test/test_call.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,14 @@ def c_py_recurse(m):
10741074
with self.assertRaises(RecursionError):
10751075
c_py_recurse(100_000)
10761076

1077+
def test_recursion_with_kwargs(self):
1078+
# GH-137883: The interpreter forgot to check the recursion limit when
1079+
# calling with keywords.
1080+
def recurse_kw(a=0):
1081+
recurse_kw(a=0)
1082+
with self.assertRaises(RecursionError):
1083+
recurse_kw()
1084+
10771085

10781086
class TestFunctionWithManyArgs(unittest.TestCase):
10791087
def test_function_with_many_args(self):

Lib/test/test_dis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ def foo(x):
830830
%4d LOAD_GLOBAL 1 (list + NULL)
831831
LOAD_FAST_BORROW 0 (x)
832832
BUILD_TUPLE 1
833-
LOAD_CONST 1 (<code object <genexpr> at 0x..., file "%s", line %d>)
833+
LOAD_CONST %d (<code object <genexpr> at 0x..., file "%s", line %d>)
834834
MAKE_FUNCTION
835835
SET_FUNCTION_ATTRIBUTE 8 (closure)
836836
LOAD_DEREF 1 (y)
@@ -842,6 +842,7 @@ def foo(x):
842842
_h.__code__.co_firstlineno + 1,
843843
_h.__code__.co_firstlineno + 1,
844844
_h.__code__.co_firstlineno + 3,
845+
1 if __debug__ else 0,
845846
__file__,
846847
_h.__code__.co_firstlineno + 3,
847848
)
@@ -1468,7 +1469,7 @@ def get_disassembly(self, func, lasti=-1, wrapper=True, **kwargs):
14681469
Kw-only arguments: 0
14691470
Number of locals: 1
14701471
Stack size: \\d+
1471-
Flags: OPTIMIZED, NEWLOCALS, HAS_DOCSTRING
1472+
Flags: OPTIMIZED, NEWLOCALS(, HAS_DOCSTRING)?
14721473
Constants:
14731474
{code_info_consts}
14741475
Names:

0 commit comments

Comments
 (0)