8000 Merge branch 'main' into zstandard-pc · python/cpython@ec03039 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec03039

Browse files
authored
Merge branch 'main' into zstandard-pc
2 parents 14d24ad + 0eeaa0e commit ec03039

Some content is hidden

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

73 files changed

+1127
-265
lines changed

Doc/library/ast.rst

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:mod:`!ast` --- Abstract Syntax Trees
1+
:mod:`!ast` --- Abstract syntax trees
22
=====================================
33

44
.. module:: ast
@@ -29,7 +29,7 @@ compiled into a Python code object using the built-in :func:`compile` function.
2929

3030
.. _abstract-grammar:
3131

32-
Abstract Grammar
32+
Abstract grammar
3333
----------------
3434

3535
The abstract grammar is currently defined as follows:
@@ -2156,10 +2156,10 @@ Async and await
21562156
of :class:`ast.operator`, :class:`ast.unaryop`, :class:`ast.cmpop`,
21572157
:class:`ast.boolop` and :class:`ast.expr_context`) on the returned tree
21582158
will be singletons. Changes to one will be reflected in all other
2159-
occurrences of the same value (e.g. :class:`ast.Add`).
2159+
occurrences of the same value (for example, :class:`ast.Add`).
21602160

21612161

2162-
:mod:`ast` Helpers
2162+
:mod:`ast` helpers
21632163
------------------
21642164

21652165
Apart from the node classes, the :mod:`ast` module defines these utility functions
@@ -2484,7 +2484,7 @@ and classes for traversing abstract syntax trees:
24842484

24852485
.. _ast-compiler-flags:
24862486

2487-
Compiler Flags
2487+
Compiler flags
24882488
--------------
24892489

24902490
The following flags may be passed to :func:`compile` in order to change
@@ -2533,7 +2533,7 @@ effects on the compilation of a program:
25332533

25342534
.. _ast-cli:
25352535

2536-
Command-Line Usage
2536+
Command-line usage
25372537
------------------
25382538

25392539
.. versionadded:: 3.9
@@ -2572,6 +2572,28 @@ The following options are accepted:
25722572

25732573
Indentation of nodes in AST (number of spaces).
25742574

2575+
.. option:: --feature-version <version>
2576+
2577+
Python version in the format 3.x (for example, 3.10). Defaults to the
2578+
current version of the interpreter.
2579+
2580+
.. versionadded:: next
2581+
2582+
.. option:: -O <level>
2583+
--optimize <level>
2584+
2585+
Optimization level for parser. Defaults to no optimization.
2586+
2587+
.. versionadded:: next
2588+
2589+
.. option:: --show-empty
2590+
2591+
Show empty lists and fields that are ``None``. Defaults to not showing empty
2592+
objects.
2593+
2594+
.. versionadded:: next
2595+
2596+
25752597
If :file:`infile` is specified its contents are parsed to AST and dumped
25762598
to stdout. Otherwise, the content is read from stdin.
25772599

Doc/library/gc.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ The :mod:`gc` module provides the following functions:
128128
starts. For each collection, all the objects in the young generation and some
129129
fraction of the old generation is collected.
130130

131+
In the free-threaded build, the increase in process resident set size (RSS)
132+
is also checked before running the collector. If the RSS has not increased
133+
by 10% since the last collection and the net number of object allocations
134+
has not exceeded 40 times *threshold0*, the collection is not run.
135+
131136
The fraction of the old generation that is collected is **inversely** proportional
132137
to *threshold1*. The larger *threshold1* is, the slower objects in the old generation
133138
are collected.

Doc/library/pathlib.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,10 @@ conforming to :rfc:`8089`.
872872
.. versionadded:: 3.13
873873

874874
.. versionchanged:: next
875-
If a URL authority (e.g. a hostname) is present and resolves to a local
876-
address, it is discarded. If an authority is present and *doesn't*
877-
resolve to a local address, then on Windows a UNC path is returned (as
878-
before), and on other platforms a :exc:`ValueError` is raised.
875+
The URL authority is discarded if it matches the local hostname.
876+
Otherwise, if the authority isn't empty or ``localhost``, then on
877+
Windows a UNC path is returned (as before), and on other platforms a
878+
:exc:`ValueError` is raised.
879879

880880

881881
.. method:: Path.as_uri()

Doc/library/urllib.request.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ The :mod:`urllib.request` module defines the following functions:
172172
the URL ``///etc/hosts``.
173173

174174
.. versionchanged:: next
175-
The *add_scheme* argument was added.
175+
The *add_scheme* parameter was added.
176176

177177

178-
.. function:: url2pathname(url, *, require_scheme=False)
178+
.. function:: url2pathname(url, *, require_scheme=False, resolve_host=False)
179179

