Commit Graph

29175 Commits

Author SHA1 Message Date
Alex Waygood 9cdb642997
gh-85432: Harmonise parameter names between C and pure-Python implementations of `datetime.time.strftime`, `datetime.datetime.fromtimestamp` (#99993) 2022-12-22 15:57:18 -06:00
Itamar Ostricher 4cc63e0d4e
gh-100344: Add C implementation for `asyncio.current_task` (#100345)
Co-authored-by: pranavtbhat
2022-12-22 19:08:12 +05:30
Eli Schwartz aa878f086b
gh-78997: fix bad rebase of moved test file (#100424) 2022-12-22 13:28:25 +00:00
Hai Shi d713c54ac8
gh-78878: Fix crash when creating an instance of `_ctypes.CField` (#14837) 2022-12-21 23:01:17 +05:30
Serhiy Storchaka b98d2d31bf
gh-100129: Add tests for pickling all builtin types and functions (GH-100142) 2022-12-21 16:31:22 +02:00
Dominic Socular 12be23cf3c
gh-100374: Fixed a bug in socket.getfqdn() (gh-100375) 2022-12-21 22:25:04 +09:00
Kumar Aditya a7715ccfba
GH-100133: fix `asyncio` subprocess losing `stderr` and `stdout` output (#100154) 2022-12-21 15:20:26 +05:30
Shantanu 79311cbfe7
gh-85267: Improvements to inspect.signature __text_signature__ handling (#98796)
This makes a couple related changes to inspect.signature's behaviour
when parsing a signature from `__text_signature__`.

First, `inspect.signature` is documented as only raising ValueError or
TypeError. However, in some cases, we could raise RuntimeError.  This PR
changes that, thereby fixing #83685.

(Note that the new ValueErrors in RewriteSymbolics are caught and then
reraised with a message)

Second, `inspect.signature` could randomly drop parameters that it
didn't understand (corresponding to `return None` in the `p` function).
This is the core issue in #85267. I think this is very surprising
behaviour and it seems better to fail outright.

Third, adding this new failure broke a couple tests. To fix them (and to
e.g. allow `inspect.signature(select.epoll.register)` as in #85267), I
add constant folding of a couple binary operations to RewriteSymbolics.

(There's some discussion of making signature expression evaluation
arbitrary powerful in #68155. I think that's out of scope. The
additional constant folding here is pretty straightforward, useful, and
not much of a slippery slope)

Fourth, while #85267 is incorrect about the cause of the issue, it turns
out if you had consecutive newlines in __text_signature__, you'd get
`tokenize.TokenError`.

Finally, the `if name is invalid:` code path was dead, since
`parse_name` never returned `invalid`.
2022-12-20 19:29:02 -08:00
Nikita Sobolev 44892d45b0
gh-99576: Fix cookiejar file that was not truncated for some classes (GH-99616)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2022-12-20 17:51:26 +01:00
František Nesveda d98ca8172c
gh-99925: Fix inconsistency in `json.dumps()` error messages (GH-99926) 2022-12-20 12:54:56 +02:00
Thomas Grainger 79ccc03b62
gh-89051: Add ssl.OP_LEGACY_SERVER_CONNECT (#93927)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Fixes https://github.com/python/cpython/issues/89051
2022-12-20 09:10:30 +02:00
Jon Burdo 797edb28c3
gh-89727: Fix os.walk RecursionError on deep trees (#99803)
Use a stack to implement os.walk iteratively instead of recursively to
avoid hitting recursion limits on deeply nested trees.
2022-12-19 10:59:01 -08:00
Carlton Gibson 532aa4e4e0
gh-94912: Added marker for non-standard coroutine function detection (#99247)
This introduces a new decorator `@inspect.markcoroutinefunction`,
which, applied to a sync function, makes it appear async to
`inspect.iscoroutinefunction()`.
2022-12-18 11:13:24 -08:00
Serhiy Storchaka 0fe61d0838
gh-100272: Fix JSON serialization of OrderedDict (GH-100273)
It now preserves the order of keys.
2022-12-17 14:32:48 +02:00
Erlend E. Aasland 2b38a9aa74
gh-93649: Split tracemalloc tests from _testcapimodule.c (#99551) 2022-12-17 09:53:36 +01:00
colorfulappl efbb1eb9f5
gh-99240: Reset pointer to NULL when the pointed memory is freed in argument parsing (#99890)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2022-12-17 12:07:44 +05:30
Barney Gale 5a991da329
gh-78707: deprecate passing >1 argument to `PurePath.[is_]relative_to()` (GH-94469)
This brings `relative_to()` and `is_relative_to()` more in line with other pathlib methods like `rename()` and `symlink_to()`.

Resolves #78707.
2022-12-16 16:14:27 -08:00
Ethan Furman a5a7cea202
gh-100039: enhance __signature__ to work with str and callables (GH-100168)
Callables should be either class- or static-methods.
Enum now uses the classmethod version to greatly improve the help
given for enums and flags.
2022-12-16 12:30:47 -08:00
Raymond Hettinger b430399d41
GH-100234: Set a default value for random.expovariate() (GH-100235) 2022-12-15 12:40:45 -06:00
Yesung(Isaac) Lee 54289f85b2
gh-99688: Fix outdated tests in test_unary (#99712)
* Remove duplicates from "L" suffix removal
* test_invert now tests `~`.
2022-12-11 18:44:29 -05:00
Gregory P. Smith 2e279e85fe
gh-88500: Reduce memory use of `urllib.unquote` (#96763)
`urllib.unquote_to_bytes` and `urllib.unquote` could both potentially generate `O(len(string))` intermediate `bytes` or `str` objects while computing the unquoted final result depending on the input provided. As Python objects are relatively large, this could consume a lot of ram.

This switches the implementation to using an expanding `bytearray` and a generator internally instead of precomputed `split()` style operations.

Microbenchmarks with some antagonistic inputs like `mess = "\u0141%%%20a%fe"*1000` show this is 10-20% slower for unquote and unquote_to_bytes and no different for typical inputs that are short or lack much unicode or % escaping. But the functions are already quite fast anyways so not a big deal.  The slowdown scales consistently linear with input size as expected.

Memory usage observed manually using `/usr/bin/time -v` on `python -m timeit` runs of larger inputs. Unittesting memory consumption is difficult and does not seem worthwhile.

Observed memory usage is ~1/2 for `unquote()` and <1/3 for `unquote_to_bytes()` using `python -m timeit -s 'from urllib.parse import unquote, unquote_to_bytes; v="\u0141%01\u0161%20"*500_000' 'unquote_to_bytes(v)'` as a test.
2022-12-10 16:17:39 -08:00
DarioDaF 1bb68ba6d9
gh-99941: Ensure that asyncio.Protocol.data_received receives immutable bytes (#100053) 2022-12-10 15:07:02 -08:00
Fantix King 50b08d5b5f
Fix potential flakiness in `test_run_until_complete_baseexception` (#100148) 2022-12-10 15:34:22 +05:30
andrei kulakov d0679c1239
bpo-44512: Fix handling of extrasactions arg to csv.DictWriter with mixed or upper case (#26924) 2022-12-09 16:14:33 +00:00
Shreyan Avigyan a29a7b9b78
bpo-43984: Allow winreg.SetValueEx to set -1 without treating it as an error (GH-25775) 2022-12-09 12:47:18 +00:00
Kumar Aditya 0448deac70
GH-100113: remove remaining `yield from` usage from `asyncio` tests (#100114) 2022-12-09 09:22:18 +05:30
Eric Snow cda9f0236f
gh-81057: Move OS-Related Globals to _PyRuntimeState (gh-100082)
https://github.com/python/cpython/issues/81057
2022-12-08 15:38:06 -07:00
Raymond Hettinger 35cc0ea736
GH-98363: Have batched() return tuples (GH-100118) 2022-12-08 15:08:16 -06:00
Victor Stinner cd67c1bb30
test_ast uses infinite_recursion() to prevent crash (#100104)
test.test_ast_recursion_limit() now uses infinite_recursion() of
test.support to prevent crashes on debug builds.

Before this change, the test crashed on ARM64 Windows 3.x buildbot
worker which builds Python in debug mode.
2022-12-08 09:26:38 +01:00
Fantix King e8fff515f0
Fix `test_run_until_complete_baseexception` test to check for `KeyboardInterrupt` in asyncio (#24477) 2022-12-08 13:51:04 +05:30
Ethan Furman ded02ca54d
gh-100098: [Enum] insist on actual tuples, no subclasses, for auto (GH-100099)
When checking for auto() instances, only top-level usage is supported,
which means either alone or as part of a regular tuple. Other
containers, such as lists, dicts, or namedtuples, will not have auto()
transformed into a value.
2022-12-07 22:58:08 -08:00
Dong-hee Na dc8a86893d
gh-98778: Update HTTPError to initialize properly even if fp is None (gh-99966) 2022-12-08 11:20:34 +09:00
Victor Stinner 3c89202247
gh-100086: Add build info to test.libregrtest (#100093)
The Python test runner (libregrtest) now logs Python build information like
"debug" vs "release" build, or LTO and PGO optimizations.
2022-12-08 01:38:47 +01:00
Irit Katriel f3e97c90ed
gh-100077: make test_code.test_invalid_bytecode more robust and maintainable (#100078) 2022-12-07 18:09:05 +00:00
Carl Meyer 68e41295b8
gh-83035: handle decorator with nested parens in inspect.getsource (#99654) 2022-12-07 08:55:12 -08:00
Matěj Cepl 7031275776
gh-93018: Fix for the compatibility problems with expat (gh-93900) 2022-12-07 15:55:49 +09:00
Nikita Sobolev 889b0b9bf9
[Enum] Remove unused code from `test_enum.py` (GH-96986) 2022-12-06 18:44:47 -08:00
Pablo Galindo Salgado 97e7004cfe
gh-100050: Fix an assertion error when raising unclosed parenthesis errors in the tokenizer (GH-100065)
Automerge-Triggered-By: GH:pablogsal
2022-12-06 15:09:56 -08:00
Ethan Furman 679efbb080
gh-94943: [Enum] improve repr() when inheriting from a dataclass (GH-99740)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
2022-12-06 13:43:41 -08:00
Serhiy Storchaka fd38a2f0ec
gh-93453: No longer create an event loop in get_event_loop() (#98440)
asyncio.get_event_loop() now always return either running event loop or
the result of get_event_loop_policy().get_event_loop() call. The latter
should now raise an RuntimeError if no current event loop was set
instead of creating and setting a new event loop.

It affects also a number of asyncio functions and constructors which
call get_event_loop() implicitly: ensure_future(), shield(), gather(),
etc.

DeprecationWarning is no longer emitted if there is no running event loop but
the current event loop was set.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2022-12-06 18:42:12 +01:00
Brandt Bucher b72014c783
GH-99729: Unlink frames before clearing them (GH-100030) 2022-12-06 14:01:38 +00:00
Erik De Bonte 5c19050546
gh-99957: Add `frozen_default` parameter on `dataclass_transform` (#99958) 2022-12-05 19:35:43 -08:00
Gregory P. Smith 7e29398407
gh-100001: Also escape \s in http.server log messages. (#100038)
Also \ escape \s in the http.server BaseHTTPRequestHandler.log_message so
that it is technically possible to parse the line and reconstruct what the
original data was.  Without this a \xHH is ambiguious as to if it is a hex
replacement we put in or the characters r"\x" came through in the original
request line.
2022-12-05 14:27:55 -08:00
Gregory P. Smith d8ab0a4dfa
gh-100001: Omit control characters in http.server stderr logs. (#100002)
Replace control characters in http.server.BaseHTTPRequestHandler.log_message with an escaped \xHH sequence to avoid causing problems for the terminal the output is printed to.
2022-12-05 12:55:45 -08:00
Eric Snow 530cc9dbb6
gh-99741: Implement Multi-Phase Init for the _xxsubinterpreters Module (gh-99742)
_xxsubinterpreters is an internal module used for testing.

https://github.com/python/cpython/issues/99741
2022-12-05 13:40:20 -07:00
Serhiy Storchaka 922a6cf6c2
gh-60203: Revert changes in cycle.__setstate__ (#99982)
In case if only True/False be supported as boolean arguments in future,
we should continue to support 1/0 here.
2022-12-05 17:27:40 +01:00
Victor Stinner 2488c1e1b6
gh-99892: test_unicodedata: skip test on download failure (#100011)
Skip test_normalization() of test_unicodedata if it fails to download
NormalizationTest.txt file from pythontest.net.
2022-12-05 16:37:40 +01:00
Victor Stinner 038b151963
gh-100005: Skip test_script_as_dev_fd() on FreeBSD (#100006)
On FreeBSD, skip test_script_as_dev_fd() of test_cmd_line_script if
fdescfs is not mounted (at /dev/fd).
2022-12-05 14:23:35 +01:00
Felix Ye 854a878e4f
gh-98248: Normalizing the error messages in function struct.pack (GH-98252)
Provide consistent and informative error messages in function struct.pack when its integral arguments are not in range.
2022-12-04 20:24:18 +00:00
AlexTate 72ec518203
gh-98458: unittest: bugfix for infinite loop while handling chained exceptions that contain cycles (#98459)
* Bugfix addressing infinite loop while handling self-referencing chained exception in TestResult._clean_tracebacks()
* Bugfix extended to properly handle exception cycles in _clean_tracebacks. The "seen" set follows the approach used in the TracebackException class (thank you @iritkatriel for pointing it out)
* adds a test for a single chained exception that holds a self-loop in its __cause__ and __context__ attributes
2022-12-04 11:37:55 -08:00