Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3a9e37

Browse files
Merge branch 'main' into sqlite-autocommit
2 parents 4deed17 + 9762572 commit f3a9e37

File tree

64 files changed

+993
-654
lines changed

Some content is hidden

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

64 files changed

+993
-654
lines changed

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ labels: "type-bug"
1515
your problem has already been reported
1616
-->
1717

18-
**Bug report**
18+
# Bug report
1919

2020
A clear and concise description of what the bug is.
2121
Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.
2222

23-
**Your environment**
23+
# Your environment
2424

2525
<!-- Include as many relevant details as possible about the environment you experienced the bug in -->
2626

.github/ISSUE_TEMPLATE/crash.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ labels: "type-crash"
1313
For CPython, a "crash" is when Python itself fails, leading to a traceback in the C stack.
1414
-->
1515

16-
**Crash report**
16+
# Crash report
1717

1818
Tell us what happened, ideally including a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example).
1919

20-
**Error messages**
20+
# Error messages
2121

2222
Enter any relevant error message caused by the crash, including a core dump if there is one.
2323

24-
**Your environment**
24+
# Your environment
2525

2626
<!-- Include as many relevant details as possible about the environment you experienced the bug in -->
2727

.github/ISSUE_TEMPLATE/documentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ about: Report a problem with the documentation
44
labels: "docs"
55
---
66

7-
**Documentation**
7+
# Documentation
88

99
(A clear and concise description of the issue.)

.github/ISSUE_TEMPLATE/feature.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ about: Submit a proposal for a new CPython feature or enhancement
44
labels: "type-feature"
55
---
66

7-
**Feature or enhancement**
7+
# Feature or enhancement
88

99
(A clear and concise description of your proposal.)
1010

11-
**Pitch**
11+
# Pitch
1212

1313
(Explain why this feature or enhancement should be implemented and how it would be used.
1414
Add examples, if applicable.)
1515

16-
**Previous discussion**
16+
# Previous discussion
1717

1818
<!--
1919
New features to Python should first be discussed elsewhere before creating issues on GitHub,

Doc/includes/sqlite3/pysqlite_datetime.py

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

Doc/library/multiprocessing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ their parent process exits. The manager classes are defined in the
17061706
shutdown times out, the process is terminated. If terminating the process
17071707
also times out, the process is killed.
17081708

1709-
.. versionchanged: 3.11
1709+
.. versionchanged:: 3.11
17101710
Added the *shutdown_timeout* parameter.
17111711

17121712
.. method:: start([initializer[, initargs]])