180180
Convert the given ``file:`` URL to a local path. This function uses
181181
:func:`~urllib.parse.unquote` to decode the URL.
@@ -185,6 +185,13 @@ The :mod:`urllib.request` module defines the following functions:
185185
value should include the prefix; a :exc:`~urllib.error.URLError` is raised
186186
if it doesn't.
187187

188+
The URL authority is discarded if it is empty, ``localhost``, or the local
189+
hostname. Otherwise, if *resolve_host* is set to true, the authority is
190+
resolved using :func:`socket.gethostbyname` and discarded if it matches a
191+
local IP address (as per :rfc:`RFC 8089 §3 <8089#section-3>`). If the
192+
authority is still unhandled, then on Windows a UNC path is returned, and
193+
on other platforms a :exc:`~urllib.error.URLError` is raised.
194+
188195
This example shows the function being used on Windows::
189196

190197
>>> from urllib.request import url2pathname
@@ -198,14 +205,13 @@ The :mod:`urllib.request` module defines the following functions:
198205
:exc:`OSError` exception to be raised on Windows.
199206

200207
.. versionchanged:: next
201-
This function calls :func:`socket.gethostbyname` if the URL authority
202-
isn't empty, ``localhost``, or the machine hostname. If the authority
203-
resolves to a local IP address then it is discarded; otherwise, on
208+
The URL authority is discarded if it matches the local hostname.
209+
Otherwise, if the authority isn't empty or ``localhost``, then on
204210
Windows a UNC path is returned (as before), and on other platforms a
205211
:exc:`~urllib.error.URLError` is raised.
206212

207213
.. versionchanged:: next
208-
The *require_scheme* argument was added.
214+
The *require_scheme* and *resolve_host* parameters were added.
209215

210216

211217
.. function:: getproxies()

Doc/whatsnew/3.14.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,11 @@ ast
875875
that the root node type is appropriate.
876876
(Contributed by Irit Katriel in :gh:`130139`.)
877877

878+
* Add new ``--feature-version``, ``--optimize``, ``--show-empty`` options to
879+
command-line interface.
880+
(Contributed by Semyon Moroz in :gh:`133367`.)
881+
882+
878883
bdb
879884
---
880885

@@ -1438,6 +1443,11 @@ pdb
14381443
fill in a 4-space indentation now, instead of inserting a ``\t`` character.
14391444
(Contributed by Tian Gao in :gh:`130471`.)
14401445

1446+
* Auto-indent is introduced in :mod:`pdb` multi-line input. It will either
1447+
keep the indentation of the last line or insert a 4-space indentation when
1448+
it detects a new code block.
1449+
(Contributed by Tian Gao in :gh:`133350`.)
1450+
14411451
* ``$_asynctask`` is added to access the current asyncio task if applicable.
14421452
(Contributed by Tian Gao in :gh:`124367`.)
14431453

@@ -1703,9 +1713,11 @@ urllib
17031713

17041714
- Accept a complete URL when the new *require_scheme* argument is set to
17051715
true.
1706-
- Discard URL authorities that resolve to a local IP address.
1707-
- Raise :exc:`~urllib.error.URLError` if a URL authority doesn't resolve
1708-
to a local IP address, except on Windows where we return a UNC path.
1716+
- Discard URL authority if it matches the local hostname.
1717+
- Discard URL authority if it resolves to a local IP address when the new
1718+
*resolve_host* argument is set to true.
1719+
- Raise :exc:`~urllib.error.URLError` if a URL authority isn't local,
1720+
except on Windows where we return a UNC path as before.
17091721

17101722
In :func:`urllib.request.pathname2url`:
17111723

