Skip to content

Commit d4b8204

Browse files
authored
Merge branch 'main' into tarfile-stream-xz-preset-133005
2 parents 406dc4c + 20be6ba commit d4b8204

Some content is hidden

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

51 files changed

+460
-231
lines changed

Doc/c-api/arg.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,19 @@ small to receive the value.
274274
Convert a Python integer to a C :c:expr:`unsigned long` without
275275
overflow checking.
276276

277+
.. versionchanged:: next
278+
Use :meth:`~object.__index__` if available.
279+
277280
``L`` (:class:`int`) [long long]
278281
Convert a Python integer to a C :c:expr:`long long`.
279282

280283
``K`` (:class:`int`) [unsigned long long]
281284
Convert a Python integer to a C :c:expr:`unsigned long long`
282285
without overflow checking.
283286

287+
.. versionchanged:: next
288+
Use :meth:`~object.__index__` if available.
289+
284290
``n`` (:class:`int`) [:c:type:`Py_ssize_t`]
285291
Convert a Python integer to a C :c:type:`Py_ssize_t`.
286292

Doc/library/socket.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ Constants
476476
network interface instead of its name.
477477

478478
.. versionchanged:: 3.14
479-
Added missing ``IP_RECVERR``, ``IPV6_RECVERR``, ``IP_RECVTTL``, and
480-
``IP_RECVORIGDSTADDR`` on Linux.
479+
Added missing ``IP_FREEBIND``, ``IP_RECVERR``, ``IPV6_RECVERR``,
480+
``IP_RECVTTL``, and ``IP_RECVORIGDSTADDR`` on Linux.
481481

482482
.. versionchanged:: 3.14
483483
Added support for ``TCP_QUICKACK`` on Windows platforms when available.

Doc/whatsnew/3.14.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,11 @@ Deprecated
15801580
or *sequence* as keyword arguments is now deprecated.
15811581
(Contributed by Kirill Podoprigora in :gh:`121676`.)
15821582

1583+
* :mod:`logging`:
1584+
Support for custom logging handlers with the *strm* argument is deprecated
1585+
and scheduled for removal in Python 3.16. Define handlers with the *stream*
1586+
argument instead. (Contributed by Mariusz Felisiak in :gh:`115032`.)
1587+
15831588
* :mod:`!nturl2path`: This module is now deprecated. Call
15841589
:func:`urllib.request.url2pathname` and :func:`~urllib.request.pathname2url`
15851590
instead.
@@ -2073,6 +2078,11 @@ New features
20732078
Adding ``?`` after any format unit makes ``None`` be accepted as a value.
20742079
(Contributed by Serhiy Storchaka in :gh:`112068`.)
20752080

2081+
* The ``k`` and ``K`` formats in :c:func:`PyArg_ParseTuple` and
2082+
similar functions now use :meth:`~object.__index__` if available,
2083+
like all other integer formats.
2084+
(Contributed by Serhiy Storchaka in :gh:`112068`.)
2085+
20762086
* Add macros :c:func:`Py_PACK_VERSION` and :c:func:`Py_PACK_FULL_VERSION` for
20772087
bit-packing Python version numbers.
20782088
(Contributed by Petr Viktorin in :gh:`128629`.)

Lib/_pyrepl/readline.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
# "set_pre_input_hook",
9191
"set_startup_hook",
9292
"write_history_file",
93+
"append_history_file",
9394
# ---- multiline extensions ----
9495
"multiline_input",
9596
]
@@ -453,6 +454,7 @@ def read_history_file(self, filename: str = gethistoryfile()) -> None:
453454
del buffer[:]
454455
if line:
455456
history.append(line)
457+
self.set_history_length(self.get_current_history_length())
456458

457459
def write_history_file(self, filename: str = gethistoryfile()) -> None:
458460
maxlength = self.saved_history_length
@@ -464,6 +466,19 @@ def write_history_file(self, filename: str = gethistoryfile()) -> None:
464466
entry = entry.replace("\n", "\r\n") # multiline history support
465467
f.write(entry + "\n")
466468

469+
def append_history_file(self, filename: str = gethistoryfile()) -> None:
470+
reader = self.get_reader()
471+
saved_length = self.get_history_length()
472+
length = self.get_current_history_length() - saved_length
473+
history = reader.get_trimmed_history(length)
474+
f = open(os.path.expanduser(filename), "a",
475+
encoding="utf-8", newline="\n")
476+
with f:
477+
for entry in history:
478+
entry = entry.replace("\n", "\r\n") # multiline history support
479+
f.write(entry + "\n")
480+
self.set_history_length(saved_length + length)
481+
467482
def clear_history(self) -> None:
468483
del self.get_reader().history[:]
469484