Doc/library/pathlib.rst

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,101 @@ call fails (for example because the path doesn't exist).
946946
to the directory after creating the iterator, whether a path object for
947947
that file be included is unspecified.
948948

949+
.. method:: Path.walk(top_down=True, on_error=None, follow_symlinks=False)
950+
951+
Generate the file names in a directory tree by walking the tree
952+
either top-down or bottom-up.
953+
954+
For each directory in the directory tree rooted at *self* (including
955+
*self* but excluding '.' and '..'), the method yields a 3-tuple of
956+
``(dirpath, dirnames, filenames)``.
957+
958+
*dirpath* is a :class:`Path` to the directory currently being walked,
959+
*dirnames* is a list of strings for the names of subdirectories in *dirpath*
960+
(excluding ``'.'`` and ``'..'``), and *filenames* is a list of strings for
961+
the names of the non-directory files in *dirpath*. To get a full path
962+
(which begins with *self*) to a file or directory in *dirpath*, do
963+
``dirpath / name``. Whether or not the lists are sorted is file
964+
system-dependent.
965+
966+
If the optional argument *top_down* is true (which is the default), the triple for a
967+
directory is generated before the triples for any of its subdirectories
968+
(directories are walked top-down). If *top_down* is false, the triple
969+
for a directory is generated after the triples for all of its subdirectories
970+
(directories are walked bottom-up). No matter the value of *top_down*, the
971+
list of subdirectories is retrieved before the triples for the directory and
972+
its subdirectories are walked.
973+
974+
When *top_down* is true, the caller can modify the *dirnames* list in-place
975+
(for example, using :keyword:`del` or slice assignment), and :meth:`Path.walk`
976+
will only recurse into the subdirectories whose names remain in *dirnames*.
977+
This can be used to prune the search, or to impose a specific order of visiting,
978+
or even to inform :meth:`Path.walk` about directories the caller creates or
979+
renames before it resumes :meth:`Path.walk` again. Modifying *dirnames* when
980+
*top_down* is false has no effect on the behavior of :meth:`Path.walk()` since the
981+
directories in *dirnames* have already been generated by the time *dirnames*
982+
is yielded to the caller.
983+
984+
By default, errors from :func:`os.scandir` are ignored. If the optional
985+
argument *on_error* is specified, it should be a callable; it will be
986+
called with one argument, an :exc:`OSError` instance. The callable can handle the
987+
error to continue the walk or re-raise it to stop the walk. Note that the
988+
filename is available as the ``filename`` attribute of the exception object.
989+
990+
By default, :meth:`Path.walk` does not follow symbolic links, and instead adds them
991+
to the *filenames* list. Set *follow_symlinks* to true to resolve symlinks
992+
and place them in *dirnames* and *filenames* as appropriate for their targets, and
993+
consequently visit directories pointed to by symlinks (where supported).
994+
995+
.. note::
996+
997+
Be aware that setting *follow_symlinks* to true can lead to infinite
998+
recursion if a link points to a parent directory of itself. :meth:`Path.walk`
999+
does not keep track of the directories it has already visited.
1000+
1001+
.. note::
1002+
:meth:`Path.walk` assumes the directories it walks are not modified during
1003+
execution. For example, if a directory from *dirnames* has been replaced
1004+
with a symlink and *follow_symlinks* is false, :meth:`Path.walk` will
1005+
still try to descend into it. To prevent such behavior, remove directories
1006+
from *dirnames* as appropriate.
1007+
1008+
.. note::
1009+
1010+
Unlike :func:`os.walk`, :meth:`Path.walk` lists symlinks to directories in
1011+
*filenames* if *follow_symlinks* is false.
1012+
1013+
This example displays the number of bytes used by all files in each directory,
1014+
while ignoring ``__pycache__`` directories::
1015+
1016+
from pathlib import Path
1017+
for root, dirs, files in Path("cpython/Lib/concurrent").walk(on_error=print):
1018+
print(
1019+
root,
1020+
"consumes",
1021+
sum((root / file).stat().st_size for file in files),
1022+
"bytes in",
1023+
len(files),
1024+
"non-directory files"
1025+
)
1026+
if '__pycache__' in dirs:
1027+
dirs.remove('__pycache__')
1028+
1029+
This next example is a simple implementation of :func:`shutil.rmtree`.
1030+
Walking the tree bottom-up is essential as :func:`rmdir` doesn't allow
1031+
deleting a directory before it is empty::
1032+
1033+
# Delete everything reachable from the directory "top".
1034+
# CAUTION: This is dangerous! For example, if top == Path('/'),
1035+
# it could delete all of your files.
1036+
for root, dirs, files in top.walk(topdown=False):
1037+
for name in files:
1038+
(root / name).unlink()
1039+
for name in dirs:
1040+
(root / name).rmdir()
1041+
1042+
.. versionadded:: 3.12
1043+
9491044
.. method:: Path.lchmod(mode)
9501045

9511046
Like :meth:`Path.chmod` but, if the path points to a symbolic link, the
@@ -1122,8 +1217,8 @@ call fails (for example because the path doesn't exist).
11221217

11231218
.. method:: Path.rglob(pattern)
11241219

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

11281223
>>> sorted(Path().rglob("*.py"))
11291224
[PosixPath('build/lib/pathlib.py'),
@@ -1285,6 +1380,7 @@ Below is a table mapping various :mod:`os` functions to their corresponding
12851380
:func:`os.path.expanduser` :meth:`Path.expanduser` and
12861381
:meth:`Path.home`
12871382
:func:`os.listdir` :meth:`Path.iterdir`
1383+
:func:`os.walk` :meth:`Path.walk`
12881384
:func:`os.path.isdir` :meth:`Path.is_dir`
12891385
:func:`os.path.isfile` :meth:`Path.is_file`
12901386
:func:`os.path.islink` :meth:`Path.is_symlink`

Doc/library/sqlite3.rst

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,18 +1035,11 @@ Cursor Objects
10351035

10361036
.. attribute:: rowcount
10371037

1038-
Although the :class:`Cursor` class of the :mod:`sqlite3` module implements this
1039-
attribute, the database engine's own support for the determination of "rows
1040-
affected"/"rows selected" is quirky.
1041-
1042-
For :meth:`executemany` statements, the number of modifications are summed up
1043-
into :attr:`rowcount`.
1044-
1045-
As required by the Python DB API Spec, the :attr:`rowcount` attribute "is -1 in
1046-
case no ``executeXX()`` has been performed on the cursor or the rowcount of the
1047-
last operation is not determinable by the interface". This includes ``SELECT``
1048-
statements because we cannot determine the number of rows a query produced
1049-
until all rows were fetched.
1038+
Read-only attribute that provides the number of modified rows for
1039+
``INSERT``, ``UPDATE``, ``DELETE``, and ``REPLACE`` statements;
1040+
is ``-1`` for other statements,
1041+
including :abbr:`CTE (Common Table Expression)` queries.
1042+
It is only updated by the :meth:`execute` and :meth:`executemany` methods.
10501043

10511044
.. attribute:: lastrowid
10521045

@@ -1402,6 +1395,8 @@ This function can then be registered using :func:`register_adapter`.
14021395
.. literalinclude:: ../includes/sqlite3/adapter_point_2.py
14031396

14041397

1398+
.. _sqlite3-converters:
1399+
14051400
Converting SQLite values to custom Python types
14061401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14071402

@@ -1442,27 +1437,28 @@ The following example illustrates the implicit and explicit approaches:
14421437
.. literalinclude:: ../includes/sqlite3/converter_point.py
14431438

14441439

1445-
Default adapters and converters
1446-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1447-
1448-
There are default adapters for the date and datetime types in the datetime
1449-
module. They will be sent as ISO dates/ISO timestamps to SQLite.
1440+
.. _sqlite3-default-converters:
14501441

1451-
The default converters are registered under the name "date" for
1452-
:class:`datetime.date` and under the name "timestamp" for
1453-
:class:`datetime.datetime`.
1442+
Default adapters and converters (deprecated)
1443+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14541444

1455-
This way, you can use date/timestamps from Python without any additional
1456-
fiddling in most cases. The format of the adapters is also compatible with the
1457-
experimental SQLite date/time functions.
1445+
.. note::
14581446

1459-
The following example demonstrates this.
1447+
The default adapters and converters are deprecated as of Python 3.12.
1448+
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
1449+
and tailor them to your needs.
14601450

1461-
.. literalinclude:: ../includes/sqlite3/pysqlite_datetime.py
1451+
The deprecated default adapters and converters consist of:
14621452

1463-
If a timestamp stored in SQLite has a fractional part longer than 6
1464-
numbers, its value will be truncated to microsecond precision by the
1465-
timestamp converter.
1453+
* An adapter for :class:`datetime.date` objects to :class:`strings <str>` in
1454+
`ISO 8601`_ format.
1455+
* An adapter for :class:`datetime.datetime` objects to strings in
1456+
ISO 8601 format.
1457+
* A converter for :ref:`declared <sqlite3-converters>` "date" types to
1458+
:class:`datetime.date` objects.
1459+
* A converter for declared "timestamp" types to
1460+
:class:`datetime.datetime` objects.
1461+
Fractional parts will be truncated to 6 digits (microsecond precision).
14661462

14671463
.. note::
14681464

@@ -1471,6 +1467,10 @@ timestamp converter.
14711467
offsets in timestamps, either leave converters disabled, or register an
14721468
offset-aware converter with :func:`register_converter`.
14731469

1470+
.. deprecated:: 3.12
1471+
1472+
.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601
1473+
14741474

14751475
.. _sqlite3-adapter-converter-recipes:
14761476

Doc/library/unittest.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,8 +1150,8 @@ Test cases
11501150
Example::
11511151

11521152
with self.assertLogs('foo', level='INFO') as cm:
1153-
logging.getLogger('foo').info('first message')
1154-
logging.getLogger('foo.bar').error('second message')
1153+
logging.getLogger('foo').info('first message')
1154+
logging.getLogger('foo.bar').error('second message')
11551155
self.assertEqual(cm.output, ['INFO:foo:first message',
11561156
'ERROR:foo.bar:second message'])
11571157

Doc/reference/compound_stmts.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ Is semantically equivalent to::
14951495
else:
14961496
SUITE2
14971497

1498-
See also :meth:`__aiter__` and :meth:`__anext__` for details.
1498+
See also :meth:`~object.__aiter__` and :meth:`~object.__anext__` for details.
14991499

15001500
It is a :exc:`SyntaxError` to use an ``async for`` statement outside the
15011501
body of a coroutine function.
@@ -1537,7 +1537,7 @@ is semantically equivalent to::
15371537
if not hit_except:
15381538
await aexit(manager, None, None, None)
15391539

1540-
See also :meth:`__aenter__` and :meth:`__aexit__` for details.
1540+
See also :meth:`~object.__aenter__` and :meth:`~object.__aexit__` for details.
15411541

15421542
It is a :exc:`SyntaxError` to use an ``async with`` statement outside the
15431543
body of a coroutine function.

0 commit comments

Comments
 (0)