Skip to content

Commit 3cd822e

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Import CPython 3.14.10+ stable branch (2026-11-11)
Summary: Imported python/cpython `3.14.10+` from upstream rev [`a5e78cb`](https://www.github.com/python/cpython/commit/a5e78cbb9d3efb7b601eca82336d1e97e993dd48) (committed 2026-11-11 07:35:08+00:00). # Commit Info - Base: (`3.14.10+`) - [`d68d5f3`](https://www.github.com/python/cpython/commit/d68d5f328cc3cec969fc68be36013e3a952d58ed) (commit date: 2026-11-09 09:05:30+00:00) - Imported: (`3.14.10+`) - [`a5e78cb`](https://www.github.com/python/cpython/commit/a5e78cbb9d3efb7b601eca82336d1e97e993dd48) (commit date: 2026-11-11 07:35:08+00:00) # Noteworthy file changes - Low-signal files (10 added) (NEWS.d, docs, .github) Complete list of added/removed files: https://www.internalfb.com/intern/everpaste/?color=0&handle=GJGNrzCTpuxdywsEAHNhrK7VmnBhbr0LAAAz Reviewed By: KasraGhodsi Differential Revision: D131206542 fbshipit-source-id: 6cbe0fc1ff44bb1e94490a8ce91f61f8f34056d3
1 parent 854a4c6 commit 3cd822e

43 files changed

Lines changed: 493 additions & 56 deletions

Some content is hidden

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

‎Doc/c-api/init_config.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,8 @@ PyConfig
12161216
12171217
.. c:member:: int safe_path
12181218
1219-
If equals to zero, ``Py_RunMain()`` prepends a potentially unsafe path to
1220-
:data:`sys.path` at startup:
1219+
If equals to zero, ``Py_RunMain()`` prepends a potentially unsafe
1220+
:data:`sys._path0` to :data:`sys.path` at startup:
12211221
12221222
* If :c:member:`argv[0] <PyConfig.argv>` is equal to ``L"-m"``
12231223
(``python -m module``), prepend the current working directory.

‎Doc/glossary.rst‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ Glossary
2929
Abstract base classes complement :term:`duck-typing` by
3030
providing a way to define interfaces when other techniques like
3131
:func:`hasattr` would be clumsy or subtly wrong (for example with
32-
:ref:`magic methods <special-lookup>`). ABCs introduce virtual
33-
subclasses, which are classes that don't inherit from a class but are
34-
still recognized by :func:`isinstance` and :func:`issubclass`; see the
32+
:ref:`magic methods <special-lookup>`). ABCs introduce
33+
:term:`virtual subclasses <virtual subclass>`, which are classes that
34+
don't inherit from a class but are still recognized by
35+
:func:`isinstance` and :func:`issubclass`; see the
3536
:mod:`abc` module documentation. Python comes with many built-in ABCs for
3637
data structures (in the :mod:`collections.abc` module), numbers (in the
3738
:mod:`numbers` module), streams (in the :mod:`io` module), import finders
@@ -1727,6 +1728,12 @@ Glossary
17271728
A computer defined entirely in software. Python's virtual machine
17281729
executes the :term:`bytecode` emitted by the bytecode compiler.
17291730

1731+
virtual subclass
1732+
A class that :func:`issubclass` and :func:`isinstance` treat as a
1733+
subclass of an :term:`abstract base class` even though it does not
1734+
inherit from it. A class is made a virtual subclass by registering
1735+
it with the ABC's :meth:`~abc.ABCMeta.register` method.
1736+
17301737
walrus operator
17311738
A light-hearted way to refer to the :ref:`assignment expression
17321739
<assignment-expressions>` operator ``:=`` because it looks a bit like a

‎Doc/library/sys.rst‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,24 @@ always available. Unless explicitly noted otherwise, all variables are read-only
15161516
* Module :mod:`site` This describes how to use .pth files to
15171517
extend :data:`sys.path`.
15181518

1519+
.. data:: _path0
1520+
1521+
Path prepended to :data:`sys.path` at Python startup:
1522+
1523+
* Current directory if running a module
1524+
with ``python -m module`` command line.
1525+
* Script's directory if running a script
1526+
with ``python script.py``.
1527+
* Otherwise an empty string, which means the current working directory,
1528+
for ``python -c code`` or ``python`` (REPL) command line.
1529+
1530+
If :option:`-P` or :option:`-I` command line options are used or if
1531+
:envvar:`PYTHONSAFEPATH` environment variable is used, :data:`sys._path0` is
1532+
``None`` and :data:`sys.path` is left unchanged.
1533+
1534+
.. versionadded:: next
1535+
1536+
15191537
.. data:: path_hooks
15201538