@@ -533,6 +548,7 @@ def insert_text(self, text: str) -> None:
533548
get_current_history_length = _wrapper.get_current_history_length
534549
read_history_file = _wrapper.read_history_file
535550
write_history_file = _wrapper.write_history_file
551+
append_history_file = _wrapper.append_history_file
536552
clear_history = _wrapper.clear_history
537553
get_history_item = _wrapper.get_history_item
538554
remove_history_item = _wrapper.remove_history_item

Lib/_pyrepl/simple_interact.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
import os
3131
import sys
3232
import code
33+
import warnings
3334

34-
from .readline import _get_reader, multiline_input
35+
from .readline import _get_reader, multiline_input, append_history_file
3536

3637

3738
_error: tuple[type[Exception], ...] | type[Exception]
@@ -144,6 +145,10 @@ def maybe_run_command(statement: str) -> bool:
144145
input_name = f"<python-input-{input_n}>"
145146
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
146147
assert not more
148+
try:
149+
append_history_file()
150+
except (FileNotFoundError, PermissionError, OSError) as e:
151+
warnings.warn(f"failed to open the history file for writing: {e}")
147152
input_n += 1
148153
except KeyboardInterrupt:
149154
r = _get_reader()

Lib/ast.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
"""
2-
ast
3-
~~~
4-
5-
The `ast` module helps Python applications to process trees of the Python
6-
abstract syntax grammar. The abstract syntax itself might change with
7-
each Python release; this module helps to find out programmatically what
8-
the current grammar looks like and allows modifications of it.
9-
10-
An abstract syntax tree can be generated by passing `ast.PyCF_ONLY_AST` as
11-
a flag to the `compile()` builtin function or by using the `parse()`
12-
function from this module. The result will be a tree of objects whose
13-
classes all inherit from `ast.AST`.
14-
15-
A modified abstract syntax tree can be compiled into a Python code object
16-
using the built-in `compile()` function.
17-
18-
Additionally various helper functions are provided that make working with
19-
the trees simpler. The main intention of the helper functions and this
20-
module in general is to provide an easy to use interface for libraries
21-
that work tightly with the python syntax (template engines for example).
22-
23-
24-
:copyright: Copyright 2008 by Armin Ronacher.
25-
:license: Python License.
2+
The `ast` module helps Python applications to process trees of the Python
3+
abstract syntax grammar. The abstract syntax itself might change with
4+
each Python release; this module helps to find out programmatically what
5+
the current grammar looks like and allows modifications of it.
6+
7+
An abstract syntax tree can be generated by passing `ast.PyCF_ONLY_AST` as
8+
a flag to the `compile()` builtin function or by using the `parse()`
9+
function from this module. The result will be a tree of objects whose
10+
classes all inherit from `ast.AST`.
11+
12+
A modified abstract syntax tree can be compiled into a Python code object
13+
using the built-in `compile()` function.
14+
15+
Additionally various helper functions are provided that make working with
16+
the trees simpler. The main intention of the helper functions and this
17+
module in general is to provide an easy to use interface for libraries
18+
that work tightly with the python syntax (template engines for example).
19+
20+
:copyright: Copyright 2008 by Armin Ronacher.
21+
:license: Python License.
2622
"""
2723
from _ast import *
2824

Lib/bz2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
__author__ = "Nadeem Vawda <[email protected]>"
1111

1212
from builtins import open as _builtin_open
13+
from compression._common import _streams
1314
import io
1415
import os
15-
import _compression
1616

1717
from _bz2 import BZ2Compressor, BZ2Decompressor
1818

@@ -23,7 +23,7 @@
2323
_MODE_WRITE = 3
2424

2525

26-
class BZ2File(_compression.BaseStream):
26+
class BZ2File(_streams.BaseStream):
2727

2828
"""A file object providing transparent bzip2 (de)compression.
2929
@@ -88,7 +88,7 @@ def __init__(self, filename, mode="r", *, compresslevel=9):
8888
raise TypeError("filename must be a str, bytes, file or PathLike object")
8989

9090
if self._mode == _MODE_READ:
91-
raw = _compression.DecompressReader(self._fp,
91+
raw = _streams.DecompressReader(self._fp,
9292
BZ2Decompressor, trailing_error=OSError)
9393
self._buffer = io.BufferedReader(raw)
9494
else:
@@ -248,7 +248,7 @@ def writelines(self, seq):
248248
249249
Line separators are not added between the written byte strings.
250250
"""
251-
return _compression.BaseStream.writelines(self, seq)
251+
return _streams.BaseStream.writelines(self, seq)
252252

253253
def seek(self, offset, whence=io.SEEK_SET):
254254
"""Change the file position.

Lib/compression/__init__.py

Whitespace-only changes.

Lib/_compression.py renamed to Lib/compression/_common/_streams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Internal classes used by the gzip, lzma and bz2 modules"""
1+
"""Internal classes used by compression modules"""
22

33
import io
44
import sys

Lib/compression/bz2/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import bz2
2+
__doc__ = bz2.__doc__
3+
del bz2
4+
5+
from bz2 import *

0 commit comments

Comments
 (0)