Commit Graph

28857 Commits

Author SHA1 Message Date
Sergey B Kirpichev 987311d42e
gh-69639: Add mixed-mode rules for complex arithmetic (C-like) (GH-124829)
"Generally, mixed-mode arithmetic combining real and complex variables should
be performed directly, not by first coercing the real to complex, lest the sign
of zero be rendered uninformative; the same goes for combinations of pure
imaginary quantities with complex variables." (c) Kahan, W: Branch cuts for
complex elementary functions.

This patch implements mixed-mode arithmetic rules, combining real and
complex variables as specified by C standards since C99 (in particular,
there is no special version for the true division with real lhs
operand).  Most C compilers implementing C99+ Annex G have only these
special rules (without support for imaginary type, which is going to be
deprecated in C2y).
2024-11-26 17:57:39 +02:00
Jelle Zijlstra dcf629213b
gh-119180: Add VALUE_WITH_FAKE_GLOBALS format to annotationlib (#124415) 2024-11-26 15:40:13 +00:00
Filipe Laíns 🇵🇸 2b0e2b2893
GH-126985: move pyvenv.cfg detection from site to getpath (#126987) 2024-11-26 13:46:33 +00:00
Richard Hansen ab237ff81d
Doc: Typo fix: nrace -> race (#127288) 2024-11-26 15:05:07 +02:00
Yuki Kobayashi 733fe59206
gh-101100: Fix sphinx warnings in `howto/*` (#127084) 2024-11-26 10:17:54 +02:00
funkyrailroad 26ff32b305
gh-127265: Remove single quotes from 'arrow's in tutorial/errors.rst (GH-127267) 2024-11-25 15:34:01 -06:00
Barney Gale 5bb059fe60
GH-127236: `pathname2url()`: generate RFC 1738 URL for absolute POSIX path (#127194)
When handed an absolute Windows path such as `C:\foo` or `//server/share`,
the `urllib.request.pathname2url()` function returns a URL with an
authority section, such as `///C:/foo` or `//server/share` (or before
GH-126205, `////server/share`). Only the `file:` prefix is omitted.

But when handed an absolute POSIX path such as `/etc/hosts`, or a Windows
path of the same form (rooted but lacking a drive), the function returns a
URL without an authority section, such as `/etc/hosts`.

This patch corrects the discrepancy by adding a `//` prefix before
drive-less, rooted paths when generating URLs.
2024-11-25 19:59:20 +00:00
Victor Stinner d9331f1b16
gh-107954: Document PEP 741 in What's New 3.14 (#127056) 2024-11-25 15:24:33 +01:00
Jun Komoda f4f075b3d5
Replace `:platform:` with `.. availability::` in `socket.ioctl` doc. (GH-127122)
In `socket.ioctl`, `:platform:` -> `.. availability::`
2024-11-25 13:53:17 +01:00
Barney Gale 307c633586
Improve `pathname2url()` and `url2pathname()` docs (#127125)
These functions have long sown confusion among Python developers. The
existing documentation says they deal with URL path components, but that
doesn't fit the evidence on Windows:

    >>> pathname2url(r'C:\foo')
    '///C:/foo'
    >>> pathname2url(r'\\server\share')
    '////server/share'  # or '//server/share' as of quite recently

If these were URL path components, they would imply complete URLs like
`file://///C:/foo` and `file://////server/share`. Clearly this isn't right.
Yet the implementation in `nturl2path` is deliberate, and the 
`url2pathname()` function correctly inverts it.

On non-Windows platforms, the behaviour until quite recently is to simply
quote/unquote the path without adding or removing any leading slashes. This
behaviour is compatible with *both* interpretations -- 1) the value is a
URL path component (existing docs), and 2) the value is everything
following `file:` (this commit)

The conclusion I draw is that these functions operate on everything after
the `file:` prefix, which may include an authority section. This is the
only explanation that fits both the  Windows and non-Windows behaviour.
It's also a better match for the function names.
2024-11-24 17:33:46 +00:00
da-woods 2bb7846cac
Fix macro expansions in critical section docs (#127226) 2024-11-24 12:21:02 -05:00
Yuki Kobayashi 3d8ac48aed
gh-101100: Fix sphinx warnings of removed opcodes (#127222) 2024-11-24 17:43:25 +02:00
Savannah Ostrowski 2104bde572
GH-127133: Remove ability to nest argument groups & mutually exclusive groups (#127186) 2024-11-24 15:20:37 +00:00
Richard Hansen e3038e976b
Doc: C API: Fix `Py_NewInterpreterFromConfig` example code (#126667) 2024-11-23 21:47:08 +02:00
Barney Gale cc813e10ff
GH-125866: Preserve Windows drive letter case in file URIs (#127138)
Stop converting Windows drive letters to uppercase in
`urllib.request.pathname2url()` and `url2pathname()`. This behaviour is
unnecessary and inconsistent with pathlib's file URI implementation.
2024-11-23 10:41:39 +00:00
Savannah Ostrowski a13e94d84b
GH-127134: Add note about forward compatibility for suggest_on_error (#127137) 2024-11-22 19:18:18 -08:00
Rafael Fontenelle 39e60aeb38
Fix a few typos found in the docs (GH-127126) 2024-11-22 16:02:51 -08:00
Serhiy Storchaka a5440d4a38
gh-86463: Fix a trailing space in argparse.rst (#127162) 2024-11-22 16:34:05 +00:00
Serhiy Storchaka 8899e85de1
gh-127001: Fix PATHEXT issues in shutil.which() on Windows (GH-127035)
* Name without a PATHEXT extension is only searched if the mode does not
  include X_OK.
* Support multi-component PATHEXT extensions (e.g. ".foo.bar").
* Support files without extensions in PATHEXT contains dot-only extension
  (".", "..", etc).
* Support PATHEXT extensions that end with a dot (e.g. ".foo.").
2024-11-22 17:52:15 +02:00
Serhiy Storchaka 0cb4d6c654
gh-86463: Fix default prog in subparsers if usage is used in the main parser (GH-125891)
The usage parameter of argparse.ArgumentParser no longer
affects the default value of the prog parameter in subparsers.

Previously the full custom usage of the main parser was used as
the prog prefix in subparsers.
2024-11-22 17:29:33 +02:00
Jun Komoda 3c770e3f09
gh-127082: Replace "Windows only" with the `availability: Windows` in `ctypes` doc (#127099) 2024-11-22 08:56:34 +01:00
Savannah Ostrowski fcfdb55465
GH-122679: Add `register()` to argparse docs (#126939)
* Add register() to argparse docs

* Add newline

* Formatting

* Fix codeblock

* Move section

* Add signature

* Add newline

* Fix indent

* Fix indent take 2

* Rephrase

* Simplify language

* Address PR comments

* Add references to register in type and action

* Remove unnecessary reference

* Rephrase and add success case
2024-11-21 16:36:11 -08:00
Barney Gale fd133d4f21
GH-126601: `pathname2url()`: handle NTFS alternate data streams (#126760)
Adjust `pathname2url()` to encode embedded colon characters in Windows
paths, rather than bailing out with an `OSError`.

Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2024-11-22 00:29:05 +00:00
Serhiy Storchaka 4803cd0244
gh-126727: Fix locale.nl_langinfo(locale.ERA) (GH-126730)
It now returns multiple era description segments separated by semicolons.
Previously it only returned the first segment on platforms with Glibc.
2024-11-21 13:16:08 +02:00
Mark Shannon aea0c586d1
GH-127010: Don't lazily track and untrack dicts (GH-127027) 2024-11-20 16:41:20 +00:00
Gregory P. Smith 7191b7662e
gh-97514: Authenticate the forkserver control socket. (GH-99309)
This adds authentication to the forkserver control socket. In the past only filesystem permissions protected this socket from code injection into the forkserver process by limiting access to the same UID, which didn't exist when Linux abstract namespace sockets were used (see issue) meaning that any process in the same system network namespace could inject code. We've since stopped using abstract namespace sockets by default, but protecting our control sockets regardless of type is a good idea.

This reuses the HMAC based shared key auth already used by `multiprocessing.connection` sockets for other purposes.

Doing this is useful so that filesystem permissions are not relied upon and trust isn't implied by default between all processes running as the same UID with access to the unix socket.

### pyperformance benchmarks

No significant changes. Including `concurrent_imap` which exercises `multiprocessing.Pool.imap` in that suite.

### Microbenchmarks

This does _slightly_ slow down forkserver use. How much so appears to depend on the platform. Modern platforms and simple platforms are less impacted. This PR adds additional IPC round trips to the control socket to tell forkserver to spawn a new process. Systems with potentially high latency IPC are naturally impacted more.

Typically a 1-4% slowdown on a very targeted process creation microbenchmark, with a worst case overloaded system slowdown of 20%.  No evidence that these slowdowns appear in practical sense.  See the PR for details.
2024-11-20 08:18:58 -08:00
Jun Komoda 5b4502560b
gh-126615: `ctypes`: Make `COMError` public (GH-126686)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-11-20 12:53:43 +00:00
Barney Gale 9d2a879aff
GH-84850: Improve whatsnew entry for `[Fancy]URLopener` removal (#127032) 2024-11-20 13:14:07 +02:00
Hugo van Kemenade 3746d0a7b3
gh-123299: Copyedit "What's New in Python 3.14" (#127028) 2024-11-20 11:35:24 +02:00
Richard Hansen 9bca3ef575
Doc: C API: `PyThreadState::on_delete` was removed in v3.13 (#126536) 2024-11-20 09:44:45 +01:00
Hugo van Kemenade 2cdfb41d0c Merge remote-tracking branch 'upstream/main' 2024-11-19 22:10:24 +02:00
Hugo van Kemenade 5fcc3a4cee
Update docs 'make serve' to suggest 'make htmllive' (#126969) 2024-11-19 17:28:34 +02:00
Hugo van Kemenade add43c3420 Python 3.14.0a2 2024-11-19 16:52:44 +02:00
Barney Gale 4d771977b1
GH-84850: Remove `urllib.request.URLopener` and `FancyURLopener` (#125739) 2024-11-19 16:01:49 +02:00
Hugo van Kemenade 933f21c3c9
gh-85957: Add missing MIME types for images with RFCs (#126966) 2024-11-18 20:13:20 +02:00
Serhiy Storchaka f7ef0203d4
gh-123803: Support arbitrary code page encodings on Windows (GH-123804)
If the cpXXX encoding is not directly implemented in Python, fall back
to use the Windows-specific API codecs.code_page_encode() and
codecs.code_page_decode().
2024-11-18 17:45:25 +00:00
Joseph Martinot-Lagarde ce453e6c2f
Doc: Reorganize math module documentation (#126337)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-11-18 08:57:32 +01:00
beavailable 0c5c80928c
gh-126896: Fix docs about `asyncio.start_server()` (#126897) 2024-11-17 11:32:35 -08:00
Hood Chatham 2313f84210
GH-126748: amend configure.rst description for the 'build_wasm' make target (#126687)
Clarified the documentation around how the build_wasm target is selected.
2024-11-16 09:46:39 +08:00
Hood Chatham 544b001b23
gh-126691: Remove --with-emscripten-target (#126787)
This unifies the code for nodejs and the code for the browser. After this
commit, the browser example doesn't work; this will be fixed in a
subsequent update.
2024-11-16 09:44:05 +08:00
Alex Gaynor d6bcc154e9
Added a warning to the urljoin docs, indicating that it is not safe to use with attacker controlled URLs (GH-126659)
This was flagged to me at a party today by someone who works in red-teaming as a frequently encountered footgun. Documenting the potentially unexpected behavior seemed like a good place to start.
2024-11-15 18:09:05 -05:00
Beomsoo Kim 94a7a4e22f
Docs: Miscellaneous corrections to simple statements in the language reference (GH-126720)
* Replace: The :keyword:`global` -> The :keyword:`global` statement
Add :keyword: when it's needed

* Replace repeated links with duoble backticks
2024-11-15 13:02:34 -08:00
Seth Michael Larson a2c180f4e7
Add PEP 761 to What's New (#126550)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-11-15 15:54:56 +00:00
Bénédikt Tran 612ac283b8
gh-122549: Add platform.invalidate_caches() (#122547)
Allow to invalidate platform's cached results.
2024-11-15 13:52:56 +00:00
Petr Viktorin d00f7b1b9d
gh-125063: marshal: Add version 5, improve documentation (GH-126829)
* Document that slices can be marshalled
* Deduplicate and organize the list of supported types
  in docs
* Organize the type code list in marshal.c, to make
  it more obvious that this is a versioned format
* Back-fill some historical info

Co-authored-by: Michael Droettboom <mdboom@gmail.com>
2024-11-15 13:48:57 +01:00
Bénédikt Tran e17486982c
gh-89083: small docs fixup for UUIDv8 (#126857) 2024-11-15 14:26:38 +02:00
RUANG (James Roy) 1e3497e745
gh-126061: add new functions to `refcounts.dat` (#126788) 2024-11-14 15:04:38 +01:00
Petr Viktorin ff0ef0a54b
gh-123832: Adjust `socket.getaddrinfo` docs for better POSIX compliance (GH-126182)
* gh-123832: Adjust `socket.getaddrinfo` docs for better POSIX compliance

This changes nothing changes for CPython supported platforms,
but hints how to deal with platforms that stick to the letter of
the spec.
It also marks `socket.getaddrinfo` as a wrapper around `getaddrinfo(3)`;
specifically, workarounds to make the function work consistently across
platforms are out of scope in its code.

Include wording similar to the POSIX's “by providing options and by
limiting the returned information”, which IMO suggests that the
hints limit the resulting list compared to the defaults, *but* can
be interpreted differently. Details are added in a note.

Specifically say that this wraps the underlying C function. So, the
details are in OS docs. The “full range of results” bit goes away.

Use `AF_UNSPEC` rather than zero for the *family* default, although
I don't think a system where it's nonzero would be very usable.

Suggest setting proto and/or type (with examples, as the appropriate
values aren't obvious). Say why you probably want to do that that
on all systems; mention the behavior on the “letter of the spec”
systems.

Suggest that the results should be tried in order, which is,
AFAIK best practice -- see RFC 6724 section 2, and its predecessor
from 2003 (which are specific to IP, but indicate how people use this):

> Well-behaved applications SHOULD iterate through the list of
> addresses returned from `getaddrinfo()` until they find a working address.


Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2024-11-14 09:31:14 +01:00
John Marshall e0692f1165
Document that return-less user-defined functions return None (#126769)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2024-11-14 07:47:24 +00:00
Colin Watson 73e34b6808
Doc: Recommend shlex.quote alongside pipes removal (#126570)
One of the most common reasons I see the old `pipes` module still in use
when porting to Python 3.13 is for the undocumented `pipes.quote`
function, which can easily be replaced with `shlex.quote`.  I think it's
worth specifically calling this out, since being directed to the
`subprocess` module would be confusing in this case.
2024-11-14 05:01:35 +00:00