15211539
A list of callables that take a path argument to try to create a

‎Doc/library/urllib.request.rst‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ The following classes are provided:
382382
``HTTP_PROXY`` will be ignored if a variable ``REQUEST_METHOD`` is set;
383383
see the documentation on :func:`~urllib.request.getproxies`.
384384

385+
Because *proxies* holds at most one proxy for each protocol, it cannot
386+
use a proxy auto-config (PAC) file, which selects a proxy for each
387+
URL. See :ref:`this example <urllib-request-pac>` for one way to use a
388+
PAC file.
389+
385390

386391
.. class:: HTTPPasswordMgr()
387392

@@ -1386,6 +1391,51 @@ programmatically supplied proxy URLs, and adds proxy authorization support with
13861391
with opener.open('http://www.example.com/login.html') as f:
13871392
print(f.read().decode('utf-8'))
13881393

1394+
.. _urllib-request-pac:
1395+
1396+
Proxy auto-config (PAC) files select a proxy for each URL, so they cannot be
1397+
described by the *proxies* mapping that :class:`ProxyHandler` expects. The
1398+
:pypi:`pypac` package finds and evaluates PAC files; its ``ProxyResolver``
1399+
can be used to write a handler that consults the PAC file once per request::
1400+
1401+
import urllib.error
1402+
import urllib.request
1403+
from pypac import get_pac
1404+
from pypac.resolver import ProxyResolver
1405+
1406+
class PACProxyHandler(urllib.request.ProxyHandler):
1407+
1408+
def __init__(self, resolver):
1409+
self.resolver = resolver
1410+
# An empty mapping suppresses the <protocol>_open methods that
1411+
# ProxyHandler would make from a static proxies mapping.
1412+
super().__init__({})
1413+
1414+
def _pac_open(self, req, protocol):
1415+
proxy = self.resolver.get_proxy(req.full_url)
1416+
if proxy is None:
1417+
raise urllib.error.URLError('no proxy available')
1418+
if proxy == 'DIRECT':
1419+
return None # continue with the remaining handlers
1420+
if proxy.startswith('socks'):
1421+
raise urllib.error.URLError('SOCKS proxies are not supported')
1422+
return self.proxy_open(req, proxy, protocol)
1423+
1424+
def http_open(self, req):
1425+
return self._pac_open(req, 'http')
1426+
1427+
def https_open(self, req):
1428+
return self._pac_open(req, 'https')
1429+
1430+
opener = urllib.request.build_opener(PACProxyHandler(ProxyResolver(get_pac())))
1431+
with opener.open('http://www.example.com/') as f:
1432+
print(f.read().decode('utf-8'))
1433+
1434+
Note that a PAC file may also select a SOCKS proxy, which :mod:`urllib.request`
1435+
cannot use, and that the :envvar:`no_proxy` environment variable and the
1436+
operating system's proxy bypass list still apply to requests the PAC file
1437+
assigned to a proxy.
1438+
13891439
Adding HTTP headers:
13901440

13911441
Use the *headers* argument to the :class:`Request` constructor, or::

‎Doc/using/cmdline.rst‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,12 @@ Miscellaneous options
313313
Run Python in isolated mode. This also implies :option:`-E`, :option:`-P`
314314
and :option:`-s` options.
315315

