Commit Graph

123921 Commits

Author SHA1 Message Date
Raymond Hettinger b2a7272408
Misc improvements to the itertools docs (gh-125147) 2024-10-08 14:02:58 -05:00
spacemanspiff2007 760b1e103a
gh-124832: Add a note to indicate that `datetime.now` may return the same instant (#124834)
* Update datetime.rst

* Update datetime.rst

replace warning with note

* Update Doc/library/datetime.rst

Co-authored-by: Victor Stinner <vstinner@python.org>

* Update Doc/library/datetime.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

---------

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-08 11:17:53 -07:00
Michael Droettboom c6127af868
gh-125063: Emit slices as constants in the bytecode compiler (#125064)
* Make slices marshallable

* Emit slices as constants

* Update Python/marshal.c

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>

* Refactor codegen_slice into two functions so it
always has the same net effect

* Fix for free-threaded builds

* Simplify marshal loading of slices

* Only return SUCCESS/ERROR from codegen_slice

---------

Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-10-08 13:18:39 -04:00
Cody Maloney 7dca7322cc
gh-125084: Resolve paths in generator common code (GH-125085)
In out of tree builds, the paths can contain `../ which needs to be
resolved for the relative path calculation to work.
2024-10-08 12:16:02 -05:00
Kumar Aditya fca552993d
gh-117721: use PyMutex in `_thread.lock` (#125110) 2024-10-08 20:17:32 +05:30
Victor Stinner c203955f3b
gh-124502: Optimize unicode_eq() (#125105) 2024-10-08 16:25:24 +02:00
mpage e99f159be4
gh-115999: Stop the world when invalidating function versions (#124997)
Stop the world when invalidating function versions

The tier1 interpreter specializes `CALL` instructions based on the values
of certain function attributes (e.g. `__code__`, `__defaults__`). The tier1
interpreter uses function versions to verify that the attributes of a function
during execution of a specialization match those seen during specialization.
A function's version is initialized in `MAKE_FUNCTION` and is invalidated when
any of the critical function attributes are changed. The tier1 interpreter stores
the function version in the inline cache during specialization. A guard is used by
the specialized instruction to verify that the version of the function on the operand
stack matches the cached version (and therefore has all of the expected attributes).
It is assumed that once the guard passes, all attributes will remain unchanged
while executing the rest of the specialized instruction.

Stopping the world when invalidating function versions ensures that all critical
function attributes will remain unchanged after the function version guard passes
in free-threaded builds. It's important to note that this is only true if the remainder
of the specialized instruction does not enter and exit a stop-the-world point.

We will stop the world the first time any of the following function attributes
are mutated:

- defaults
- vectorcall
- kwdefaults
- closure
- code

This should happen rarely and only happens once per function, so the performance
impact on majority of code should be minimal.

Additionally, refactor the API for manipulating function versions to more clearly
match the stated semantics.
2024-10-08 10:04:35 -04:00
Victor Stinner 65ce228d63
gh-125096: Don't import _pyrepl in site if PYTHON_BASIC_REPL (#125097)
If the PYTHON_BASIC_REPL environment variable is set, the site module
no longer imports the _pyrepl module.

Moreover, the site module now respects -E and -I command line
options: ignore PYTHON_BASIC_REPL in this case.
2024-10-08 15:48:40 +02:00
monkeyman192 5967dd8a4d
gh-112433 add versionadded for `ctypes.Structure._align_` (#125087)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-10-08 12:41:46 +00:00
Kirill Podoprigora e8773e59a8
Doc: Improve description of ``GET_LEN`` opcode (#114583) 2024-10-08 17:55:40 +05:30
Mikhail Efimov 9a35d05338
gh-121404: typo fix in compile.c: MATADATA -> METADATA (#125101) 2024-10-08 12:18:28 +00:00
Jan Kaliszewski 9047146e54
gh-75898: make use of thread more explicit in the "Socket Programming HOWTO" document (#125023) 2024-10-08 17:43:37 +05:30
Cody Maloney 43ad3b5170
gh-90102: Fix pyio _isatty_open_only() (#125089)
Spotted by @ngnpope.

`isatty` returns False to indicate the file is not a TTY. The C
implementation of _io does that (`Py_RETURN_FALSE`) but I got the
bool backwards in the _pyio implementaiton.
2024-10-08 11:49:50 +00:00
Bénédikt Tran e4292c0410
gh-123961: Convert _curses to a multi-phase init module (PEP-489) (#124965) 2024-10-08 13:42:44 +02:00
Bénédikt Tran ba14dfafd9
gh-123378: fix a crash in `UnicodeError.__str__` (#124935) 2024-10-08 13:37:59 +02:00
Serhiy Storchaka 19984fe024
gh-53203: Improve tests for strptime() (GH-125090)
Run them with different locales and different date and time.

Add the @run_with_locales() decorator to run the test with multiple
locales.

Improve the run_with_locale() context manager/decorator -- it now
catches only expected exceptions and reports the test as skipped if no
appropriate locale is available.
2024-10-08 08:40:02 +00:00
Alyssa Coghlan 7c4b6a68f2
bpo-34206: Improve docs and test coverage for pre-init functions (#8023)
- move the Py_Main documentation from the very high level API section
  to the initialization and finalization section
- make it clear that it encapsulates a full Py_Initialize/Finalize
  cycle of its own
- point out that exactly which settings will be read and applied
  correctly when Py_Main is called after a separate runtime
  initialization call is version dependent
- be explicit that Py_IsInitialized can be called prior to
  initialization
- actually test that Py_IsInitialized can be called prior to
  initialization
- flush stdout in the embedding tests that run code so it appears
  in the expected order when running with "-vv"
- make "-vv" on the subinterpreter embedding tests less spammy

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2024-10-08 08:34:11 +00:00
Serhiy Storchaka 93b9e6bd7d
gh-69998: Fix decoding error in locale.nl_langinfo() (GH-124963)
The function now sets temporarily the LC_CTYPE locale to the locale
of the category that determines the requested value if the locales are
different and the resulting string is non-ASCII.
This temporary change affects other threads.
2024-10-08 11:27:49 +03:00
Alyssa Coghlan 27390990fa
gh-70870: Clarify dual usage of 'free variable' (#122545)
The term "free variable" has unfortunately become genuinely
ambiguous over the years (presumably due to the names of
some relevant code object instance attributes).

While we can't eliminate that ambiguity at this late date, we can
at least alert people to the potential ambiguity by describing
both the formal meaning of the term and the common
alternative use as a direct synonym for "closure variable".

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2024-10-08 07:52:12 +00:00
Cody Maloney cc9b9bebb2
gh-90102: Remove isatty call during regular open (#124922)
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-10-08 08:50:42 +02:00
Ned Batchelder 6e3c70c61b
Docs: make a tutorial example more precise (#125066)
Based on discussion here:

https://discuss.python.org/t/omission-in-the-documentation/66816
2024-10-07 19:41:13 -04:00
Emily Morehouse 447a15190d
gh-125072: Add label for assignment expressions; update tracked section for assignment expression topic (#125074) 2024-10-07 22:51:14 +00:00
Victor Stinner a7f0727ca5
gh-124502: Add PyUnicode_Equal() function (#124504) 2024-10-07 21:24:53 +00:00
Zhikang Yan c5df1cb7bd
gh-122392: IDLE - Fix overlapping lines in browsers (#122392) (#124975)
Increase currently inadequate vertical spacing for the IDLE browsers (path,
module, and stack) on high-resolution monitors.
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2024-10-07 14:52:09 -04:00
Bénédikt Tran 7ffe94fb24
gh-124653: Relax (again) detection of queue API for logging handlers (GH-124897) 2024-10-07 19:42:19 +01:00
Victor Stinner 03775472cc
Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() (#125044)
These functions cannot fail.
2024-10-07 19:54:42 +02:00
ffelixg 3287c834e5
gh-124182: Explain naming rules for struct sequence types (#124335) 2024-10-07 19:52:34 +02:00
sobolevn 51d426dc03
gh-124956: Use `#undef` for temp macros in `_csv.c` (#124957) 2024-10-07 23:05:56 +05:30
Mark Shannon d1453f60c2
GH-121459: Streamline PyObject* to PyStackRef conversions by disallowing NULL pointers. (GH-124894) 2024-10-07 18:13:04 +01:00
Adam Turner 10094a533a
gh-125018: Fix role syntax (#125050) 2024-10-07 17:51:53 +01:00
Petr Viktorin 744caa8ef4
gh-120762: make_ssl_certs: Don't set extensions for the temporary CSR (GH-125045)
gh-120762: make_ssl_certs: Don't set extensions for the CSR

`openssl req` fails with openssl 3.2.2 because the config line

    authorityKeyIdentifier = keyid:always,issuer:always

is not supported for certificate signing requests (since the issuing
certificate authority is not known).

David von Oheimb, the OpenSSL dev that made the change, commented in:
https://github.com/openssl/openssl/issues/22966#issuecomment-1858396738 :

> This problem did not show up in older OpenSSL versions because of a bug:
> the `req` app ignored the `-extensions` option unless `-x505` is given,
> which I fixed in https://github.com/openssl/openssl/pull/16865.

(I assume `-x505` is a typo for `-x509`.)

In our `make_cert_key` function:

If `sign` is true:
- We don't pass `-x509` to `req`, so in this case it should be safe to
  omit the `-extensions` argument. (Old OpenSSL ignores it, new OpenSSL
  fails on it.)
- The extensions are passed to the `ca` call later in the function.
  There they take effect, and `authorityKeyIdentifier` is valid.

If `sign` is false, this commit has no effect except rearranging the
CLI arguments.
2024-10-07 17:37:52 +02:00
Mark Shannon da071fa3e8
GH-119866: Spill the stack around escaping calls. (GH-124392)
* Spill the evaluation around escaping calls in the generated interpreter and JIT. 

* The code generator tracks live, cached values so they can be saved to memory when needed.

* Spills the stack pointer around escaping calls, so that the exact stack is visible to the cycle GC.
2024-10-07 14:56:39 +01:00
Alyssa Coghlan cda3b5a576
gh-125018: Add importlib.metadata semantic link targets (#125027)
This allows direct intersphinx references to APIs via references
like `` :func:`importlib.metadata.version` ``.

---------

Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-10-07 23:44:18 +10:00
Victor Stinner d8f707420b
gh-111178: Fix function signatures in fileio.c (#125043)
* Add "fileio_" prefix to getter functions.
* Small refactoring.
2024-10-07 15:27:36 +02:00
Sergey B Kirpichev 7487db4c7a
gh-121249: Support _Complex types in the struct module (#121613)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-10-07 13:53:02 +02:00
Mark Shannon f55273b3b7
GH-116968: Remove branch from advance_backoff_counter (GH-124469) 2024-10-07 11:46:33 +01:00
Adam Turner 31516c98dd
GH-109975: Announce final release in What's New in Python 3.13 (#125007)
Prepare What's New in Python 3.13 for final release
2024-10-06 21:43:03 -07:00
Jan Kaliszewski 1e098dc766
gh-125025: `_thread` docs: fix/update the *caveats* list (GH-125026) 2024-10-06 15:57:03 -07:00
Andrés Delfino feca4cf64e
Doc: Simplify the definition of 'soft deprecated' (#124988)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2024-10-06 22:22:19 +00:00
Tomas R. a1be83dae3
gh-125010: Fix `use-after-free` in AST `repr()` (#125015) 2024-10-06 12:46:03 -07:00
Shantanu 3fc673e97d
gh-119535: python𝜋 (#119536)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2024-10-06 21:47:13 +03:00
Tomas R. db23b8bb13
gh-125008: Fix `tokenize.untokenize` roundtrip for `\n{{` (#125013) 2024-10-06 15:16:41 +02:00
Rigel Di Scala 39c859f6ff
gh-122951: Simplify the grammar of the assignment rule (#124998) 2024-10-06 11:55:56 +02:00
Victor Stinner 16cd6cc86b
gh-111178: Fix function signatures in genobject.c (#124970)
* Add "CAST" macros.
* Rename parameters/variables "o" to "ag", "ags", "agw" or "agt"
  in some functions.
2024-10-05 09:56:44 +02:00
Donghee Na a5fc50994a
gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)
* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit
2024-10-05 11:27:32 +09:00
Tian Gao adfe7657a3
gh-124552 : Improve the accuracy of possible breakpoint check in bdb (#124553) 2024-10-04 21:32:57 -04:00
Adam Turner 2d8b6a4e9d
gh-119786: Replace a Sphinx role with a link to `Python/errors.c` (#124990) 2024-10-05 01:00:19 +01:00
morotti 6efd95c465
gh-117151: increase default buffer size of shutil.copyfileobj() to 256k. (GH-119783)
* gh-117151: increase default buffer size of shutil.copyfileobj() to 256k.

it was set to 16k in the 1990s.
it was raised to 64k in 2019. the discussion at the time mentioned another 5% improvement by raising to 128k and settled for a very conservative setting.

it's 2024 now, I think it should be revisited to match modern hardware. I am measuring 0-15% performance improvement when raising to 256k on various types of disk. there is no downside as far as I can tell.

this function is only intended for sequential copy of full files (or file like objects). it's the typical use case that benefits from larger operations.

for reference, I came across this function while trying to profile pip that is using it to copy files when installing python packages.

* add news

---------

Co-authored-by: rmorotti <romain.morotti@man.com>
2024-10-04 16:51:22 -07:00
Irit Katriel 8bcf118dcb
gh-119786: move a few more details on exception handling from devguide to InternalDocs (#124989) 2024-10-05 00:48:12 +01:00
Irit Katriel f474391b26
gh-124871: fix 'visited' tracking in compiler's reachability analysis (#124952) 2024-10-04 17:37:38 +01:00