Commit graph

57216 commits

Author SHA1 Message Date
Miss Islington (bot)
dc5ebe3da4
[3.15] gh-123619: Fix PyUnstable_Object_EnableDeferredRefcount() (GH-151260) (#151326)
gh-123619: Fix PyUnstable_Object_EnableDeferredRefcount() (GH-151260)

Return 0 if the object is not tracked by the GC.
(cherry picked from commit 72e7eddce6)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-11 11:21:26 +00:00
Miss Islington (bot)
9d0999133e
[3.15] gh-151295: Fix use-after-free in bytes.join()/bytearray.join() via re-entrant __buffer__ (GH-151296) (GH-151304)
(cherry picked from commit 84a322aa15)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
2026-06-11 11:30:24 +03:00
Miss Islington (bot)
e8d914fd49
[3.15] gh-151278: Fix test_faulthandler on UBSan (GH-151279) (#151281)
gh-151278: Fix test_faulthandler on UBSan (GH-151279)

* Py_FatalError() no longer calls _PyFaulthandler_Fini() if it
  doesn't hold the GIL.
* Skip test_faulthandler tests raising signals if run with UBSan.
* Enable test_faulthandler in GitHub Action "Reusable Sanitizer".
(cherry picked from commit e60c42dc3f)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-10 20:07:07 +00:00
Victor Stinner
10f616cf39
[3.15] gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250) (#151269)
gh-151253: Dump the Python path configuration on _PyCodec_InitRegistry() failure (#151250)

If "import encodings" fails at Python startup, dump the Python path
configuration to help users debugging their configuration. The
encodings module is the first module imported during Python startup.

(cherry picked from commit 7b6e98911e)
2026-06-10 22:03:27 +02:00
Miss Islington (bot)
5c83037313
[3.15] gh-109940: Respect VIRTUAL_ENV_DISABLE_PROMPT in activate.bat (GH-151215) (GH-151225)
Co-authored-by: Harjoth Khara <harjoth.khara@gmail.com>
2026-06-10 17:48:10 +01:00
Miss Islington (bot)
9261f8b588
[3.15] gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_into (GH-143987) (#151246)
gh-143988: Fix re-entrant mutation crashes in socket sendmsg/recvmsg_into (GH-143987)

Fix crashes in socket.sendmsg() and socket.recvmsg_into() that could
occur if buffer sequences are mutated re-entrantly during argument
parsing via __buffer__ protocol callbacks.

The bug occurs because:

1. PySequence_Fast() returns the original list object when the input
   is already a list (not a copy).
2. During iteration, PyObject_GetBuffer() triggers __buffer__
   callbacks which may clear the list.
3. Subsequent iterations access invalid memory (heap OOB read).

The fix replaces PySequence_Fast() with PySequence_Tuple() which
always creates a new tuple, ensuring the sequence cannot be mutated
during iteration.
(cherry picked from commit 896f7fdc7d)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: tonghuaroot <23011166+tonghuaroot@users.noreply.github.com>
2026-06-10 14:25:33 +00:00
Miss Islington (bot)
7a76730125
[3.15] Add yet one assertion in test_set_text_charset_cp949 (GH-151224) (GH-151237)
Add yet one assertion in test_set_text_charset_cp949 (GH-151224)

Check bytes(m), not only str(m).
(cherry picked from commit 3ca93ab198)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-10 13:36:58 +00:00
Miss Islington (bot)
7201b9d18f
[3.15] gh-150988: Fix refleak in OSError when attrs are set before super().__init__() (GH-150990) (#151240)
gh-150988: Fix refleak in `OSError` when attrs are set before `super().__init__()` (GH-150990)
(cherry picked from commit f2a0f82282)

Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-10 12:56:54 +00:00
Miss Islington (bot)
153607ef89
[3.15] gh-98894: Fix DTrace test_check_probes for shared builds (GH-151122) (#151235)
gh-98894: Fix DTrace test_check_probes for shared builds (GH-151122)

When building with --enable-shared, the SystemTap/DTrace notes
live in libpython. Add detection logic to be used by readelf.

Force the C locale on readelf output.
(cherry picked from commit 3a08e93739)

Co-authored-by: stratakis <cstratak@redhat.com>
2026-06-10 11:35:01 +00:00
Miss Islington (bot)
73e5d444ac
[3.15] gh-150700: Fix class-scope inline comprehensions when nested scopes reference __class__ and friends (GH-150735) (#151211)
gh-150700: Fix class-scope inline comprehensions when nested scopes reference `__class__` and friends (GH-150735)

* Fix class-scope inline comprehensions when nested scopes reference `__class__` and friends

In `inline_comprehension()`, when `__class__` / `__classdict__` /
`__conditional_annotations__` appears as `FREE` in a comprehension's
symbol table because a nested scope captured it (e.g. nested lambdas),
this name is still discarded from `comp_free` unconditionally.

This prevents `drop_class_free()` from seeing it, so the appropriate
`ste_needs_(...)` flag is never set on the enclosing class.
That leads to `codegen_make_closure()` throwing `SystemError` when it
couldn't find `__class__` / `__classdict__` /
`__conditional_annotations__` in the class's cellvars.

From now on we just discard from `comp_free` when no child scope
(e.g. a lambda) still needs the name as `FREE`. When a child scope does
need it, keep it in `comp_free` so `drop_class_free()` can set the
appropriate flag and the class creates the implicit cell.

* Fix tests

* Fix typo

* Fix formatting

* Add test checking validity of `__class__` returned

* Prefer 'used' to 'deferred'
(cherry picked from commit ce916dc506)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-06-09 16:33:04 -07:00
Miss Islington (bot)
2aba3d99ac
[3.15] gh-150285: Fix too long docstrings in the asyncio package (GH-151074) (GH-151172)
(cherry picked from commit ed2b04248a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-09 16:41:54 +00:00
Miss Islington (bot)
ca0cb46648
[3.15] gh-150285: Fix too long docstrings in the concurrent package (GH-151076) (GH-151173)
(cherry picked from commit 0fa06f4d7f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-09 16:41:26 +00:00
Miss Islington (bot)
19e4b8f559
[3.15] gh-109503: Fix document for shutil.move() on usage of os.rename() since it's inaccurate (GH-109507) (GH-150611)
Nonatomic move might be used even if the files are
on the same filesystem in some cases.
(cherry picked from commit 6ecd197c03)

Co-authored-by: Fang Li <fangli@users.noreply.github.com>
2026-06-09 16:06:30 +03:00
Miss Islington (bot)
3199f3ba29
[3.15] gh-151039: Fix a crash when _datetime types outlive _datetime module (GH-151044) (#151143)
gh-151039: Fix a crash when `_datetime` types outlive `_datetime` module (GH-151044)
(cherry picked from commit 9fdbade99e)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-06-09 12:14:47 +00:00
Miss Islington (bot)
2d432f21db
[3.15] gh-151130: Add more tests for PyWeakref_* C API (GH-151131) (GH-151140)
(cherry picked from commit c3cd75afdf)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-09 11:37:56 +00:00
Pablo Galindo Salgado
83e26a43a7
[3.15] gh-149321: Remove lazy_imports=none startup mode (GH-149389) (#150129) 2026-06-08 22:55:57 +00:00
Miss Islington (bot)
fd252e80f5
[3.15] gh-148932: Fix profiling.sampling on Windows virtual environments (GH-150541) (#151097)
gh-148932: Fix `profiling.sampling` on Windows virtual environments (GH-150541)
(cherry picked from commit 5c13217314)

Co-authored-by: Eduardo Villalpando Mello <eduardovil@microsoft.com>
2026-06-08 23:04:06 +01:00
Miss Islington (bot)
eeba221905
[3.15] gh-150633: Minor improvement of a newly added test (GH-151103) (#151106)
gh-150633: Minor improvement of a newly added test (GH-151103)

Minor improvement of a newly added test.
(cherry picked from commit fccf67a354)

Co-authored-by: Barry Warsaw <barry@python.org>
2026-06-08 13:04:02 -07:00
Miss Islington (bot)
5751633fac
[3.15] gh-150633: Properly handle null characters in the name when importing frozen modules (GH-150634) (GH-151100)
(cherry picked from commit 54de5475cd)

Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com>
2026-06-08 18:58:11 +00:00
Miss Islington (bot)
e795bd4be7
[3.15] gh-119949: Refactor test_exc() helper in test_format.py (GH-135452) (GH-150329)
Use assertRaisesRegex() context and fix
https://github.com/python/cpython/pull/119781#pullrequestreview-2088240959

(cherry picked from commit 0851700a9d)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2026-06-08 18:01:52 +00:00
Miss Islington (bot)
99979753b3
[3.15] gh-149816: Fix SNI callback callable race (GH-150018) (GH-150099)
(cherry picked from commit 8b31d08e62)

Co-authored-by: Kirill Ignatev <kiri11@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2026-06-08 21:01:31 +03:00
Miss Islington (bot)
199751ea6a
[3.15] gh-151019: Fix test_os on 32-bit FreeBSD (GH-151087) (#151093)
gh-151019: Fix test_os on 32-bit FreeBSD (GH-151087)

Remove references to server.handler_instance. This attribute has been
removed in 2022 by commit 3ae975f1ac.
(cherry picked from commit a9002349cb)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-08 17:25:50 +00:00
Miss Islington (bot)
d3ca26983d
[3.15] gh-150599: Prevent bz2 decompressor reuse after errors (GH-150600)
(cherry picked from commit 5755d0f083)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-07 17:48:30 +01:00
Miss Islington (bot)
a642d1ab38
[3.15] gh-151021: Fix mmap empty searches past the end (GH-151023) (GH-151041)
(cherry picked from commit f2cab7b0cf)

Co-authored-by: esadomer <54475303+esadomer@users.noreply.github.com>
2026-06-07 13:27:26 +00:00
Miss Islington (bot)
d7aef33bd7
[3.15] gh-148954: Escape methodname in xmlrpc.client.dumps() to prevent XML injection (GH-148968) (GH-151033)
(cherry picked from commit ab930175e7)

Co-authored-by: Sanyam Kumat <124618873+sanyamk23@users.noreply.github.com>
2026-06-07 10:52:40 +03:00
Miss Islington (bot)
96073736a4
[3.15] gh-50948: IDLE: Warn if saving a file will overwrite a newer version (GH-17578) (GH-151026)
(cherry picked from commit 69851a6407)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Co-authored-by: Guilherme Polo <ggpolo@gmail.com>
Co-authored-by: Priya Pappachan <priyapappachan010@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-07 00:11:55 +03:00
Miss Islington (bot)
9352936b4e
[3.15] gh-149083: Use sentinel for urllib.parse._UNSPECIFIED (GH-149612) (#151017)
This was added in 3.15; let's use a real sentinel instead of an ad-hoc list object.
(cherry picked from commit 884ac3e3ec)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2026-06-06 13:13:52 +00:00
Miss Islington (bot)
ad8a3d33be
[3.15] gh-150662: Stop unbounded memory growth in Tachyon --gecko collector (GH-150845) (#151000) 2026-06-06 13:45:53 +01:00
Miss Islington (bot)
0a2e7af44b
[3.15] gh-149835: Use realpath() instead of abspath() in shutil.move() (GH-149986) (GH-151009)
(cherry picked from commit fab449bddb)

Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com>
2026-06-06 10:29:57 +00:00
Miss Islington (bot)
d0a263d6d6
[3.15] gh-149977: Fix extra output of -m test test_lazy_import, again (GH-150965) (#150975)
gh-149977: Fix extra output of `-m test test_lazy_import`, again (GH-150965)
(cherry picked from commit 9b4090c48e)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-06-05 15:46:57 +00:00
Miss Islington (bot)
68f814eb71
[3.15] gh-53144: Improve charset support in the email package (GH-149942) (GH-150967)
Defer to the codecs module for all aliases.
Use MIME/IANA names for all IANA registered charsets.
Fix email.contentmanager.set_text_content().
(cherry picked from commit c195a046f8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-05 13:22:33 +00:00
Miss Islington (bot)
e8384cf1a0
[3.15] gh-149891: Add more encoding aliases (GH-149892) (GH-150961)
Support all aliases officially registered in IANA, except
Extended_UNIX_Code_Packed_Format_for_Japanese.

New names:
KSC_5601, KS_C_5601-1989, iso-ir-149, GB_2312-80, windows-936, mac,
CCSID00858, CCSID01140, and a number of "cs"-prefixed names.

Fix csHPRoman8, which was not normalized.
(cherry picked from commit 49f4ecfb08)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-05 15:45:22 +03:00
Miss Islington (bot)
675ed8a749
[3.15] gh-62825: Fix encoding aliases "KS_C_5601-1987", "KS X 1001", etc (GH-150933) (GH-150946)
They are now aliases of CP949 instead of EUC-KR.
(cherry picked from commit 45562c6f4f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-06-05 14:41:22 +03:00
sobolevn
b48c208bb0
[3.15] gh-150899: Do not reset custom -Xlazy_imports mode in test_lazy_imports (GH-150900) (#150947)
(cherry picked from commit 2f064fbc0b)
2026-06-05 08:43:27 +00:00
Miss Islington (bot)
a13fd39832
[3.15] gh-145177: Bump emscripten version to 4.0.19 (GH-150926) (#150939)
Bumps the emscripten version to 4.0.19.
(cherry picked from commit c83d3d789e)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
2026-06-05 06:25:21 +00:00
Miss Islington (bot)
c6d64cc60d
[3.15] gh-150913: Fix sqlite3.Blob validation for empty slice assignment (GH-150915) (GH-150923)
ass_subscript_slice() returned early when the computed slice length
was zero, bypassing validation performed for non-empty slices.
(cherry picked from commit fc9c4db130)

Co-authored-by: Jiseok CHOI <jiseok.dev@gmail.com>
2026-06-04 14:10:30 +00:00
Miss Islington (bot)
42a41cc69f
[3.15] gh-150750: Fix a race condition in deque.index with free-threading (GH-150779) (#150920)
gh-150750: Fix a race condition in `deque.index` with free-threading (GH-150779)
(cherry picked from commit d83d50b5b7)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-06-04 13:58:59 +00:00
Miss Islington (bot)
6b46aac7d6
[3.15] gh-150436: Skip subprocess test on STATUS_DLL_INIT_FAILED (GH-150704) (#150713)
gh-150436: Skip subprocess test on STATUS_DLL_INIT_FAILED (GH-150704)

If a subprocess spawned with CREATE_NEW_CONSOLE creation flag fails
with STATUS_DLL_INIT_FAILED return code, skip the test. It's likely a
memory allocation failure in the desktop heap memory which caused the
DLL init failure.
(cherry picked from commit e8034dd841)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-06-04 08:46:08 +00:00
Miss Islington (bot)
d7505294df
[3.15] gh-148613: Fix race in gc_set_threshold and gc_get_threshold (GH-150356) (#150841)
gh-148613: Fix race in `gc_set_threshold` and `gc_get_threshold` (GH-150356)
(cherry picked from commit 41eb8ee2bb)

Co-authored-by: Edward Xu <xuxiangad@gmail.com>
2026-06-04 12:43:46 +05:30
Miss Islington (bot)
54bd7c0258
[3.15] gh-132467: Document and test that generic aliases are not classes (GH-133504) (#150854)
gh-132467: Document and test that generic aliases are not classes (GH-133504)
(cherry picked from commit 5915a1fb9d)

Co-authored-by: Abduaziz π <mail@ziyodov.uz>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2026-06-03 08:26:36 -07:00
Miss Islington (bot)
21a4ac77be
[3.15] gh-91099: fix[imaplib]: call Exception with string instance (GH-31823) (#150811)
* bpo-46943: fix[imaplib]: call Exception with string instance

Adjust the behavior of 'login' to be similar to `authenticate()`,
where self.error is called with a str() instance.
(cherry picked from commit 29805f00a1)

Co-authored-by: Florian Best <spaceone@users.noreply.github.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2026-06-03 09:12:46 -04:00
Miss Islington (bot)
f8cea98b4e
[3.15] gh-149805: Fix SystemError when compiling __classdict__ class annotation (GH-149806)
(cherry picked from commit c52d2b16dd)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-06-03 09:39:22 +01:00
Miss Islington (bot)
53e7f2400a
[3.15] gh-150723: Fix perf jitdump files on macOS (GH-150728) (#150832)
gh-150723: Fix perf jitdump files on macOS (GH-150728)

The perf jitdump format defines the thread id field of the JR_CODE_LOAD
record as a 32-bit value, but on macOS it was declared as a uint64_t
(since pthread_threadid_np() returns a uint64_t). Those extra 8 bytes
plus alignment padding shifted every following field, so parsers reading
the file by the spec misread code_size as the code address and failed to
resolve any Python frames.

Declare thread_id as uint32_t on all platforms and truncate the macOS
thread id when writing the record. The value is only informational.
Symbols are resolved by address, and not thread ids so truncation is
safe here.

* Use mach_absolute_time for macOS jitdump timestamps

On macOS the jitdump file is consumed by profilers such as samply, which
timestamp their samples using mach_absolute_time(). The jitdump events were
stamped with clock_gettime(CLOCK_MONOTONIC), a different clock domain that
keeps advancing while the system is asleep, so the JIT code mappings could be
off by days relative to the samples and no Python frame would resolve. Stamp
jitdump events with mach_absolute_time() on macOS so they share the sampler's
clock domain. Linux continues to use CLOCK_MONOTONIC to stay aligned with perf.

Exercise the -Xperf_jit (jitdump) backend through samply and assert that
Python frames resolve, exercising the binary jitdump path end to end.
Skipped when samply is not installed.
(cherry picked from commit 494f2e3c92)

Co-authored-by: Nazım Can Altınova <canaltinova@gmail.com>
2026-06-03 00:41:24 +00:00
Hugo van Kemenade
49c92ac874 Merge branch '3.15' of https://github.com/python/cpython into 3.15 2026-06-02 20:35:34 +03:00
Miss Islington (bot)
fd0a7fd5ba
[3.15] gh-101913: changed wording of docstring for _parsedate_tz (GH-134446) (#150796)
Fixed incorrect word.
(cherry picked from commit f7e0fb60cf)

Co-authored-by: Gustaf <79180496+gostak-dd@users.noreply.github.com>
Co-authored-by: Gustaf <79180496+GGyll@users.noreply.github.com>
2026-06-02 11:31:56 -04:00
Hugo van Kemenade
94a64bbc6c Python 3.15.0b2 2026-06-02 18:28:41 +03:00
Miss Islington (bot)
80f3d798a7
[3.15] gh-150720: Remove '-d 1' in test_script_error_treatment (GH-150736) (#150746)
Co-authored-by: László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
2026-06-02 14:32:04 +03:00
Miss Islington (bot)
c5512bd7c1
[3.15] gh-149079: Fix O(n^2) canonical ordering in unicodedata.normalize() (GH-149080) (#150776)
Replace the insertion sort used for canonical ordering of combining
characters with a hybrid approach: insertion sort for short runs (< 20)
and counting sort for longer runs, reducing worst-case complexity from
O(n^2) to O(n). This prevents denial of service via crafted Unicode
strings with many combining characters in alternating CCC order.
(cherry picked from commit 991224b1e8)

Co-authored-by: Seth Larson <seth@python.org>
Co-authored-by: ch4n3-yoon <ch4n3.yoon@gmail.com>
Co-authored-by: Seokchan Yoon <13852925+ch4n3-yoon@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
2026-06-02 10:10:04 +00:00
Miss Islington (bot)
1835400ff5
[3.15] gh-149738: Fix segmentation fault bug in sqllite3 (GH-149754) (#150768)
gh-149738: Fix segmentation fault bug in sqllite3 (GH-149754)

Deleting the `row_factory` or `text_factory` attribute is no longer allowed.
(cherry picked from commit 60fdb3192b)

Co-authored-by: Sepehr Rasouli <sepehrrasouli06@gmail.com>
2026-06-02 09:36:03 +00:00
Miss Islington (bot)
848ba18bcd
[3.15] gh-150228: Improve the PEP 829 batch processing APIs (GH-150542) (#150748)
gh-150228: Improve the PEP 829 batch processing APIs (GH-150542)

* gh-150228: Improve the PEP 829 batch processing APIs

As previously discussed with @ncoghlan and approved for 3.15b2 by @hugovk,
this implements the batch processing APIs for addsitedir() and friends.  We
remove the `defer_processing_start_files` flag which required some implicit
module global state, and promote StartupState to the public documented API.

This also moves the bulk of the module global functions into methods of the
`StartupState` class, so it removes the awkward APIs in 3.15b1.  Now, instances
of this class are an accumulator for startup state, using `StartupState.process()`
to process them.  Callers can now batch up startup state themselves by using
the methods on this class.  The module global functions are shims for this
which preserve the legacy APIs and semantics using the new state class.

This PR also fixes the interleaving regression identified by @ncoghlan in the
same issue.  Now, .pth file sys.path extensions are added to sys.path after
the sitedir that the .pth file is found in, restoring the legacy behavior.

Along the way, I've made a lot of improvements to function docstrings,
site.rst documentation, and comments in the code explaining what's going on.

* Add a note that if known_paths is provided to StartupState.__init__(), it
  will get mutated in place.
* Improve some conditional flows.
* Improve some comments.
* Improve the what's new entry.

* Make test_impl_exec_imports_suppressed_by_matching_start() more robust

Based on PR comment, we need to read both the .pth and .start files, and prove
that the .pth file's import line (which passes a bigger increment) is not
called, but the .start file's entry point (which uses the default increment)
is called.

* As per review, move some methods to the private API

_read_pth_file() and _read_start_file() are not intended to be part of the
public API surface outside of the site module, so even though they are used by
methods outside of the StartupState class, make them privately named.

* Resolve several review feedbacks

* Move a `versionadded`
* Better list comprehension formatting (use the output from
  `ruff format --line-length 78`)

* Add docs for site.makepath() and point the case-normalization requirement to
  this utility function.
* Note that StartupState.process() is not idempotent.

* Address another feedback comment

This time, we get rid of the legacy implementation `reset` local, which was
always difficult to understand, and just implement a return value based on the
processing mode selected.

* Changes based on gh-150228 review

The comment by @encukou that started this change:

```
I still see two red flags here though: an argument that doesn't combine with
other arguments, and (another instance of) changing the return type based on
an argument.

Did you consider adding a StartupState.addsitedir(sitedir) method, instead of
the startup_state argument?
```

As it turns out, this is an even cleaner design.  By moving the bulk of the
previous module global functions into `StartupState` methods, we can get rid
of all the awkward `startup_state` keyword-only arguments which conflict
with `known_path` (Petr's first point).  We can also get rid of the
return value dichotomy (Petr's second point) because now we can preserve
exactly the Python 3.14 API in the module global functions, and implement
the better APIs in the class methods.  We also generally don't have to
pass around `process_known_sitedirs`.

Now the following module global functions are essentially shims around
class methods:

* site.addsitedir() -> StartupState.addsitedir()
* site.addusersitepackages() -> StartupState.addusersitepackages()
* site.addsitepackages() -> StartupState.addsitepackages()
* Additional minor changes
* Remove a now unused parameter

(cherry picked from commit 27ebd9abce)

Co-authored-by: Barry Warsaw <barry@python.org>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-06-02 02:11:51 +00:00