Commit Graph

29582 Commits

Author SHA1 Message Date
Alex Waygood 6d59c9e32e
gh-102433: Use `inspect.getattr_static` in `typing._ProtocolMeta.__instancecheck__` (#103034) 2023-04-02 14:22:19 +01:00
Ethan Furman 2a4d8c0a9e
gh-102549: [Enum] fail enum creation when data type raises in __init__ (GH-103149) 2023-03-31 13:52:31 -07:00
Eric Snow dfc4c95762
gh-101659: Clean Up the General Import Tests for Subinterpreters (gh-103151)
This involves 3 changes: some general cleanup, checks to match the kind of module, and switch from testing against sys to _imp.

This is a precursor to gh-103150, though the changes are meant to stand on their own.
2023-03-31 12:18:33 -06:00
James De Bias b0422e140d
gh-102871: Remove obsolete browsers from webbrowser (#102872) 2023-03-31 11:02:47 -04:00
Irit Katriel 44bd3fe570
gh-102799: use exception instance instead of sys.exc_info() (#102885) 2023-03-31 11:23:02 +01:00
Brandt Bucher 121057aa36
GH-89987: Shrink the BINARY_SUBSCR caches (GH-103022) 2023-03-29 15:53:30 -07:00
gaogaotiantian e375bff037
gh-103068: Check condition expression of breakpoints for pdb (#103069)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Artem Mukhin <ortem00@gmail.com>
2023-03-29 12:09:12 +02:00
Nikita Sobolev 60bdc16b45
gh-103054: typing: Improve `Callable` type substitution tests (#103055)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Eclips4 <80244920+Eclips4@users.noreply.github.com>
2023-03-28 20:04:26 -07:00
Ethan Furman f4ed2c6ae5
gh-102558: [Enum] better handling of non-Enum EnumType classes (GH-103060) 2023-03-27 16:26:16 -07:00
Ethan Furman b838d80085
gh-103056: [Enum] ensure final _generate_next_value_ is a staticmethod (GH-103062) 2023-03-27 16:25:19 -07:00
Oleg Iarygin 56d055a0d8
gh-74468: [tarfile] Fix incorrect name attribute of ExFileObject (GH-102424)
Co-authored-by: Simeon Visser <svisser@users.noreply.github.com>
2023-03-27 16:21:07 -07:00
gaogaotiantian 34eb6f7276
gh-103046: Display current line correctly for `dis.disco()` with CACHE entries (#103047) 2023-03-27 23:22:06 +01:00
gaogaotiantian 3606753246
gh-103023: Add SyntaxError check in pdb's `display` command (#103024)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2023-03-27 22:37:22 +02:00
Shantanu 718e86671f
gh-98886: Fix issues with dataclass fields with special underscore names (#102032)
This commit prefixes `__dataclass` to several things in the locals dict:
- Names like `_dflt_` (which cause trouble, see first test)
- Names like `_type_` (not known to be able to cause trouble)
- `_return_type` (not known to able to cause trouble)
- `_HAS_DEFAULT_FACTORY` (which causes trouble, see second test)

In addition, this removes `MISSING` from the locals dict. As far as I can tell, this wasn't needed even in the initial implementation of dataclasses.py (and tests on that version passed with it removed). This makes me wary :-)

This is basically a continuation of #96151, where fixing this was welcomed in https://github.com/python/cpython/pull/98143#issuecomment-1280306360
2023-03-25 14:40:11 -07:00
JakobDev 64cb1a4f0f
gh-100131: Add optional delete parameter to tempfile.TemporaryDirectory() (#100132)
Add optional delete parameter to tempfile.TemporaryDirectory().

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-03-24 14:52:06 -07:00
gaogaotiantian ded9a7fc19
gh-102980: Add tests for pdf's display, alias and where commands (#102981) 2023-03-24 20:50:06 +00:00
David Benjamin acfe02f3b0
gh-100372: Use BIO_eof to detect EOF for SSL_FILETYPE_ASN1 (GH-100373)
In PEM, we need to parse until error and then suppress `PEM_R_NO_START_LINE`, because PEM allows arbitrary leading and trailing data. DER, however, does not. Parsing until error and suppressing `ASN1_R_HEADER_TOO_LONG` doesn't quite work because that error also covers some cases that should be rejected.

Instead, check `BIO_eof` early and stop the loop that way.

Automerge-Triggered-By: GH:Yhg1s
2023-03-24 06:04:30 -07:00
MonadChains 413b7db8a4
gh-94684: uuid: support bytes in the name argument to uuid3/5 (#94709)
RFC 4122 does not specify that name should be a string, so for completness the functions should also support a name given as a raw byte sequence.
2023-03-23 17:42:43 -06:00
Brandt Bucher 0444ae2487
GH-100982: Break up COMPARE_AND_BRANCH (GH-102801) 2023-03-23 15:25:09 -07:00
Dong-hee Na bd063756b3
gh-102558: [Enum] fix AttributeError during member repr() (GH-102601) 2023-03-23 13:30:18 -07:00
AN Long bf42eb8722
gh-102943: Stop checking localized error text in socket tests on Windows (GH-102944) 2023-03-23 16:34:48 +00:00
Nikita Sobolev adb0621652
gh-88965: typing: fix type substitution of a list of types after initial `ParamSpec` substitution (#102808)
Previously, this used to fail:

```py
from typing import *
T = TypeVar("T")
P = ParamSpec("P")

class X(Generic[P]):
    f: Callable[P, int]

Y = X[[int, T]]
Z = Y[str]
```

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-23 16:26:11 +00:00
Alex Waygood baf4eb083c
gh-102947: Improve traceback when calling `fields()` on a non-dataclass (#102948) 2023-03-23 14:17:54 +00:00
Irit Katriel 3468c768ce
gh-102859: Remove JUMP_IF_FALSE_OR_POP and JUMP_IF_TRUE_OR_POP (#102870) 2023-03-22 18:10:48 +00:00
Kristján Valur Jónsson 04adf2df39
gh-102780: Fix uncancel() call in asyncio timeouts (#102815)
Also use `raise TimeOut from <CancelledError instance>` so that the CancelledError is set
in the `__cause__` field rather than in the `__context__` field.

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-22 10:52:10 -07:00
Stanislav Zmiev 713df2c534
GH-89727: Fix pathlib.Path.walk RecursionError on deep trees (GH-100282)
Use a stack to implement `pathlib.Path.walk()` iteratively instead of recursively to avoid hitting recursion limits on deeply nested trees.

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Brett Cannon <brett@python.org>
2023-03-22 14:45:25 +00:00
Benjamin Fogle af9c34f6ef
gh-96931: Fix incorrect results in ssl.SSLSocket.shared_ciphers (#96932) 2023-03-22 15:08:41 +01:00
Erlend E. Aasland 61405da9a5
gh-101947: Remove size check from sqlite3 serialize test (#102914)
The size of the returned data is too implementation specific.
2023-03-22 14:05:08 +01:00
David Benjamin 420bbb783b
GH-95494: Fix transport EOF handling in OpenSSL 3.0 (GH-95495)
GH-25309 enabled SSL_OP_IGNORE_UNEXPECTED_EOF by default, with a comment
that it restores OpenSSL 1.1.1 behavior, but this wasn't quite right.
That option causes OpenSSL to treat transport EOF as the same as
close_notify (i.e. SSL_ERROR_ZERO_RETURN), whereas Python actually has
distinct SSLEOFError and SSLZeroReturnError exceptions. (The latter is
usually mapped to a zero return from read.) In OpenSSL 1.1.1, the ssl
module would raise them for transport EOF and close_notify,
respectively. In OpenSSL 3.0, both act like close_notify.

Fix this by, instead, just detecting SSL_R_UNEXPECTED_EOF_WHILE_READING
and mapping that to the other exception type.

There doesn't seem to have been any unit test of this error, so fill in
the missing one. This had to be done with the BIO path because it's
actually slightly tricky to simulate a transport EOF with Python's fd
based APIs. (If you instruct the server to close the socket, it gets
confused, probably because the server's SSL object is still referencing
the now dead fd?)
2023-03-22 13:16:26 +01:00
Irit Katriel 76350e85eb
gh-102406: replace exception chaining by PEP-678 notes in codecs (#102407) 2023-03-21 21:36:31 +00:00
wim glenn 4bb1dd3c5c
gh-102876: remove superfluous parens from itertools.batched recipe (GH-102877)
remove superfluous parens from itertools.batched recipe
2023-03-21 12:06:18 -05:00
Irit Katriel 7f760c2fca
gh-102828: emit deprecation warning for onerror arg to shutil.rmtree (#102850) 2023-03-21 11:08:46 +00:00
Irit Katriel 5c471f3f2a
gh-102755: PyErr_DisplayException only in ABI >= 3.12. Tests cover PyErr_Display as well (GH-102849) 2023-03-21 10:36:18 +01:00
Alan Williams 5e6661bce9
gh-72346: Added isdst deprecation warning to email.utils.localtime (GH-91450) 2023-03-19 19:20:20 -05:00
Irit Katriel 40d4f15793
gh-102828: fix test failure (add missing skip instructions) (#102835) 2023-03-20 00:03:55 +00:00
Pieter Eendebak 382ee2f0f2
gh-102491: Remove IronPython version check in sys_version (#102492) 2023-03-19 15:52:47 -07:00
Irit Katriel d51a6dc28e
gh-102828: add onexc arg to shutil.rmtree. Deprecate onerror. (#102829) 2023-03-19 18:33:51 +00:00
Irit Katriel e1e9bab006
gh-102778: Add sys.last_exc, deprecate sys.last_type, sys.last_value,sys.last_traceback (#102779) 2023-03-18 11:47:11 +00:00
Irit Katriel b3cc11a08e
gh-102799: remove unnecessary calls to sys.exc_info() in tests (#102800) 2023-03-18 07:19:38 +00:00
Inada Naoki 65fb7c4055
gh-102701: Fix overflow in dictobject.c (GH-102750) 2023-03-17 22:39:09 +09:00
Kumar Aditya 4f5774f648
GH-78530: add support for generators in `asyncio.wait` (#102761) 2023-03-17 06:58:43 +05:30
Irit Katriel 3f9285a8c5
gh-102755: Add PyErr_DisplayException(exc) (#102756) 2023-03-16 22:18:04 +00:00
Steve Dower 0f175766e2
gh-99726: Improves correctness of stat results for Windows, and uses faster API when available (GH-102149)
This deprecates `st_ctime` fields on Windows, with the intent to change them to contain the correct value in 3.14. For now, they should keep returning the creation time as they always have.
2023-03-16 17:27:21 +00:00
Kumar Aditya adaed17341
GH-102748: remove legacy support for generator based coroutines from `asyncio.iscoroutine` (#102749)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-16 20:28:10 +05:30
Nikita Sobolev fbe82fdd77
gh-102721: Improve coverage of `_collections_abc._CallableGenericAlias` (#102722)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-16 14:47:30 +00:00
Irit Katriel 51d693c584
gh-102594: PyErr_SetObject adds note to exception raised on normalization error (#102675) 2023-03-16 10:16:01 +00:00
yonatanp 2dc94634b5
gh-94440: Fix issue of ProcessPoolExecutor shutdown hanging (#94468)
Fix an issue of concurrent.futures ProcessPoolExecutor shutdown hanging.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-15 21:44:52 -07:00
Kumar Aditya a44553ea9f
GH-100112: avoid using iterable coroutines in asyncio internally (#100128) 2023-03-16 09:20:43 +05:30
Martin Breuss 00d1ef73d6
Fix typo in code comment (#102726) 2023-03-15 19:18:18 +00:00
Nikita Sobolev 2b5781d659
gh-102615: Use `list` instead of `tuple` in `repr` of paramspec (#102637)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-15 09:33:41 +00:00
Andre Hora 5e0865f22e
gh-101377: improving test_locale_calendar_formatweekday of calendar (#101378)
---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2023-03-14 22:36:31 -04:00
Steve Dower 5fce813d8e
gh-102519: Avoid failing tests due to inaccessible volumes (GH-102706) 2023-03-15 00:07:30 +00:00
JosephSBoyle a028778d4c
Rename redundant enum tests so that they run (#102535) 2023-03-14 15:16:45 -07:00
Dong-hee Na d77c48740f
gh-102674: Remove _specialization_stats from Lib/opcode.py (#102685)
It's not use except in a test, so move it there instead.
2023-03-14 13:20:14 -07:00
Eric Snow 1ff81c0cb6
gh-81057: Add a CI Check for New Unsupported C Global Variables (gh-102506)
This will keep us from adding new unsupported (i.e. non-const) C global variables, which would break interpreter isolation.

FYI, historically it is very uncommon for new global variables to get added. Furthermore, it is rare for new code to break the c-analyzer. So the check should almost always pass unnoticed.

Note that I've removed test_check_c_globals. A test wasn't a great fit conceptually and was super slow on debug builds. A CI check is a better fit.

This also resolves gh-100237.

https://github.com/python/cpython/issues/81057
2023-03-14 10:05:54 -06:00
Raymond Hettinger 457e4d1a51
GH-102670: Use sumprod() to simplify, speed up, and improve accuracy of statistics functions (GH-102649) 2023-03-13 20:06:43 -05:00
Nikita Sobolev d97757f793
gh-102069: Fix `__weakref__` descriptor generation for custom dataclasses (#102075) 2023-03-13 15:42:05 -06:00
T 71e37d9079
gh-98169 dataclasses.astuple support DefaultDict (#98170)
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
2023-03-13 14:46:35 -06:00
Irit Katriel 634cb61909
gh-87092: refactor assemble() to a number of separate functions, which do not need the compiler struct (#102562) 2023-03-13 15:59:20 +00:00
谭九鼎 9a8b66b58c
Fix broken link to MSDN (#102355) 2023-03-13 15:15:52 +02:00
gaogaotiantian 5d677c556f
GH-101673: Fix pdb bug where local variable changes are lost after longlist (#101674) 2023-03-12 23:09:55 +00:00
Nikita Sobolev bb396eece4
gh-101821: Test coverage for `ast.main` function (#101822) 2023-03-11 11:10:52 -08:00
Thomas Krennwallner 534660f168
gh-79940: skip `TestGetAsyncGenState` on wasm as it requires working sockets (GH-102605)
Skip `TestGetAsyncGenState` and restoring of the default event loop policy in `test_inspect` if platform lacks working socket support.

Fixes #11590

Automerge-Triggered-By: GH:kumaraditya303
2023-03-11 10:36:49 -08:00
Thomas Krennwallner ced13c96a4
gh-79940: add introspection API for asynchronous generators to `inspect` module (#11590) 2023-03-11 18:49:40 +05:30
Alex Waygood 5ffdaf748d
gh-102433: Add tests for how classes with properties interact with `isinstance()` checks on `typing.runtime_checkable` protocols (#102449)
Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-03-11 01:20:20 +00:00
Brandt Bucher 08b67fb34f
GH-90997: Shrink the LOAD_GLOBAL caches (#102569) 2023-03-10 17:01:16 -08:00
Nikita Sobolev b48be8fa18
gh-102103: add `module` argument to `dataclasses.make_dataclass` (#102104) 2023-03-10 17:26:46 -07:00
Xuehai Pan ee6f8413a9
gh-102578: Optimise setting and deleting mutable attributes on non-dataclass subclasses of frozen dataclasses (gh-102573) 2023-03-10 19:21:22 -05:00
Barney Gale 90f1d77717
GH-80486: Fix handling of NTFS alternate data streams in pathlib (GH-102454)
Co-authored-by: Maor Kleinberger <kmaork@gmail.com>
2023-03-10 17:29:04 +00:00
Paul Ganssle 64bde502cf
GH-102537: Handle check for PYTHONTZPATH failing in zoneinfo test (GH-102538)
It is possible but unlikely for the `python_tzpath_context` function to fail between the start of the `try` block and the point where `os.environ.get` succeeds, in which case `old_env` will be undefined. In this case, we want to take no action.

Practically speaking this will really only happen in an error condition anyway, so it doesn't really matter, but we should probably do it right anyway.
2023-03-10 07:29:37 -08:00
Steve Dower cb35882773
gh-102519: Add os.listdrives, os.listvolumes and os.listmounts on Windows (GH-102544) 2023-03-10 12:21:37 +00:00
David Hewitt 71cf7c3ddd
gh-102378: don't bother stripping `/` from __text_signature__ (#102379) 2023-03-09 15:06:20 -08:00
Max Bachmann c6858d1e7f
gh-102255: Improve build support for Windows API partitions (GH-102256)
Add `MS_WINDOWS_DESKTOP`, `MS_WINDOWS_APPS`, `MS_WINDOWS_SYSTEM` and `MS_WINDOWS_GAMES` preprocessor definitions to allow switching off functionality missing from particular API partitions ("partitions" are used in Windows to identify overlapping subsets of APIs).
CPython only officially supports `MS_WINDOWS_DESKTOP` and `MS_WINDOWS_SYSTEM` (APPS is included by normal desktop builds, but APPS without DESKTOP is not covered). Other configurations are a convenience for people building their own runtimes.
`MS_WINDOWS_GAMES` is for the Xbox subset of the Windows API, which is also available on client OS, but is restricted compared to `MS_WINDOWS_DESKTOP`. These restrictions may change over time, as they relate to the build headers rather than the OS support, and so we assume that Xbox builds will use the latest available version of the GDK.
2023-03-09 21:09:12 +00:00
Alex Waygood 401d7a7f00
gh-102515: Remove unused imports in the `Lib/` directory (#102516) 2023-03-08 11:45:38 +00:00
sblondon 7d801f245e
Remove or update bitbucket links (GH-101963)
Since Mercurial removal from bitbucket.org, some links are broken.
They are replaced by github.com or webarchive.org links if available. Otherwise, they are removed.

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2023-03-08 11:24:39 +01:00
Kumar Aditya 1a84cc007e
GH-102397: Fix segfault from race condition in signal handling (#102399)
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-03-08 13:29:39 +05:30
Carl Meyer 1e703a4733
gh-102381: don't call watcher callback with dead object (#102382)
Co-authored-by: T. Wouters <thomas@python.org>
2023-03-07 17:10:58 -07:00
Irit Katriel a33ca2ad1f
gh-102493: fix normalization in PyErr_SetObject (#102502)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-03-07 13:27:46 -08:00
Barney Gale 6716254e71
GH-101362: Optimise PurePath(PurePath(...)) (GH-101667)
The previous `_parse_args()` method pulled the `_parts` out of any supplied `PurePath` objects; these were subsequently joined in `_from_parts()` using `os.path.join()`. This is actually a slower form of joining than calling `fspath()` on the path object, because it doesn't take advantage of the fact that the contents of `_parts` is normalized!

This reduces the time taken to run `PurePath("foo", "bar")` by ~20%, and the time taken to run `PurePath(p, "cheese")`, where `p = PurePath("/foo", "bar", "baz")`, by ~40%.

Automerge-Triggered-By: GH:AlexWaygood
2023-03-05 15:50:21 -08:00
Alex Waygood 96e1022929
gh-102444: Fix minor bugs in `test_typing` highlighted by pyflakes (#102445) 2023-03-05 21:37:29 +00:00
Partha P. Mukherjee 32220543e2
GH-102341: Improve the test function for pow (#102342)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2023-03-05 12:31:26 -05:00
JosephSBoyle 7894bbe94b
Fix unused classes in a typing test (GH-102437)
As part of investigation issue https://github.com/python/cpython/issues/102433, I discovered what I believe to be an error where two classes `CI` and `DI` are not being used. The assertions beneath them act on `C` and `D`, duplicating existing assertions in this test.

Automerge-Triggered-By: GH:AlexWaygood
2023-03-05 07:07:44 -08:00
Yeojin Kim 9a478be1a4
gh-101979: argparse: fix a bug where parentheses in metavar argument of add_argument() were dropped (#102318) 2023-03-05 06:54:33 -08:00
Marta Gómez Macías 66aa78cbe6
gh-102356: Add thrashcan macros to filter object dealloc (#102426)
Add thrashcan macros to the deallocator of the filter objects to protect against deeply nested destruction of chains of nested filters.
2023-03-05 12:00:41 +01:00
Kumar Aditya a74cd3ba5d
GH-97546: fix flaky asyncio `test_wait_for_race_condition` test (#102421) 2023-03-05 12:15:22 +05:30
Jaysinh Shukla 81763341ed
gh-63301: Set exit code when tabnanny CLI exits on error (#7699)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-03-04 13:32:13 -08:00
Alexey Izbyshev c2bd55d26f
gh-102179: Fix `os.dup2` error reporting for negative fds (#102180) 2023-03-04 19:54:08 +05:30
Raj 705487c655
gh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (#101896)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2023-03-04 19:51:29 +05:30
Nikita Sobolev 12011dd8ba
gh-102324: Improve tests of `typing.override` (#102325)
Fixes #101564
2023-03-02 19:59:05 -08:00
Hyunkyun Moon 60597439ef
gh-95672: Update memory_watchdog to use test.support.get_pagesize (gh-102365) 2023-03-02 20:10:08 +09:00
Stefan Pochmann eaae563b68
gh-102088 Optimize iter_index itertools recipe (GH-102360) 2023-03-01 21:16:23 -06:00
Hyunkyun Moon 2f62a5da94
gh-95672 skip fcntl when pipesize is smaller than pagesize (gh-102163) 2023-03-01 23:56:19 +09:00
Irit Katriel 9f799ab020
gh-87092: Make jump target label equal to the offset of the target in the instructions sequence (#102093) 2023-02-28 11:29:32 +00:00
Petr Viktorin 6b2d7c0ddb
gh-101101: Unstable C API tier (PEP 689) (GH-101102) 2023-02-28 09:31:01 +01:00
Steven Troxler 0f89acf6cc
gh-101561: Add typing.override decorator (#101564)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-02-27 13:16:11 -08:00
Sergey B Kirpichev 4f3786b761
gh-101773: Optimize creation of Fractions in private methods (#101780)
This PR adds a private `Fraction._from_coprime_ints` classmethod for internal creations of `Fraction` objects, replacing the use of `_normalize=False` in the existing constructor. This speeds up creation of `Fraction` objects arising from calculations. The `_normalize` argument to the `Fraction` constructor has been removed.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2023-02-27 18:53:22 +00:00
Eric Snow bb0cf8fd60
gh-102251: Updates to test_imp Toward Fixing Some Refleaks (gh-102254)
This is related to fixing the refleaks introduced by commit 096d009.  I haven't been able to find the leak yet, but these changes are a consequence of that effort.  This includes some cleanup, some tweaks to the existing tests, and a bunch of new test cases.  The only change here that might have impact outside the tests in question is in imp.py, where I update imp.load_dynamic() to use spec_from_file_location() instead of creating a ModuleSpec directly.

Also note that I've updated the tests to only skip if we're checking for refleaks (regrtest's --huntrleaks), whereas in gh-101969 I had skipped the tests entirely.  The tests will be useful for some upcoming work and I'd rather the refleaks not hold that up.  (It isn't clear how quickly we'll be able to fix the leaking code, though it will certainly be done in the short term.)

https://github.com/python/cpython/issues/102251
2023-02-27 09:21:18 -07:00
Dennis Sweeney e3c3f9fec0
gh-102250: Fix double-decref in COMPARE_AND_BRANCH error case (GH-102287) 2023-02-27 10:46:40 +00:00
Eclips4 4197043637
gh-102252: Improve coverage of test_bool.py (#102253)
Add tests for conversion from bool to complex.
2023-02-25 15:50:24 -05:00
Jason R. Coombs a35fd38b57
gh-102209: Sync with zipp 3.15 moving complexity tests into dedicated module (#102232)
Sync with jaraco/zipp@757a4e1a.
2023-02-25 11:15:48 -05:00
SKO 56e93c8020
gh-95675: fix uid and gid at test_add_dir_getmember (gh-102207)
Co-authored-by: Seonkyo Ok <seonkyo.ok@linecorp.com>
2023-02-25 11:26:40 +09:00
Ionite 54dfa14c5a
gh-101765: Fix SystemError / segmentation fault in iter `__reduce__` when internal access of `builtins.__dict__` exhausts the iterator (#101769) 2023-02-24 15:02:04 -08:00
Jason R. Coombs 89b4c12053
gh-102209: Disable the timeout in test_implied_dirs_performance. (#102225)
Disable the timeout in test_implied_dirs_performance. Workaround for #102209 until I can work out a more robust test for linearity.
2023-02-24 17:58:10 -05:00
Eclips4 9f3ecd1aa3
gh-102158: Add tests for `softkwlist` (#102159)
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2023-02-23 21:28:24 -05:00
Jacob Bower 0c857865e4
Fix deadlock on shutdown if test_current_{exception,frames} fails (#102019)
* Don't deadlock on shutdown if test_current_{exception,frames} fails

These tests spawn a thread that waits on a threading.Event. If the test fails any of its assertions, the Event won't be signaled and the thread will wait indefinitely, causing a deadlock when threading._shutdown() tries to join all outstanding threads.

Co-authored-by: Brett Simmers <bsimmers@meta.com>

* Add a news entry

* Fix whitespace

---------

Co-authored-by: Brett Simmers <bsimmers@meta.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2023-02-23 14:57:06 -08:00
Erlend E. Aasland efc985a714
gh-93649: Split exception tests from _testcapimodule.c (GH-102173)
Automerge-Triggered-By: GH:erlend-aasland
2023-02-23 07:03:13 -08:00
Zackery Spytz 665730d217
bpo-23224: Fix segfaults and multiple leaks in the lzma and bz2 modules (GH-7822)
lzma.LZMADecompressor and bz2.BZ2Decompressor objects caused
segfaults when their `__init__()` methods were not called.

lzma.LZMADecompressor, lzma.LZMACompressor, bz2.BZ2Compressor,
and bz2.BZ2Decompressor objects would leak locks and internal buffers
when their `__init__()` methods were called multiple times.


https://bugs.python.org/issue23224
2023-02-23 06:00:58 -08:00
Mark Shannon 22b8d77b98
GH-100719: Remove redundant `gi_code` field from generator object. (GH-100749) 2023-02-23 10:19:01 +00:00
Carl Meyer 056dfc71dc
gh-87634: remove locking from functools.cached_property (GH-101890)
Remove the undocumented locking capabilities of functools.cached_property.
2023-02-22 17:49:22 -08:00
Sergey B Kirpichev 592f65fdb5
Few coverage nitpicks for the cmath module (#102067)
- partial tests for cosh/sinh overflows (L535 and L771).  I doubt
  both ||-ed conditions could be tested.
- removed inaccessible case in sqrt (L832): ax=ay=0 is handled
  above (L823) because fabs() is exact.  Also added test (checked
  with mpmath and gmpy2) for second condition on that line.
- some trivial tests for isclose (cover all conditions on L1217-1218)
- add comment for uncovered L1018

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2023-02-22 19:10:01 +00:00
Hyunkyun Moon d5c7954d0c
gh-95672 fix typo SkitTest to SkipTest (gh-102119)
Co-authored-by: HyunKyun Moon <hyunkyun.moon@linecorp.com>
2023-02-22 02:39:00 +09:00
Vo Hoang Long 0d4c7fcd4f
gh-101936: Update the default value of fp from io.StringIO to io.BytesIO (gh-102100)
Co-authored-by: Long Vo <long.vo@linecorp.com>
2023-02-22 00:14:41 +09:00
Irit Katriel c2b85a95a5
gh-102008: simplify test_except_star by using sys.exception() instead of sys.exc_info() (#102009) 2023-02-21 15:11:31 +00:00
Gihwan Kim 6f25657b83
gh-101961 fileinput.hookcompressed should not set the encoding value for the binary mode (gh-102068) 2023-02-21 12:10:29 +09:00
Irit Katriel 022b44f254
gh-102056: Fix a few bugs in error handling of exception printing code (#102078) 2023-02-20 22:16:09 +00:00
Jason R. Coombs 36854bbb24
gh-101566: Sync with zipp 3.14. (GH-102018) 2023-02-20 13:01:58 -08:00
Tim Hatch 59e86caca8
gh-88233: zipfile: handle extras after a zip64 extra (GH-96161)
Previously, any data _after_ the zip64 extra would be removed.

With many new tests.

Fixes #88233

Automerge-Triggered-By: GH:jaraco
2023-02-20 09:07:03 -08:00
Erlend E. Aasland c00faf7943
gh-101819: Adapt _io types to heap types, batch 1 (GH-101949)
Adapt StringIO, TextIOWrapper, FileIO, Buffered*, and BytesIO types.

Automerge-Triggered-By: GH:erlend-aasland
2023-02-20 05:46:20 -08:00
Furkan Onder 61f1e67c6f
GH-84783: Make the slice object hashable (GH-101264) 2023-02-18 18:22:02 -06:00
Jason R. Coombs 5170caf305
gh-97930: Apply changes from importlib_resources 5.12. (GH-102010) 2023-02-18 16:29:22 -05:00
Dong-hee Na f482ade4c7
gh-101766: Fix refleak for _BlockingOnManager resources from test suite level (gh-101988) 2023-02-18 00:18:47 +09:00
Barney Gale 072011b3c3
gh-100809: Fix handling of drive-relative paths in pathlib.Path.absolute() (GH-100812)
Resolving the drive independently uses the OS API, which ensures it starts from the current directory on that drive.
2023-02-17 14:08:14 +00:00
Barney Gale d401b20630
gh-101360: Fix anchor matching in pathlib.PureWindowsPath.match() (GH-101363)
Use `fnmatch` to match path and pattern anchors, just as we do for other
path parts. This allows patterns such as `'*:/Users/*'` to be matched.
2023-02-17 14:05:38 +00:00
Eric Snow 984f8ab018
gh-101758: Fix Refleak-Related Failures in test_singlephase_variants (gh-101969)
gh-101891 is causing failures under `$> ./python -m test test_imp -R 3:3`.  Furthermore, with that fixed, "test_singlephase_variants" is leaking references.  This change addresses the first part, but skips the leaking tests until we can follow up with a fix.

https://github.com/python/cpython/issues/101758
2023-02-16 17:21:22 -07:00
Eric Snow 4d8959b73a
gh-101758: Add _PyState_AddModule() Back for the Stable ABI (gh-101956)
We're adding the function back, only for the stable ABI symbol and not as any form of API. I had removed it yesterday.

This undocumented "private" function was added with the implementation for PEP 3121 (3.0, 2007) for internal use and later moved out of the limited API (3.6, 2016) and then into the internal API (3.9, 2019). I removed it completely yesterday, including from the stable ABI manifest (where it was added because the symbol happened to be exported). It's unlikely that anyone is using _PyState_AddModule(), especially any stable ABI extensions built against 3.2-3.5, but we're playing it safe.

https://github.com/python/cpython/issues/101758
2023-02-16 14:05:31 -07:00
Kumar Aditya a5024a261a
GH-96764: rewrite `asyncio.wait_for` to use `asyncio.timeout` (#98518)
Changes `asyncio.wait_for` to use `asyncio.timeout` as its underlying implementation.
2023-02-17 00:18:21 +05:30
Rayyan Ansari 739c026f44
gh-101881: Support (non-)blocking read/write functions on Windows pipes (GH-101882)
* fileutils: handle non-blocking pipe IO on Windows

Handle erroring operations on non-blocking pipes by reading the _doserrno code.
Limit writes on non-blocking pipes that are too large.

* Support blocking functions on Windows

Use the GetNamedPipeHandleState and SetNamedPipeHandleState Win32 API functions to add support for os.get_blocking and os.set_blocking.
2023-02-16 14:52:24 +00:00
Irit Katriel 36b139af63
gh-101951: use textwrap.dedent in compiler tests to make them more readable (GH-101950)
Fixes #101951.

Automerge-Triggered-By: GH:iritkatriel
2023-02-16 04:31:59 -08:00
penguin_wwy df7ccf6138
gh-101928: fix crash in compiler on multi-line lambda in function call (#101933) 2023-02-16 11:31:41 +00:00
Gregory P. Smith 0b13575e74
gh-99108: Refactor _sha256 & _sha512 into _sha2. (#101924)
This merges their code. They're backed by the same single HACL* static library, having them be a single module simplifies maintenance.

This should unbreak the wasm enscripten builds that currently fail due to linking in --whole-archive mode and the HACL* library appearing twice.

Long unnoticed error fixed: _sha512.SHA384Type was doubly assigned and was actually SHA512Type. Nobody depends on those internal names.

Also rename LIBHACL_ make vars to LIBHACL_SHA2_ in preperation for other future HACL things.
2023-02-15 22:08:20 -08:00
Eric Snow 89ac665891
gh-98627: Add an Optional Check for Extension Module Subinterpreter Compatibility (gh-99040)
Enforcing (optionally) the restriction set by PEP 489 makes sense. Furthermore, this sets the stage for a potential restriction related to a per-interpreter GIL.

This change includes the following:

* add tests for extension module subinterpreter compatibility
* add _PyInterpreterConfig.check_multi_interp_extensions
* add Py_RTFLAGS_MULTI_INTERP_EXTENSIONS
* add _PyImport_CheckSubinterpIncompatibleExtensionAllowed()
* fail iff the module does not implement multi-phase init and the current interpreter is configured to check

https://github.com/python/cpython/issues/98627
2023-02-15 18:16:00 -07:00
Eric Snow 3dea4ba6c1
gh-101758: Fix the wasm Buildbots (gh-101943)
They were broken by gh-101920.

https://github.com/python/cpython/issues/101758
2023-02-15 17:54:05 -07:00
Eric Snow b365d88465
gh-101758: Add a Test For Single-Phase Init Modules in Multiple Interpreters (gh-101920)
The test verifies the behavior of single-phase init modules when loaded in multiple interpreters.

https://github.com/python/cpython/issues/101758
2023-02-15 16:05:07 -07:00
Eric Snow b2fc549278
gh-101758: Clean Up Uses of Import State (gh-101919)
This change is almost entirely moving code around and hiding import state behind internal API.  We introduce no changes to behavior, nor to non-internal API.  (Since there was already going to be a lot of churn, I took this as an opportunity to re-organize import.c into topically-grouped sections of code.)  The motivation is to simplify a number of upcoming changes.

Specific changes:

* move existing import-related code to import.c, wherever possible
* add internal API for interacting with import state (both global and per-interpreter)
* use only API outside of import.c (to limit churn there when changing the location, etc.)
* consolidate the import-related state of PyInterpreterState into a single struct field (this changes layout slightly)
* add macros for import state in import.c (to simplify changing the location)
* group code in import.c into sections
*remove _PyState_AddModule()

https://github.com/python/cpython/issues/101758
2023-02-15 15:32:31 -07:00
Erlend E. Aasland c1ce0d178f
gh-99138: Isolate _zoneinfo (#99218)
* Convert zone info type to heap type and add it to module state
* Add global variables to module state
2023-02-15 22:58:48 +01:00
Erlend E. Aasland 8a2b7ee64d
gh-101693: In sqlite3, deprecate using named placeholders with parameters supplied as a sequence (#101698) 2023-02-15 06:27:16 +01:00
Eric Snow 096d0097a0
gh-101758: Add a Test For Single-Phase Init Module Variants (gh-101891)
The new test exercises the most important variants for single-phase init extension modules. We also add some explanation about those variants to import.c.

https://github.com/python/cpython/issues/101758
2023-02-14 14:26:03 -07:00
Radek Smejkal 928752ce4c
gh-74895: getaddrinfo no longer raises OverflowError (#2435)
`socket.getaddrinfo()` no longer raises `OverflowError` based on the **port** argument. Error reporting (or not) for its value is left up to the underlying C library `getaddrinfo()` implementation.
2023-02-13 17:37:34 -08:00
Mark Shannon 160f2fe2b9
GH-87849: Simplify stack effect of SEND and specialize it for generators and coroutines. (GH-101788) 2023-02-13 11:24:55 +00:00
Soumendra Ganguly da2fb92643
gh-85984: Utilize new "winsize" functions from termios in pty tests. (#101831)
Utilize new functions termios.tcgetwinsize() and termios.tcsetwinsize in test_pty.py.

Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-02-11 21:24:43 -08:00
mjoerg 3eb12df8b5
Fix typo in test_fstring.py (#101823) 2023-02-11 21:04:15 +05:30
Irit Katriel 366b949058
gh-101517: make bdb avoid looking up in linecache with lineno=None (#101787) 2023-02-10 16:49:29 +00:00
Ikko Eltociear Ashimine 272da55aff
Fix typo in `test_fstring.py` (#101600) 2023-02-09 23:15:58 +05:30
Michael Droettboom 86ebd5c3fa
gh-101196: Make isdir/isfile/exists faster on Windows (GH-101324)
Co-authored-by: Eryk Sun <eryksun@gmail.com>
2023-02-08 14:34:24 +00:00
Nikita Sobolev eb49d32b9a
gh-100933: Improve `check_element` helper in `test_xml_etree` (#100934)
Items checked by this test are always `str` and `dict` instances.
2023-02-08 11:13:43 +01:00
Mark Shannon feec49c407
GH-101578: Normalize the current exception (GH-101607)
* Make sure that the current exception is always normalized.

* Remove redundant type and traceback fields for the current exception.

* Add new API functions: PyErr_GetRaisedException, PyErr_SetRaisedException

* Add new API functions: PyException_GetArgs, PyException_SetArgs
2023-02-08 09:31:12 +00:00
Nikita Sobolev 790ff6bc6a
gh-101446: Change `repr` of `collections.OrderedDict` (#101661) 2023-02-07 20:01:10 -06:00
penguin_wwy 753fc8a5d6
gh-101632: Add the new RETURN_CONST opcode (#101633) 2023-02-07 22:32:21 +00:00
Zachary Ware 6fd5eb640a
Make use of TESTFN_ASCII in test_fileio (GH-101645)
testBytesOpen requires an ASCII filename, but TESTFN usually isn't ASCII.

Automerge-Triggered-By: GH:zware
2023-02-07 09:22:58 -08:00
Matthieu Dartiailh ae62bddaf8
gh-101072: support default and kw default in PyEval_EvalCodeEx for 3.11+ (#101127)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2023-02-07 10:34:21 +01:00
Jonathan Protzenko 1fcc0efdaa
gh-99108: Replace SHA2-224 & 256 with verified code from HACL* (#99109)
replacing hashlib primitives (for the non-OpenSSL case) with verified implementations from HACL*. This is the first PR in the series, and focuses specifically on SHA2-256 and SHA2-224.

This PR imports Hacl_Streaming_SHA2 into the Python tree. This is the HACL* implementation of SHA2, which combines a core implementation of SHA2 along with a layer of buffer management that allows updating the digest with any number of bytes. This supersedes the previous implementation in the tree.

@franziskuskiefer was kind enough to benchmark the changes: in addition to being verified (thus providing significant safety and security improvements), this implementation also provides a sizeable performance boost!

```
---------------------------------------------------------------
Benchmark                     Time             CPU   Iterations
---------------------------------------------------------------
Sha2_256_Streaming            3163 ns      3160 ns       219353     // this PR
LibTomCrypt_Sha2_256          5057 ns      5056 ns       136234     // library used by Python currently
``` 

The changes in this PR are as follows:
- import the subset of HACL* that covers SHA2-256/224 into `Modules/_hacl`
- rewire sha256module.c to use the HACL* implementation

Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-02-06 18:11:01 -08:00
Eric Snow 914f8fd9f7
gh-59956: Add a Test to Verify GILState Matches the "Current" Thread State (gh-101625)
This test should have been in gh-101431.

https://github.com/python/cpython/issues/59956
2023-02-06 15:53:31 -07:00
Eclips4 b96b344f25
gh-101562: typing: add tests for inheritance with NotRequired & Required in parent fields (#101563) 2023-02-06 11:28:24 -08:00
Mark Dickinson 46416b9004
gh-76961: Fix buildbot failures in test_pep3118 (#101587)
This PR fixes the buildbot failures introduced by the merge of #5561, by restricting the relevant tests to something that should work on both 32-bit and 64-bit platforms. It also silences some compiler warnings introduced in that PR.
2023-02-06 12:25:31 +00:00
Ethan Furman ef7c2bfcf1
gh-101541: [Enum] create flag psuedo-member without calling original __new__ (GH-101590) 2023-02-05 19:29:06 -08:00
Gregory P. Smith ffcb8220d7
gh-101334: Don't force USTAR format in test_tarfile. (GH-101572)
That causes the test to fail when run using a high UID as that ancient format
cannot represent it. The current default (PAX) and the old default (GNU) both
support high UIDs.
2023-02-05 09:44:57 -08:00
mrh1997 f7e9fbacb2
bpo-33591: Add support for path like objects to `ctypes.CDLL` (#7032)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2023-02-05 23:06:57 +05:30
Eric Wieser 90d85a9b41
gh-76961: Fix the PEP3118 format string for ctypes.Structure (#5561)
The summary of this diff is that it:

* adds a `_ctypes_alloc_format_padding` function to append strings like `37x` to a format string to indicate 37 padding bytes
* removes the branches that amount to "give up on producing a valid format string if the struct is packed"
* combines the resulting adjacent `if (isStruct) {`s now that neither is `if (isStruct && !isPacked) {`
* invokes `_ctypes_alloc_format_padding` to add padding between structure fields, and after the last structure field. The computation used for the total size is unchanged from ctypes already used.

This patch does not affect any existing aligment computation; all it does is use subtraction to deduce the amount of paddnig introduced by the existing code.

---

Without this fix, it would never include padding bytes - an assumption that was only
valid in the case when `_pack_` was set - and this case was explicitly not implemented.

This should allow conversion from ctypes structs to numpy structs

Fixes https://github.com/numpy/numpy/issues/10528
2023-02-05 17:10:53 +00:00
Mark Dickinson 0672a6c23b
Revert "gh-89381: Fix invalid signatures of math/cmath.log (#101404)" (#101580)
This reverts commit 0ef92d9793.
2023-02-05 16:36:33 +00:00
Mark Dickinson 39017e04b5
gh-101266: Fix __sizeof__ for subclasses of int (#101394)
Fix the behaviour of the `__sizeof__` method (and hence the results returned by `sys.getsizeof`) for subclasses of `int`. Previously, `int` subclasses gave identical results to the `int` base class, ignoring the presence of the instance dictionary.

<!-- gh-issue-number: gh-101266 -->
* Issue: gh-101266
<!-- /gh-issue-number -->
2023-02-05 10:02:53 +00:00
Alexander Belopolsky ddd619cffa
Fix detection of presence of time.tzset (gh-101539) (#101540)
Resolves gh-101539
Related to gh-31898
2023-02-05 11:14:15 +04:00
Raymond Hettinger 5a2b984568
GH-100485: Create an alternative code path when an accurate fma() implementation is not available (#101567) 2023-02-04 17:54:44 -06:00
Ruben Vorderman a89e6713c4
gh-101322: Ensure test_zlib.ZlibDecompressorTest runs, fix errors in ZlibDecompressor (#101323)
* Ensure test_zlib.ZlibDecompressorTest actually runs, fix errors in ZlibDecompressor.
2023-02-04 12:07:30 -08:00
Eric Snow c67b00534a
gh-101524: Split Up the _xxsubinterpreters Module (gh-101526)
This is step 1 in potentially dropping all the "channel"-related code. Channels have already been removed from PEP 554.

https://github.com/python/cpython/issues/101524
2023-02-03 18:14:43 -07:00
Gregory P. Smith d4c410f0f9
gh-84559: Remove the new multiprocessing warning, too disruptive. (#101551)
This reverts the core of #100618 while leaving relevant documentation
improvements and minor refactorings in place.
2023-02-03 15:20:46 -08:00
Gregory P. Smith 5dcae3f0c3
gh-84559: skip the test when no multiprocessing (wasm, etc) (#101530)
skip test when no _multiprocessing (wasm, etc)
2023-02-02 17:14:23 -08:00
Gregory P. Smith 0ca67e6313
GH-84559: Deprecate fork being the multiprocessing default. (#100618)
This starts the process. Users who don't specify their own start method
and use the default on platforms where it is 'fork' will see a
DeprecationWarning upon multiprocessing.Pool() construction or upon
multiprocessing.Process.start() or concurrent.futures.ProcessPool use.

See the related issue and documentation within this change for details.
2023-02-02 15:50:35 -08:00
Steve Dower eda60916bc
gh-101467: Correct py.exe handling of prefix matches and cases when only one runtime is installed (GH-101468) 2023-02-01 21:06:56 +00:00
Erlend E. Aasland 2b3e02a705
gh-101277: Isolate itertools, add group and _grouper types to module state (#101302)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-02-01 12:41:30 +01:00
Dong-hee Na e867c1b753
gh-101400: Fix incorrect lineno in exception message on continue/break which are not in a loop (#101413) 2023-01-30 23:33:54 +00:00
Eclips4 28db978d7f
gh-101229: Add tests for aliases of imported names (#101230) 2023-01-30 11:49:06 -08:00
Sergey B Kirpichev 0ef92d9793
gh-89381: Fix invalid signatures of math/cmath.log (#101404) 2023-01-29 11:50:10 -08:00
Raymond Hettinger 84483aacc0
GH-100485: Add extended accuracy test. Switch to faster fma() based variant. GH-101383) 2023-01-28 06:29:21 -06:00
Gregory P. Smith 052f53d65d
gh-39615: Add warnings.warn() skip_file_prefixes support (#100840)
`warnings.warn()` gains the ability to skip stack frames based on code
filename prefix rather than only a numeric `stacklevel=` via a new
`skip_file_prefixes=` keyword argument.
2023-01-27 18:35:14 -08:00
Barney Gale e5b08ddddf
gh-101000: Add os.path.splitroot() (#101002)
Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-01-27 00:28:27 +00:00
Oleg Iarygin 409f5337a3
gh-60580: Fix a wrong type of `ctypes.wintypes.BYTE` (#97579)
Created from a patch file attached to an issue, by Anatoly Techtonik.
2023-01-26 18:16:27 +04:00
Dong-hee Na f2ac9510a5
gh-85100: Migrate BPO link to the GitHub link for malloc warnings (gh-101343) 2023-01-26 21:58:35 +09:00
Yukihiro Nakadaira dfad678d70
gh-99952: [ctypes] fix refcount issues in from_param() result. (#100169)
Fixes a reference counting issue with `ctypes.Structure` when a `from_param()` method call is used and the structure size is larger than a C pointer `sizeof(void*)`.

This problem existed for a very long time, but became more apparent in 3.8+ by change likely due to garbage collection cleanup timing changes.
2023-01-26 00:28:34 -08:00
JosephSBoyle a2262789ab
gh-100522 Add a test for 'futures.as_completed' timing out with a non-zero timeout value (#100523) 2023-01-25 23:01:11 -08:00
Shantanu a178ba82bf
gh-101326: Fix regression when passing None to FutureIter.throw (#101327) 2023-01-25 12:01:01 -08:00
achhina 952a1d9cc9
GH-88597: Rename uuid's new CLI args to be in line with uuidgen. (#101248)
this way they match an existing uuidgen command line tool.
2023-01-25 09:39:42 -08:00
Mark Shannon f02fa64bf2
GH-100762: Don't call `gen.throw()` in `gen.close()`, unless necessary. (GH-101013)
* Store exception stack depth in YIELD_VALUE's oparg and use it avoid expensive gen.throw() in gen.close() where possible.
2023-01-24 17:25:37 +00:00
Irit Katriel bd7903967c
gh-101261: add test for function with > 255 args (#101262) 2023-01-23 20:10:10 +00:00
Nikita Sobolev 807d6b576f
gh-101015: Fix `typing.get_type_hints` with unpacked `*tuple` (PEP 646) (#101031) 2023-01-23 07:52:58 +00:00
Jacob Walls d717be04dc
gh-83122: Deprecate testing element truth values in `ElementTree` (#31149)
When testing element truth values, emit a DeprecationWarning in all implementations.

This had emitted a FutureWarning in the rarely used python-only implementation since ~2.7 and has always been documented as a behavior not to rely on.

Matching an element in a tree search but having it test False can be unexpected. Raising the warning enables making the choice to finally raise an exception for this ambiguous behavior in the future.
2023-01-22 17:16:48 -08:00
Mark Dickinson 3e09f3152e
gh-67790: Support float-style formatting for Fraction instances (#100161)
This PR adds support for float-style formatting for `Fraction` objects: it supports the `"e"`, `"E"`, `"f"`, `"F"`, `"g"`, `"G"` and `"%"` presentation types, and all the various bells and whistles of the formatting mini-language for those presentation types. The behaviour almost exactly matches that of `float`, but the implementation works with the exact `Fraction` value and does not do an intermediate conversion to `float`, and so avoids loss of precision or issues with numbers that are outside the dynamic range of the `float` type.

Note that the `"n"` presentation type is _not_ supported. That support could be added later if people have a need for it.

There's one corner-case where the behaviour differs from that of float: for the `float` type, if explicit alignment is specified with a fill character of `'0'` and alignment type `'='`, then thousands separators (if specified) are inserted into the padding string:

```python
>>> format(3.14, '0=11,.2f')
'0,000,003.14'
```

The exact same effect can be achieved by using the `'0'` flag:

```python
>>> format(3.14, '011,.2f')
'0,000,003.14'
```

For `Fraction`, only the `'0'` flag has the above behaviour with respect to thousands separators: there's no special-casing of the particular `'0='` fill-character/alignment combination. Instead, we treat the fill character `'0'` just like any other:

```python
>>> format(Fraction('3.14'), '0=11,.2f')
'00000003.14'
>>> format(Fraction('3.14'), '011,.2f')
'0,000,003.14'
```

The `Fraction` formatter is also stricter about combining these two things: it's not permitted to use both the `'0'` flag _and_ explicit alignment, on the basis that we should refuse the temptation to guess in the face of ambiguity. `float` is less picky:

```python
>>> format(3.14, '0<011,.2f')
'3.140000000'
>>> format(Fraction('3.14'), '0<011,.2f')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mdickinson/Repositories/python/cpython/Lib/fractions.py", line 414, in __format__
    raise ValueError(
ValueError: Invalid format specifier '0<011,.2f' for object of type 'Fraction'; can't use explicit alignment when zero-padding
```
2023-01-22 18:44:49 +00:00
achhina 95f5b05a8c
GH-88597: Added command line interface to UUID module. (#99463)
The `uuid` module now supports command line usage.

```python
❯ ./python.exe -m uuid             
5f2d57b1-90e8-417c-ba5d-69b9b6f74289

❯ ./python.exe -m uuid -h          
usage: uuid.py [-h] [-u {uuid1,uuid3,uuid4,uuid5}] [-ns NAMESPACE] [-n NAME]
...
```
2023-01-21 22:59:31 -08:00
Nikita Sobolev c1c5882359
gh-100518: Add tests for `ast.NodeTransformer` (#100521) 2023-01-21 21:44:41 +00:00
Pieter Eendebak f63f525e16
gh-100726: Optimize construction of range object for medium sized integers (#100810)
Use C long arithmetic instead of PyLong arithmetic to compute the range length, where possible.

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2023-01-21 19:33:08 +00:00
Kamil Turek b4e11a7985
gh-99266: ctypes: Preserve more detailed exception in `ArgumentError`
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-01-21 19:14:43 +05:30
Erlend E. Aasland 3847a6c64b
gh-92123: Convert `_elementtree` types to heap types (#99221) 2023-01-20 12:40:06 +01:00
Gregory P. Smith 5927013e47
gh-101144: Allow open and read_text encoding to be positional. (#101145)
The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only.

Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.
2023-01-19 23:04:30 -08:00
Irit Katriel 0c5db2a607
gh-101167: fix bug in the new test.support.requires_specialization decorator (GH-101171)
Fixes #101167.

Automerge-Triggered-By: GH:iritkatriel
2023-01-19 15:45:53 -08:00
Irit Katriel e9ccfe4a63
gh-100712: make it possible to disable specialization (for debugging) (#100713) 2023-01-19 18:14:55 +00:00
Steve Dower df10571a13
gh-100320: Fix path calculations on Windows when python.exe is moved outside of the normal location (GH-100947) 2023-01-16 16:05:39 +00:00
Mark Shannon 7b14c2ef19
GH-100982: Add `COMPARE_AND_BRANCH` instruction (GH-100983) 2023-01-16 12:35:21 +00:00
Yurii Karabas 080cb27829
gh-74033: Fix bug when Path takes and ignores **kwargs (GH-19632)
Fix a bug where `Path` takes and ignores `**kwargs` by adding to `PurePath`  class `__init__` method which can take only positional arguments.

Automerge-Triggered-By: GH:brettcannon
2023-01-13 16:05:43 -08:00
Guido van Rossum 1bc7a73683
GH-100573: Fix server hang caused by os.stat() on named pipe (Windows) (#100959) 2023-01-13 13:24:57 -08:00
Serhiy Storchaka e5bd5ad70d
gh-100160: Restore and deprecate implicit creation of an event loop (GH-100410)
Partially revert changes made in GH-93453.

asyncio.DefaultEventLoopPolicy.get_event_loop() now emits a
DeprecationWarning and creates and sets a new event loop instead of
raising a RuntimeError if there is no current event loop set.

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
2023-01-13 14:40:29 +02:00
Steve Dower 468c3bf798
gh-100247: Fix py.exe launcher not using entire shebang command for finding custom commands (GH-100944) 2023-01-13 11:49:01 +00:00