316-
In isolated mode :data:`sys.path` contains neither the script's directory nor
317-
the user's site-packages directory. All ``PYTHON*`` environment
318-
variables are ignored, too. Further restrictions may be imposed to prevent
319-
the user from injecting malicious code.
316+
In isolated mode, Python does not prepend the potentially unsafe path
317+
:data:`sys._path0` to :data:`sys.path`, and ignores all ``PYTHON*``
318+
environment variables, e.g. :envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`,
319+
that might be set.
320+
Further restrictions may be imposed to prevent the user from injecting
321+
malicious code.
320322

321323
.. versionadded:: 3.4
322324

@@ -344,14 +346,8 @@ Miscellaneous options
344346

345347
.. option:: -P
346348

347-
Don't prepend a potentially unsafe path to :data:`sys.path`:
348-
349-
* ``python -m module`` command line: Don't prepend the current working
350-
directory.
351-
* ``python script.py`` command line: Don't prepend the script's directory.
352-
If it's a symbolic link, resolve symbolic links.
353-
* ``python -c code`` and ``python`` (REPL) command lines: Don't prepend an
354-
empty string, which means the current working directory.
349+
Don't prepend the potentially unsafe path :data:`sys._path0` to
350+
:data:`sys.path`.
355351

356352
See also the :envvar:`PYTHONSAFEPATH` environment variable, and :option:`-E`
357353
and :option:`-I` (isolated) options.
@@ -784,7 +780,9 @@ conflict.
784780
.. envvar:: PYTHONSAFEPATH
785781

786782
If this is set to a non-empty string, don't prepend a potentially unsafe
787-
path to :data:`sys.path`: see the :option:`-P` option for details.
783+
path :data:`sys._path0` to :data:`sys.path`.
784+
785+
See also the :option:`-P` option.
788786

789787
.. versionadded:: 3.11
790788

‎Lib/_pyio.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,9 +2417,12 @@ def tell(self):
24172417
# be O(1) in most situations (common decoders, sensible input).
24182418
# Actually, it will be exactly 1 for fixed-size codecs (all
24192419
# 8-bit codecs, also UTF-16 and UTF-32).
2420-
skip_bytes = int(self._b2cratio * chars_to_skip)
2420+
skip_estimate = self._b2cratio * chars_to_skip
2421+
if 0 <= skip_estimate <= len(next_input):
2422+
skip_bytes = int(skip_estimate)
2423+
else:
2424+
skip_bytes = 0
24212425
skip_back = 1
2422-
assert skip_bytes <= len(next_input)
24232426
while skip_bytes > 0:
24242427
decoder.setstate((b'', dec_flags))
24252428
# Decode up to temptative start point

‎Lib/asyncio/base_tasks.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,16 @@ def _task_get_stack(task, limit):
6767

6868

6969
def _task_print_stack(task, limit, file):
70+
exc = task._exception
71+
tb = exc.__traceback__ if exc is not None else None
7072
extracted_list = []
7173
checked = set()
7274
for f in task.get_stack(limit=limit):
73-
lineno = f.f_lineno
75+
if tb is not None:
76+
lineno = tb.tb_lineno
77+
tb = tb.tb_next
78+
else:
79+
lineno = f.f_lineno
7480
co = f.f_code
7581
filename = co.co_filename
7682
name = co.co_name
@@ -80,7 +86,6 @@ def _task_print_stack(task, limit, file):
8086
line = linecache.getline(filename, lineno, f.f_globals)
8187
extracted_list.append((filename, lineno, name, line))
8288

83-
exc = task._exception
8489
if not extracted_list:
8590
print(f'No stack for {task!r}', file=file)
8691
elif exc is not None:

‎Lib/gzip.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,11 @@ def decompress(data):
695695

696696
def main():
697697
from argparse import ArgumentParser
698+
import runpy
699+
700+
# Prevent shadowing a stdlib module from the extracted file
701+
runpy._remove_sys_path0()
702+
698703
parser = ArgumentParser(description=
699704
"A simple command line interface for the gzip module: act like gzip, "
700705
"but do not delete the input file.",

‎Lib/multiprocessing/shared_memory.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __init__(self, name=None, create=False, size=0, *, track=True):
186186

187187
def __del__(self):
188188
try:
189-
self.close()
189+
self._closefd()
190190
except OSError:
191191
pass
192192

@@ -222,6 +222,11 @@ def size(self):
222222
"Size in bytes."
223223
return self._size
224224

225+
def _closefd(self):
226+
if _USE_POSIX and self._fd >= 0:
227+
os.close(self._fd)
228+
self._fd = -1
229+
225230
def close(self):
226231
"""Closes access to the shared memory from this instance but does
227232
not destroy the shared memory block."""
@@ -231,9 +236,7 @@ def close(self):
231236
if self._mmap is not None:
232237
self._mmap.close()
233238
self._mmap = None
234-
if _USE_POSIX and self._fd >= 0:
235-
os.close(self._fd)
236-
self._fd = -1
239+
self._closefd()
237240

238241
def unlink(self):
239242
"""Requests that the underlying shared memory block be destroyed.

‎Lib/runpy.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,26 @@ def run_path(path_name, init_globals=None, run_name=None):
317317
pass
318318

319319

320+
def _remove_sys_path0():
321+
"""
322+
Remove sys._path0 from sys.path. Do nothing if sys._path0 is
323+
sys._stdlib_dir or if it has already been removed. Similar to using -P
324+
(safe path) command line option.
325+
"""
326+
path0 = sys._path0
327+
if path0 is None:
328+
return
329+
330+
if path0 == sys._stdlib_dir:
331+
return
332+
333+
# Remove all path0 copies, not only the first one.
334+
# We are intentionally not trying to normalize & match alternate
335+
# representations of path0, this is only intended to remove copies
336+
# of the exact value the runtime itself may have added.
337+
sys.path[:] = [path for path in sys.path if path != path0]
338+
339+
320340
if __name__ == "__main__":
321341
# Run the module specified as the next command line argument
322342
if len(sys.argv) < 2:

0 commit comments

Comments
 (0)