Skip to content

Commit fbeb1a7

Browse files
authored
Merge branch 'main' into run-pidfdchildwatcher-on-the-running-loop
2 parents 978c822 + 834bd5d commit fbeb1a7

38 files changed

+483
-235
lines changed

Doc/includes/sqlite3/pysqlite_datetime.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

Doc/library/pathlib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,8 @@ call fails (for example because the path doesn't exist).
11221122

11231123
.. method:: Path.rglob(pattern)
11241124

1125-
This is like calling :func:`Path.glob` with "``**/``" added in front of the
1126-
given relative *pattern*::
1125+
Glob the given relative *pattern* recursively. This is like calling
1126+
:func:`Path.glob` with "``**/``" added in front of the *pattern*::
11271127

11281128
>>> sorted(Path().rglob("*.py"))
11291129
[PosixPath('build/lib/pathlib.py'),

Doc/library/sqlite3.rst

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,8 @@ This function can then be registered using :func:`register_adapter`.
13331333
.. literalinclude:: ../includes/sqlite3/adapter_point_2.py
13341334

13351335

1336+
.. _sqlite3-converters:
1337+
13361338
Converting SQLite values to custom Python types
13371339
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13381340

@@ -1373,27 +1375,28 @@ The following example illustrates the implicit and explicit approaches:
13731375
.. literalinclude:: ../includes/sqlite3/converter_point.py
13741376

13751377

1376-
Default adapters and converters
1377-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1378-
1379-
There are default adapters for the date and datetime types in the datetime
1380-
module. They will be sent as ISO dates/ISO timestamps to SQLite.
1378+
.. _sqlite3-default-converters:
13811379

1382-
The default converters are registered under the name "date" for
1383-
:class:`datetime.date` and under the name "timestamp" for
1384-
:class:`datetime.datetime`.
1380+
Default adapters and converters (deprecated)
1381+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13851382

1386-
This way, you can use date/timestamps from Python without any additional
1387-
fiddling in most cases. The format of the adapters is also compatible with the
1388-
experimental SQLite date/time functions.
1383+
.. note::
13891384

1390-
The following example demonstrates this.
1385+
The default adapters and converters are deprecated as of Python 3.12.
1386+
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
1387+
and tailor them to your needs.
13911388

1392-
.. literalinclude:: ../includes/sqlite3/pysqlite_datetime.py
1389+
The deprecated default adapters and converters consist of:
13931390

1394-
If a timestamp stored in SQLite has a fractional part longer than 6
1395-
numbers, its value will be truncated to microsecond precision by the
1396-
timestamp converter.
1391+
* An adapter for :class:`datetime.date` objects to :class:`strings <str>` in
1392+
`ISO 8601`_ format.
1393+
* An adapter for :class:`datetime.datetime` objects to strings in
1394+
ISO 8601 format.
1395+
* A converter for :ref:`declared <sqlite3-converters>` "date" types to
1396+
:class:`datetime.date` objects.
1397+
* A converter for declared "timestamp" types to
1398+
:class:`datetime.datetime` objects.
1399+
Fractional parts will be truncated to 6 digits (microsecond precision).
13971400

13981401
.. note::
13991402

@@ -1402,6 +1405,10 @@ timestamp converter.
14021405
offsets in timestamps, either leave converters disabled, or register an
14031406
offset-aware converter with :func:`register_converter`.
14041407

1408+
.. deprecated:: 3.12
1409+
1410+
.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601
1411+
14051412

14061413
.. _sqlite3-adapter-converter-recipes:
14071414

Doc/using/windows.rst

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ developers using Python for any kind of project.
3434

3535
:ref:`windows-store` is a simple installation of Python that is suitable for
3636
running scripts and packages, and using IDLE or other development environments.
37-
It requires Windows 10, but can be safely installed without corrupting other
37+
It requires Windows 10 and above, but can be safely installed without corrupting other
3838
programs. It also provides many convenient commands for launching Python and
3939
its tools.
4040

@@ -348,14 +348,42 @@ Python in Start and right-click to select Uninstall. Uninstalling will
348348
remove all packages you installed directly into this Python installation, but
349349
will not remove any virtual environments
350350

351-
Known Issues
351+
Known issues
352352
------------
353353

354+
Redirection of local data, registry, and temporary paths
355+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
356+
354357
Because of restrictions on Microsoft Store apps, Python scripts may not have
355-
full write access to shared locations such as ``TEMP`` and the registry.
358+
full write access to shared locations such as :envvar:`TEMP` and the registry.
356359
Instead, it will write to a private copy. If your scripts must modify the
357360
shared locations, you will need to install the full installer.
358361

362+
At runtime, Python will use a private copy of well-known Windows folders and the registry.
363+
For example, if the environment variable :envvar:`%APPDATA%` is :file:`c:\\Users\\<user>\\AppData\\`,
364+
then when writing to :file:`C:\\Users\\<user>\\AppData\\Local` will write to
365+
:file:`C:\\Users\\<user>\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\Local\\`.
366+
367+
When reading files, Windows will return the file from the private folder, or if that does not exist, the
368+
real Windows directory. For example reading :file:`C:\\Windows\\System32` returns the contents of :file:`C:\\Windows\\System32`
369+
plus the contents of :file:`C:\\Program Files\\WindowsApps\\package_name\\VFS\\SystemX86`.
370+
371+
You can find the real path of any existing file using :func:`os.path.realpath`:
372+
373+
.. code-block:: python
374+
375+
>>> import os
376+
>>> test_file = 'C:\\Users\\example\\AppData\\Local\\test.txt'
377+
>>> os.path.realpath(test_file)
378+
'C:\\Users\\example\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\Local\\test.txt'
379+
380+
When writing to the Windows Registry, the following behaviors exist:
381+
382+
* Reading from ``HKLM\\Software`` is allowed and results are merged with the :file:`registry.dat` file in the package.
383+
* Writing to ``HKLM\\Software`` is not allowed if the corresponding key/value exists, i.e. modifying existing keys.
384+
* Writing to ``HKLM\\Software`` is allowed as long as a corresponding key/value does not exist in the package
385+
and the user has the correct access permissions.
386+
359387
For more detail on the technical basis for these limitations, please consult
360388
Microsoft's documentation on packaged full-trust apps, currently available at
361389
`docs.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-behind-the-scenes

Doc/whatsnew/3.12.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ Deprecated
135135
* :class:`typing.Hashable` and :class:`typing.Sized` aliases for :class:`collections.abc.Hashable`
136136
and :class:`collections.abc.Sized`. (:gh:`94309`)
137137

138+
* The :mod:`sqlite3` :ref:`default adapters and converters
139+
<sqlite3-default-converters>` are now deprecated.
140+
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
141+
and tailor them to your needs.
142+
(Contributed by Erlend E. Aasland in :gh:`90016`.)
143+
138144

139145
Pending Removal in Python 3.13
140146
------------------------------

Lib/idlelib/NEWS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ What's New in IDLE 3.10.0
2929
Released on 2021-10-04
3030
=========================
3131

32+
bpo-45193: Make completion boxes appear on Ubuntu again.
3233

3334
bpo-40128: Mostly fix completions on macOS when not using tcl/tk 8.6.11
3435
(as with 3.9).

Lib/pathlib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ def __init__(self, pat, child_parts, flavour):
299299

300300
def _select_from(self, parent_path, is_dir, exists, scandir):
301301
try:
302+
# We must close the scandir() object before proceeding to
303+
# avoid exhausting file descriptors when globbing deep trees.
302304
with scandir(parent_path) as scandir_it:
303305
entries = list(scandir_it)
304306
for entry in entries:
@@ -330,6 +332,8 @@ def __init__(self, pat, child_parts, flavour):
330332
def _iterate_directories(self, parent_path, is_dir, scandir):
331333
yield parent_path
332334
try:
335+
# We must close the scandir() object before proceeding to
336+
# avoid exhausting file descriptors when globbing deep trees.
333337
with scandir(parent_path) as scandir_it:
334338
entries = list(scandir_it)
335339
for entry in entries:

Lib/shutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,8 @@ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
11181118
save_cwd = None
11191119
if root_dir is not None:
11201120
if support_root_dir:
1121+
# Support path-like base_name here for backwards-compatibility.
1122+
base_name = os.fspath(base_name)
11211123
kwargs['root_dir'] = root_dir
11221124
else:
11231125
save_cwd = os.getcwd()

Lib/sqlite3/dbapi2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,25 @@ def TimestampFromTicks(ticks):
5555
collections.abc.Sequence.register(Row)
5656

5757
def register_adapters_and_converters():
58+
from warnings import warn
59+
60+
msg = ("The default {what} is deprecated as of Python 3.12; "
61+
"see the sqlite3 documentation for suggested replacement recipes")
62+
5863
def adapt_date(val):
64+
warn(msg.format(what="date adapter"), DeprecationWarning, stacklevel=2)
5965
return val.isoformat()
6066

6167
def adapt_datetime(val):
68+
warn(msg.format(what="datetime adapter"), DeprecationWarning, stacklevel=2)
6269
return val.isoformat(" ")
6370

6471
def convert_date(val):
72+
warn(msg.format(what="date converter"), DeprecationWarning, stacklevel=2)
6573
return datetime.date(*map(int, val.split(b"-")))
6674

6775
def convert_timestamp(val):
76+
warn(msg.format(what="timestamp converter"), DeprecationWarning, stacklevel=2)
6877
datepart, timepart = val.split(b" ")
6978
year, month, day = map(int, datepart.split(b"-"))
7079
timepart_full = timepart.split(b".")

Lib/test/test_bytes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,23 @@ def test_repeat_after_setslice(self):
17101710
self.assertEqual(b1, b)
17111711
self.assertEqual(b3, b'xcxcxc')
17121712

1713+
def test_mutating_index(self):
1714+
class Boom:
1715+
def __index__(self):
1716+
b.clear()
1717+
return 0
1718+
1719+
with self.subTest("tp_as_mapping"):
1720+
b = bytearray(b'Now you see me...')
1721+
with self.assertRaises(IndexError):
1722+
b[0] = Boom()
1723+
1724+
with self.subTest("tp_as_sequence"):
1725+
_testcapi = import_helper.import_module('_testcapi')
1726+
b = bytearray(b'Now you see me...')
1727+
with self.assertRaises(IndexError):
1728+
_testcapi.sequence_setitem(b, 0, Boom())
1729+
17131730

17141731
class AssortedBytesTest(unittest.TestCase):
17151732
#

0 commit comments

Comments
 (0)