Include/cpython/object.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ typedef struct {
143143
* backwards-compatibility */
144144
typedef Py_ssize_t printfunc;
145145

146+
/* Specialize a binary op by setting the descriptor pointer */
147+
struct _PyBinopSpecializationDescr;
148+
typedef int (*binop_specialize_func)(PyObject *v, PyObject *w, int oparg,
149+
struct _PyBinopSpecializationDescr **descr);
150+
146151
// If this structure is modified, Doc/includes/typestruct.h should be updated
147152
// as well.
148153
struct _typeobject {
@@ -233,6 +238,13 @@ struct _typeobject {
233238
/* bitset of which type-watchers care about this type */
234239
unsigned char tp_watched;
235240

241+
/* callback that may specialize BINARY_OP
242+
* this is an experimental API based on the ideas in the paper
243+
* Cross Module Quickening - The Curious Case of C Extensions
244+
* by Felix Berlakovich and Stefan Brunthaler.
245+
*/
246+
binop_specialize_func tp_binop_specialize;
247+
236248
/* Number of tp_version_tag values used.
237249
* Set to _Py_ATTR_CACHE_UNUSED if the attribute cache is
238250
* disabled for this type (e.g. due to custom MRO entries).

Include/internal/pycore_code.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,18 @@ adaptive_counter_backoff(_Py_BackoffCounter counter) {
482482
/* Specialization Extensions */
483483

484484
/* callbacks for an external specialization */
485+
486+
struct _PyBinopSpecializationDescr;
487+
485488
typedef int (*binaryopguardfunc)(PyObject *lhs, PyObject *rhs);
486-
typedef PyObject *(*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
489+
typedef PyObject* (*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
490+
typedef void (*binaryopfreefunc)(struct _PyBinopSpecializationDescr *descr);
487491

488-
typedef struct {
492+
typedef struct _PyBinopSpecializationDescr {
489493
int oparg;
490494
binaryopguardfunc guard;
491495
binaryopactionfunc action;
496+
binaryopfreefunc free;
492497
} _PyBinaryOpSpecializationDescr;
493498

494499
/* Comparison bit masks. */

Include/internal/pycore_interp_structs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ struct _gc_runtime_state {
245245

246246
/* True if gc.freeze() has been used. */
247247
int freeze_active;
248+
249+
/* Resident set size (RSS) of the process after last GC. */
250+
Py_ssize_t last_rss;
251+
252+
/* This accumulates the new object count whenever collection is deferred
253+
due to the RSS increase condition not being meet. Reset on collection. */
254+
Py_ssize_t deferred_count;
255+
256+
/* Mutex held for gc_should_collect_rss(). */
257+
PyMutex mutex;
248258
#endif
249259
};
250260

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_metadata.h

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

Include/typeslots.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@
9393
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030E0000
9494
/* New in 3.14 */
9595
#define Py_tp_token 83
96+
#define Py_tp_binop_specialize 84
9697
#endif

Lib/_pyrepl/base_eventqueue.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,14 @@ def insert(self, event: Event) -> None:
6969
trace('added event {event}', event=event)
7070
self.events.append(event)
7171

72-
def push(self, char: int | bytes | str) -> None:
72+
def push(self, char: int | bytes) -> None:
7373
"""
7474
Processes a character by updating the buffer and handling special key mappings.
7575
"""
76+
assert isinstance(char, (int, bytes))
7677
ord_char = char if isinstance(char, int) else ord(char)
77-
if ord_char > 255:
78-
assert isinstance(char, str)
79-
char = bytes(char.encode(self.encoding, "replace"))
80-
self.buf.extend(char)
81-
else:
82-
char = bytes(bytearray((ord_char,)))
83-
self.buf.append(ord_char)
78+
char = ord_char.to_bytes()
79+
self.buf.append(ord_char)
8480

8581
if char in self.keymap:
8682
if self.keymap is self.compiled_keymap:

Lib/_pyrepl/windows_console.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def get_event(self, block: bool = True) -> Event | None:
464464

465465
if key == "\r":
466466
# Make enter unix-like
467-
return Event(evt="key", data="\n", raw=b"\n")
467+
return Event(evt="key", data="\n")
468468
elif key_event.wVirtualKeyCode == 8:
469469
# Turn backspace directly into the command
470470
key = "backspace"
@@ -476,24 +476,29 @@ def get_event(self, block: bool = True) -> Event | None:
476476
key = f"ctrl {key}"
477477
elif key_event.dwControlKeyState & ALT_ACTIVE:
478478
# queue the key, return the meta command
479-
self.event_queue.insert(Event(evt="key", data=key, raw=key))
479+
self.event_queue.insert(Event(evt="key", data=key))
480480
return Event(evt="key", data="\033") # keymap.py uses this for meta
481-
return Event(evt="key", data=key, raw=key)
481+
return Event(evt="key", data=key)
482482
if block:
483483
continue
484484

485485
return None
486486
elif self.__vt_support:
487487
# If virtual terminal is enabled, scanning VT sequences
488-
self.event_queue.push(rec.Event.KeyEvent.uChar.UnicodeChar)
488+
for char in raw_key.encode(self.event_queue.encoding, "replace"):
489+
self.event_queue.push(char)
489490
continue
490491

491492
if key_event.dwControlKeyState & ALT_ACTIVE:
492-
# queue the key, return the meta command
493-
self.event_queue.insert(Event(evt="key", data=key, raw=raw_key))
494-
return Event(evt="key", data="\033") # keymap.py uses this for meta
495-
496-
return Event(evt="key", data=key, raw=raw_key)
493+
# Do not swallow characters that have been entered via AltGr:
494+
# Windows internally converts AltGr to CTRL+ALT, see
495+
# https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-vkkeyscanw
496+
if not key_event.dwControlKeyState & CTRL_ACTIVE:
497+
# queue the key, return the meta command
498+
self.event_queue.insert(Event(evt="key", data=key))
499+
return Event(evt="key", data="\033") # keymap.py uses this for meta
500+
501+
return Event(evt="key", data=key)
497502
return self.event_queue.get()
498503

499504
def push_char(self, char: int | bytes) -> None:

0 commit comments

Comments
 (0)
0