Commit Graph

29010 Commits

Author SHA1 Message Date
Nikita Sobolev 72c166add8
gh-94808: Cover `%p` in `PyUnicode_FromFormat` (#96677)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-10-07 09:53:42 -07:00
Carl Meyer be4099e55d
Fix memory leaks in test_capi (#98017) 2022-10-07 08:17:41 -07:00
Oleg Iarygin f99bb20cde
gh-97983: Revert "Lay the foundation for further work in asyncio.test_streams: port server cases to IsolatedAsyncioTestCase" (#98015)
This PR reverts gh-93369 and gh-97896 because they've made asyncio tests unstable. After these PRs were merged, random GitHub action jobs of random commits started to fail unrelated tests and test framework methods.

The reverting is necessary because such shrapnel failures are a symptom of some underlying bug that must be found and fixed first.

I had a hope that it's a server overload because we already have extremely rare disc access errors. However, one and a half day passed, and the failures continue to emerge both in PRs and commits.

Affected issue: gh-93357.
First reported in https://github.com/python/cpython/pull/97940#issuecomment-1270004134.

* Revert "gh-93357: Port test cases to IsolatedAsyncioTestCase, part 2 (#97896)"

This reverts commit 09aea94d29.

* Revert "gh-93357: Start porting asyncio server test cases to IsolatedAsyncioTestCase (#93369)"

This reverts commit ce8fc186ac.
2022-10-07 07:14:28 -07:00
Barry Warsaw 13d4489142
gh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() (GH-97803)
In `_warnings.c`, in the C equivalent of `warnings.warn_explicit()`, if the module globals are given (and not None), the warning will attempt to get the source line for the issued warning.  To do this, it needs the module's loader.

Previously, it would only look up `__loader__` in the module globals.  In https://github.com/python/cpython/issues/86298 we want to defer to the `__spec__.loader` if available.

The first step on this journey is to check that `loader == __spec__.loader` and issue another warning if it is not.  This commit does that.

Since this is a PoC, only manual testing for now.

```python
# /tmp/foo.py
import warnings

import bar

warnings.warn_explicit(
    'warning!',
    RuntimeWarning,
    'bar.py', 2,
    module='bar knee',
    module_globals=bar.__dict__,
    )
```

```python
# /tmp/bar.py
import sys
import os
import pathlib

# __loader__ = pathlib.Path()
```

Then running this: `./python.exe -Wdefault /tmp/foo.py`

Produces:

```
bar.py:2: RuntimeWarning: warning!
  import os
```

Uncomment the `__loader__ = ` line in `bar.py` and try it again:

```
sys:1: ImportWarning: Module bar; __loader__ != __spec__.loader (<_frozen_importlib_external.SourceFileLoader object at 0x109f7dfa0> != PosixPath('.'))
bar.py:2: RuntimeWarning: warning!
  import os
```

Automerge-Triggered-By: GH:warsaw
2022-10-06 19:32:53 -07:00
Nikita Sobolev 27025e158c
gh-97850: Remove deprecated functions from `importlib.utils` (#97898)
* gh-97850: Remove deprecated functions from `importlib.utils`

* Rebase and remove `set_package` from diff
2022-10-06 17:57:10 -07:00
Guido van Rossum 09de8d7aaf
GH-90985: Revert "Deprecate passing a message into cancel()" (#97999)
Reason: we were too hasty in deprecating this.
We shouldn't deprecate it before we have a replacement.
2022-10-06 17:30:27 -07:00
Tiger c46a423a52
bpo-35540 dataclasses.asdict now supports defaultdict fields (gh-32056) 2022-10-06 17:11:59 -07:00
Carl Meyer a4b7794887
GH-91052: Add C API for watching dictionaries (GH-31787) 2022-10-07 01:08:00 +01:00
Brandt Bucher 21a2d9ff55
GH-97002: Prevent `_PyInterpreterFrame`s from backing more than one `PyFrameObject` (GH-97996) 2022-10-07 00:20:01 +01:00
Brett Cannon e1c4d56fdd
gh-65961: Do not rely solely on `__cached__` (GH-97990)
Make sure `__spec__.cached` (at minimum) can be used.
2022-10-06 15:40:22 -07:00
Jason R. Coombs 8af04cdef2
gh-97781: Apply changes from importlib_metadata 5. (GH-97785)
* gh-97781: Apply changes from importlib_metadata 5.

* Apply changes from upstream

* Apply changes from upstream.
2022-10-06 15:25:24 -04:00
Michael Droettboom 23e83a8465
gh-94808: Coverage: Test that maximum indentation level is handled (#95926)
* gh-94808: Coverage: Test that maximum indentation level is handled

* Use "compile" rather than "exec"
2022-10-06 10:39:17 -07:00
Ned Deily 6d0a0191a4
gh-97897: Prevent os.mkfifo and os.mknod segfaults with macOS 13 SDK (GH-97944)
The macOS 13 SDK includes support for the `mkfifoat` and `mknodat` system calls.
 Using the `dir_fd` option with either `os.mkfifo` or `os.mknod` could result in a
 segfault if cpython is built with the macOS 13 SDK but run on an earlier
 version of macOS. Prevent this by adding runtime support for detection of
 these system calls ("weaklinking") as is done for other newer syscalls on
 macOS.
2022-10-06 09:11:47 -07:00
Nikita Sobolev e63d7dae90
gh-94808: Cover `PyUnicode_Count` in CAPI (#96929) 2022-10-06 17:20:22 +02:00
Nikita Sobolev e39ae6bef2
gh-94808: Cover `PyObject_PyBytes` case with custom `__bytes__` method (#96610)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-10-06 05:16:16 -07:00
Ethan Furman b44372e03c
gh-96865: [Enum] fix Flag to use CONFORM boundary (GH-97528) 2022-10-05 15:25:55 -07:00
Brett Cannon c206e53bb7
gh-65961: Raise `DeprecationWarning` when `__package__` differs from `__spec__.parent` (#97879)
Also remove `importlib.util.set_package()` which was already slated for removal.

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2022-10-05 15:00:45 -07:00
Barry Warsaw 5dc3599135
gh-97850: Remove all known instances of module_repr() (#97876)
Remove all known instances of module_repr()
2022-10-05 11:42:26 -07:00
Kumar Aditya 7015e13797
gh-88050: Fix asyncio subprocess to kill process cleanly when process is blocked (#32073) 2022-10-05 10:15:31 -07:00
Oleg Iarygin 09aea94d29
gh-93357: Port test cases to IsolatedAsyncioTestCase, part 2 (#97896)
This fixes the buildbots.
2022-10-05 07:31:43 -07:00
Serhiy Storchaka 77f0249308
gh-95196: Disable incorrect pickling of the C implemented classmethod descriptors (GH-96383) 2022-10-05 14:21:16 +03:00
Serhiy Storchaka e3ef400be7
gh-74696: Pass root_dir to custom archivers which support it (GH-94251)
Co-authored-by: Éric <merwok@netwok.org>
2022-10-05 12:48:59 +03:00
Irit Katriel c529b45122
gh-87092: bring compiler code closer to a preprocessing-opt-assembler organisation (GH-97644) 2022-10-05 08:52:35 +01:00
Guido van Rossum 8079bef56f
GH-96704: Add {Task,Handle}.get_context(), use it in call_exception_handler() (#96756)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-10-04 23:49:10 -07:00
andrei kulakov db64fb9bbe
gh-97825: fix AttributeError when calling subprocess.check_output(input=None) with encoding or errors args (#97826)
* fix AttributeError, add unit test
2022-10-04 17:47:49 -07:00
Mark Shannon 76449350b3
GH-91079: Decouple C stack overflow checks from Python recursion checks. (GH-96510) 2022-10-05 01:34:03 +01:00
Brandt Bucher 0ff8fd6583
GH-97779: Ensure that *all* frame objects are backed by "complete" frames (GH-97845) 2022-10-04 17:30:03 -07:00
Nikita Sobolev c3648f4e4a
gh-97837: Change deprecation warning message in `unittest` (#97838) 2022-10-04 17:29:18 -07:00
Ev2geny 743453a554
gh-58451: Add optional delete_on_close parameter to NamedTemporaryFile (GH-97015) 2022-10-04 23:37:33 +01:00
Łukasz Langa bbc7cd649a
gh-97008: Add a Python implementation of AttributeError and NameError suggestions (#97022)
Relevant tests moved from test_exceptions to test_traceback to be able to
compare both implementations.

Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
2022-10-04 15:31:16 -07:00
Oleg Iarygin ce8fc186ac
gh-93357: Start porting asyncio server test cases to IsolatedAsyncioTestCase (#93369)
Lay the foundation for further work in `asyncio.test_streams`.
2022-10-04 10:56:47 -07:00
Nikita Sobolev 4f380db1a5
gh-96142: add missing params to `dataclass._DataclassParams` (gh-96382) 2022-10-04 09:53:28 -07:00
Victor Stinner 116fa62c6e
gh-97670: Remove sys.getdxp() and analyze_dxp.py script (#97671)
Remove the sys.getdxp() function and the Tools/scripts/analyze_dxp.py
script. DXP stands for "dynamic execution pairs". They were related
to DYNAMIC_EXECUTION_PROFILE and DXPAIRS macros which have been
removed in Python 3.11. Python can now be built with "./configure
--enable-pystats" to gather statistics on Python opcodes.
2022-10-04 15:28:57 +02:00
Victor Stinner 6cbbc26a73
gh-97669: Remove outdated example scripts (#97675)
Remove outdated example scripts of the Tools/scripts/ directory. A
copy can be found in the old-demos project:
https://github.com/gvanrossum/old-demos

Removed scripts (39):

* byext.py
* byteyears.py
* cleanfuture.py
* copytime.py
* crlf.py
* db2pickle.py
* dutree.doc
* dutree.py
* find-uname.py
* find_recursionlimit.py
* finddiv.py
* findlinksto.py
* findnocoding.py
* fixcid.py
* fixdiv.py
* fixheader.py
* fixnotice.py
* fixps.py
* get-remote-certificate.py
* google.py
* highlight.py
* ifdef.py
* import_diagnostics.py
* lfcr.py
* linktree.py
* lll.py
* mailerdaemon.py
* make_ctype.py
* mkreal.py
* objgraph.py
* pdeps.py
* pickle2db.py
* pindent.py
* pysource.py
* reindent-rst.py
* rgrep.py
* suff.py
* texi2html.py
* which.py

Changes:

* Remove test_fixcid, test_lll, test_pdeps and test_pindent
  of test.test_tools.
* Remove get-remote-certificate.py changelog entry, since the script
  was removed.

Note: there is a copy of crlf.py in Lib/test/test_lib2to3/data/.
2022-10-04 10:49:00 +02:00
Benjamin Peterson 9e8b86de4e
Remove space. (GH-97807)
Automerge-Triggered-By: GH:benjaminp
2022-10-03 17:12:36 -07:00
Brandt Bucher 93fcc1f413
GH-97752: Clear the `previous` member of newly-created generator/coroutine frames (GH-97795) 2022-10-04 00:36:52 +01:00
Gregory P. Smith b0f89cb431
gh-96512: Move int_max_str_digits setting to PyConfig (#96944)
It had to live as a global outside of PyConfig for stable ABI reasons in
the pre-3.12 backports.

This removes the `_Py_global_config_int_max_str_digits` and gets rid of
the equivalent field in the internal `struct _is PyInterpreterState` as
code can just use the existing nested config struct within that.

Adds tests to verify unique settings and configs in subinterpreters.
2022-10-03 13:55:45 -07:00
Michael Droettboom cfbc7dd910
gh-94808: Coverage: Check picklablability of calliter (#95923) 2022-10-03 13:50:30 -07:00
MonadChains 9302e331c7
gh-94808: Add test coverage for PyObject_HasAttrString (#96627)
* gh-94808: Add test for HasAttrString

* Harmonize to Python C code style guidelines

* Add check to verify no exception thrown
2022-10-03 13:37:15 -07:00
Serhiy Storchaka 0ee9619a4c
gh-97728: Argument Clinic: Fix uninitialized variable in the Py_UNICODE converter (GH-97729)
It affects function os.system() on Windows and Windows-specific modules
winreg, _winapi, _overlapped, and _msi.
2022-10-03 10:42:54 +03:00
Koki Saito 19ca114645
gh-96819: multiprocessing.resource_tracker: check if length of pipe write <= 512 (#96890)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-10-02 17:41:01 -07:00
Koki Saito 14d4f68ebb
gh-97706: multiprocessing tests: Delete unused variable `rand` (#97707) 2022-10-02 17:37:36 -07:00
Ofey Chan d639438609
gh-97591: In `Exception.__setstate__()` acquire strong references before calling `tp_hash` slot (#97700) 2022-10-01 20:57:17 -07:00
Łukasz Langa f00645d5db
gh-90908: Document asyncio.Task.cancelling() and asyncio.Task.uncancel() (#95253)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2022-10-01 10:42:36 -07:00
Guido van Rossum 63780f4599
GH-97592: Fix crash in C remove_done_callback due to evil code (#97660)
Evil code could cause fut_callbacks to be cleared when PyObject_RichCompareBool is called.
2022-09-30 12:57:09 -07:00
Ofey Chan 83a3de4e06
gh-96348: Deprecate the 3-arg signature of coroutine.throw and generator.throw (GH-96428) 2022-09-30 09:43:02 +01:00
Victor Stinner a5f092f3c4
gh-97616: list_resize() checks for integer overflow (#97617)
Fix multiplying a list by an integer (list *= int): detect the
integer overflow when the new allocated length is close to the
maximum size.  Issue reported by Jordan Limor.

list_resize() now checks for integer overflow before multiplying the
new allocated length by the list item size (sizeof(PyObject*)).
2022-09-29 00:07:07 +02:00
Pablo Galindo Salgado aab01e3524
gh-96670: Raise SyntaxError when parsing NULL bytes (#97594) 2022-09-27 23:23:42 +01:00
Serhiy Storchaka adbed2d542
gh-73588: Fix generation of the default name of tkinter.Checkbutton. (GH-97547)
Previously, checkbuttons in different parent widgets could have the same
short name and share the same state if arguments "name" and "variable" are
not specified. Now they are globally unique.
2022-09-27 14:05:05 +03:00
Cyker Way 68c46ae68b
gh-97545: Make Semaphore run faster. (#97549) 2022-09-26 16:38:00 -07:00
Michael Curran d79dd929ac
bpo-38748: Add ctypes test for stack corruption due to misaligned arguments (GH-26204) 2022-09-26 17:27:44 +01:00
Victor Stinner 41351662bc
gh-96848: Fix -X int_max_str_digits option parsing (#96988)
Fix command line parsing: reject "-X int_max_str_digits" option with
no value (invalid) when the PYTHONINTMAXSTRDIGITS environment
variable is set to a valid limit.
2022-09-26 17:20:08 +02:00
Dennis Sweeney 05c92759b6
Reject invalid opcode names in assertInBytecode (GH-97548) 2022-09-25 20:55:53 +01:00
Kumar Aditya c8c0afc713
GH-78724: Initialize struct.Struct in __new__ (GH-94532)
Closes https://github.com/python/cpython/issues/75960
Closes https://github.com/python/cpython/issues/78724
2022-09-25 14:32:48 +01:00
Serhiy Storchaka db39050396
gh-96959: Update HTTP links which are redirected to HTTPS (GH-96961) 2022-09-24 14:38:53 +03:00
Michael Droettboom f00383ec9b
gh-94808: Coverage: Test uppercase string literal prefixes (GH-95925) 2022-09-24 13:43:16 +03:00
Steve Dower a4ac14faa5
gh-77171: Fixes SubFormat check to compare the entire value. Add docs (GH-97509) 2022-09-23 16:08:21 +01:00
Cyker Way 24e0379624
gh-90155: Fix bug in asyncio.Semaphore and strengthen FIFO guarantee (#93222)
The main problem was that an unluckily timed task cancellation could cause
the semaphore to be stuck. There were also doubts about strict FIFO ordering
of tasks allowed to pass.

The Semaphore implementation was rewritten to be more similar to Lock.
Many tests for edge cases (including cancellation) were added.
2022-09-22 09:34:45 -07:00
Brandt Bucher 8fd2c3b75b
GH-96975: Skip incomplete frames in PyEval_GetFrame (GH-97003) 2022-09-22 09:16:52 -07:00
Batuhan Taskaya 5a32eeced2
gh-96954: Add tests for unicodedata.name/lookup (#96955)
They were undertested, and since #96954 might involve a
rewrite of this part of the code we want to ensure that
there won't be any behavioral change.

Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
2022-09-21 14:52:40 +02:00
Nikita Sobolev 57463d43dc
gh-90808: add more examples to `test_sched.test_priority` (#31144) 2022-09-20 18:34:13 -07:00
Nikita Sobolev 9b58eaf98c
gh-95591: [Enum] use `_FlagTests` base class (GH-96475) 2022-09-20 16:08:39 -07:00
Brandt Bucher dfc73b5724
GH-95921: Fix positions for some chained comparisons (GH-96968) 2022-09-20 12:22:24 -07:00
serge-sans-paille fc05107af9
gh-96711: Enhance SystemError message upon Invalid opcode (#96712)
Raise verbose SystemError instead of printing debug information
upon Invalid opcode.

Fix #96711
2022-09-20 12:00:34 +02:00
Gregory P. Smith e61ca22431
gh-95865: Further reduce quote_from_bytes memory consumption (#96860)
on large input values.  Based on Dennis Sweeney's chunking idea.
2022-09-19 16:06:25 -07:00
Brandt Bucher c10e33ac11
GH-96864: Check for error between line and opcode events (GH-96880) 2022-09-19 14:02:24 -07:00
Guido van Rossum 487135a396
Revert "gh-87079: Warn on unintended signal wakeup fd override in `asyncio` (#96807)" (#96898)
This reverts commit 0587810698.
Reason: This broke buildbots (some warnings added by that commit are turned to errors in the SSL buildbot).
Repro:  ./python Lib/test/ssltests.py
2022-09-17 14:12:45 -07:00
Lysandros Nikolaou 7e36abbb78
gh-91210: Improve error message when non-default param follows default (GH-95933)
- Improve error message when parameter without a default follows one with a default
- Show same error message when positional-only params precede the default/non-default sequence
2022-09-17 10:09:28 -07:00
Michel Hidalgo 0587810698
gh-87079: Warn on unintended signal wakeup fd override in `asyncio` (#96807)
Warn on loop initialization, when setting the wakeup fd disturbs a previously set wakeup fd, and on loop closing, when upon resetting the wakeup fd, we find it has been changed by someone else.
2022-09-17 08:07:54 -07:00
Serhiy Storchaka 426d72e7dd
gh-96052: codeop: fix handling compiler warnings in incomplete input (GH-96132)
Previously codeop.compile_command() emitted compiler warnings (SyntaxWarning or
DeprecationWarning) and raised a SyntaxError for incomplete input containing
a potentially incorrect code. Now it always returns None for incomplete input
without emitting any warnings.
2022-09-16 17:37:30 +03:00
Dennis Sweeney 303bd88047
Fix ResourceWarning in test.test_frame (GH-96831) 2022-09-15 18:31:45 +01:00
adphrost a41ed975e8
GH-91049: Introduce set vectorcall field API for PyFunctionObject (GH-92257)
Co-authored-by: Andrew Frost <adfrost@fb.com>
Co-authored-by: Itamar Ostricher <itamarost@gmail.com>
2022-09-15 16:42:37 +01:00
Nikita Sobolev e37ac5fbb6
gh-96751: Remove dead code from `CALL_FUNCTION_EX` opcode (GH-96752) 2022-09-15 10:33:13 +01:00
Yusuke Kadowaki 92338f8f19
gh-77171 Support WAVE_FORMAT_EXTENSIBLE in the wave module (GH-96777)
The test file, a modified version of Lib/test/audiodata/pluck-pcm24.wav, was provided by Andrea Celletti on the bug tracker.

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
2022-09-14 14:34:40 +01:00
Nikita Sobolev f2d749a2c2
gh-96784: Cover more typing special forms in `get_args()` (#96791) 2022-09-13 19:35:52 -07:00
Nikita Sobolev 9b3d2d008a
gh-96769: Cover more typing special forms to be unsubclassable (#96772) 2022-09-13 19:35:16 -07:00
Benjamin Peterson fd1e477f53
closes gh-96734: Update to Unicode 15.0.0. (GH-96809) 2022-09-13 15:45:12 -07:00
Dennis Sweeney 69d9a08099
gh-94808: improve comments and coverage of fastsearch.h (GH-96760) 2022-09-13 14:25:10 -04:00
Irit Katriel 6d7a0e0dd7
gh-87092: reduce redundancy and repetition in compiler's optimization stage (GH-96713) 2022-09-13 13:03:41 +01:00
Christian Heimes 1fc8bd3710
gh-95853: Multiple ops and debug for wasm_build.py (#96744) 2022-09-11 09:51:23 +02:00
Dong-hee Na 8d75a13fde
gh-90751: memoryview now supports half-float (#96738)
Co-authored-by: Antoine Pitrou <antoine@python.org>
2022-09-10 22:44:10 +02:00
Gregory P. Smith 11e3548fd1
gh-96710: Make the test timing more lenient for the int/str DoS regression test. (#96717)
A regression would still absolutely fail and even a flaky pass isn't
harmful as it'd fail most of the time across our N system test runs.

Windows has a low resolution timer and CI systems are prone to odd
timing so this just gives more leeway to avoid flakiness.
2022-09-09 12:51:34 -07:00
Dennis Sweeney 569ca27293
gh-96624: Fix test_dotted_but_module_not_loaded in testpatch.py (GH-96691)
* Update test_dotted_but_module_not_loaded to reflect the move of unittest.test to test.test_unittest.
2022-09-08 23:46:13 -04:00
Guido van Rossum df50938f58
GH-46412: More efficient bool() for ndbm/_gdbmmodule (#96692) 2022-09-08 19:32:40 -07:00
Steve Dower 95d6330a3e
gh-96684: Silently suppress COM security errors in _wmi module (GH-96690) 2022-09-08 22:02:04 +01:00
Zachary Ware 9c8f379433
gh-96465: Clear fractions hash lru_cache under refleak testing (GH-96689)
Automerge-Triggered-By: GH:zware
2022-09-08 11:52:07 -07:00
finefoot c06c001b30
gh-92734: Add indentation feature to reprlib.Repr (GH-92735) 2022-09-08 13:51:44 -05:00
Mark Shannon aa3b4cf779
GH-96636: Remove all uses of NOTRACE_DISPATCH (GH-96643)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
2022-09-08 17:16:48 +01:00
philg314 b9634ac776
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (#96353) 2022-09-08 12:12:14 +01:00
Michael Droettboom 8bc356a7dd
gh-96268: Fix loading invalid UTF-8 (#96270)
This makes tokenizer.c:valid_utf8 match stringlib/codecs.h:decode_utf8.

It also fixes an off-by-one error introduced in 3.10 for the line number when the tokenizer reports bad UTF8.
2022-09-07 14:23:54 -07:00
Steve Dower de33df27aa
gh-89545: Updates platform module to use new internal _wmi module on Windows to directly query OS properties (GH-96289) 2022-09-07 21:09:20 +01:00
Michael Droettboom dde15f5879
gh-94808: Improve coverage of _PyBytes_FormatEx (GH-95895)
There were two specific areas not covered:

- %(name) syntax
- %*s syntax

Automerge-Triggered-By: GH:iritkatriel
2022-09-07 04:51:50 -07:00
Dennis Sweeney 56d9cf7fc8
gh-96538: Fix refleak in _bisectmodule.c (gh-96619) 2022-09-06 19:37:18 -04:00
Michael Droettboom 05692c67c5
gh-96611: Fix error message for invalid UTF-8 in mid-multiline string (#96623) 2022-09-07 00:12:16 +01:00
Mark Shannon 95e271b226
GH-96612: Skip incomplete frames in tracemalloc traces. (GH-96613) 2022-09-06 17:37:47 +01:00
Jelle Zijlstra f0d9136c69
gh-96478: Fix new test when run in refleak mode (#96615)
./python.exe -m test -R : test.test_typing would fail, apparently
because the dictionary used in the @patch decorator was modified.
2022-09-06 09:33:09 -07:00
Nikita Sobolev f177f6f29b
gh-96478: Test `@overload` on C functions (#96479)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2022-09-05 14:35:05 -07:00
Jason R. Coombs 52fe7e50c9
gh-93963: Remove ResourceReaderDefaultsTests (GH-96598)
Automerge-Triggered-By: GH:jaraco
2022-09-05 12:37:51 -07:00
Steve Dower 80a9bd2e94
gh-96559: Fixes Windows launcher handling of defaults using old-style tags, and adds What's New section (GH-96595) 2022-09-05 20:06:30 +01:00
Shantanu 200c9a8da0
gh-92986: Fix ast.unparse when ImportFrom.level is None (#92992)
This doesn't happen naturally, but is allowed by the ASDL and compiler.
We don't want to change ASDL for backward compatibility reasons
(#57645, #92987)
2022-09-05 20:14:50 +03:00
Nikita Sobolev 2c7d2e8d46
gh-96587: Raise `SyntaxError` for PEP654 on older `feature_version` (#96588) 2022-09-05 17:54:09 +01:00
Pamela Fox a0ad63e70e
gh-93973: Add all_errors to asyncio.create_connection (#93974)
Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
2022-09-04 18:33:50 -07:00
Mark Dickinson b126196838
gh-95778: Correctly pre-check for int-to-str conversion (#96537)
Converting a large enough `int` to a decimal string raises `ValueError` as expected. However, the raise comes _after_ the quadratic-time base-conversion algorithm has run to completion. For effective DOS prevention, we need some kind of check before entering the quadratic-time loop. Oops! =)

The quick fix: essentially we catch _most_ values that exceed the threshold up front. Those that slip through will still be on the small side (read: sufficiently fast), and will get caught by the existing check so that the limit remains exact.

The justification for the current check. The C code check is:
```c
max_str_digits / (3 * PyLong_SHIFT) <= (size_a - 11) / 10
```

In GitHub markdown math-speak, writing $M$ for `max_str_digits`, $L$ for `PyLong_SHIFT` and $s$ for `size_a`, that check is:
$$\left\lfloor\frac{M}{3L}\right\rfloor \le \left\lfloor\frac{s - 11}{10}\right\rfloor$$

From this it follows that
$$\frac{M}{3L} < \frac{s-1}{10}$$
hence that
$$\frac{L(s-1)}{M} > \frac{10}{3} > \log_2(10).$$
So
$$2^{L(s-1)} > 10^M.$$
But our input integer $a$ satisfies $|a| \ge 2^{L(s-1)}$, so $|a|$ is larger than $10^M$. This shows that we don't accidentally capture anything _below_ the intended limit in the check.

<!-- gh-issue-number: gh-95778 -->
* Issue: gh-95778
<!-- /gh-issue-number -->

Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
2022-09-04 09:21:18 -07:00
Sergey B Kirpichev 8464b754c4
gh-68163: Correct conversion of Rational instances to float (GH-25619)
* gh-68163: Correct conversion of Rational instances to float

Also document that numerator/denominator properties are instances of Integral.

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2022-09-04 13:15:59 +01:00
Charlie Zhao 9b9394df5f
gh-93884: Improve test coverage of `PyNumber_ToBase` (GH-93932)
Link to #93884 
* Test with some large negative and positive values(out of range of a longlong,i.e.[-2\*\*63, 2\*\*63-1])
* Test with objects of non-int type

Automerge-Triggered-By: GH:mdickinson
2022-09-04 03:37:04 -07:00
Vinay Sajip ac4ddab405
gh-90195: Unset logger disabled flag when configuring it. (GH-96530) 2022-09-03 13:38:38 +01:00
Serhiy Storchaka 16c6759b37
gh-45108: Improve docstring and testing of ZipFile.testfile() (GH-96233) 2022-09-03 08:58:25 +03:00
Gregory P. Smith 511ca94520
gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96499)
Integer to and from text conversions via CPython's bignum `int` type is not safe against denial of service attacks due to malicious input. Very large input strings with hundred thousands of digits can consume several CPU seconds.

This PR comes fresh from a pile of work done in our private PSRT security response team repo.

Signed-off-by: Christian Heimes [Red Hat] <christian@python.org>
Tons-of-polishing-up-by: Gregory P. Smith [Google] <greg@krypto.org>
Reviews via the private PSRT repo via many others (see the NEWS entry in the PR).

<!-- gh-issue-number: gh-95778 -->
* Issue: gh-95778
<!-- /gh-issue-number -->

I wrote up [a one pager for the release managers](https://docs.google.com/document/d/1KjuF_aXlzPUxTK4BMgezGJ2Pn7uevfX7g0_mvgHlL7Y/edit#). Much of that text wound up in the Issue. Backports PRs already exist. See the issue for links.
2022-09-02 09:35:08 -07:00
Raymond Hettinger 656167db81
Allow whitespace around a slash in fraction string inputs (GH-96496) 2022-09-02 11:10:58 -05:00
Irit Katriel 4c72517cad
gh-93554: Conditional jump opcodes only jump forward (GH-96318) 2022-09-01 21:36:47 +01:00
Irit Katriel 894cafd9a5
gh-93678: apply remove_redundant_jumps in optimize_cfg (GH-96274) 2022-09-01 11:03:52 +01:00
Gregory P. Smith e93d1bda77
gh-96143: subprocess API %s/universal_newlines=/text=/g. (GH-96468)
minor missed test cleanup to use the modern API from the big review.

Automerge-Triggered-By: GH:gpshead
2022-09-01 02:47:40 -07:00
Anh71me 0cd33e11fe
GH-96079 Fix missing field name for _AnnotatedAlias (#96080) 2022-08-31 16:02:24 -07:00
Vinay Sajip 29f1b0bb1f
gh-89258: Add a getChildren() method to logging.Logger. (GH-96444)
Co-authored-by: Éric <merwok@netwok.org>
2022-08-31 10:50:29 +01:00
Filip Łajszczak 02dbb362d3
gh-96408: Test set operation on items dict view. (GH-96438) 2022-08-30 17:43:23 -05:00
Pablo Galindo Salgado f49dd54b72
gh-96143: Add some comments and minor fixes missed in the original PR (#96433)
* gh-96132: Add some comments and minor fixes missed in the original PR

* Update Doc/using/cmdline.rst

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-08-30 19:37:22 +01:00
Alexandru Mărășteanu 0ed778835d
gh-95149: Enhance `http.HTTPStatus` with properties that indicate the HTTP status category (GH-95453) 2022-08-30 11:11:44 -07:00
Nikita Sobolev 4217393aee
gh-95987: Fix `repr` of `Any` type subclasses (#96412) 2022-08-30 10:36:16 -07:00
Pablo Galindo Salgado 6d791a9736
gh-96143: Allow Linux perf profiler to see Python calls (GH-96123)
⚠️  ⚠️ Note for reviewers, hackers and fellow systems/low-level/compiler engineers ⚠️ ⚠️ 

If you have a lot of experience with this kind of shenanigans and want to improve the **first** version, **please make a PR against my branch** or **reach out by email** or **suggest code changes directly on GitHub**. 

If you have any **refinements or optimizations** please, wait until the first version is merged before starting hacking or proposing those so we can keep this PR productive.
2022-08-30 10:11:18 -07:00
Nikita Sobolev 75177358a6
gh-96385: Correctly raise error on `[*T, *V]` substitution (GH-96386) 2022-08-30 10:34:55 +03:00
Kumar Aditya e5b2453e61
GH-74116: Allow multiple drain waiters for asyncio.StreamWriter (GH-94705) 2022-08-29 11:31:11 -07:00
Nikita Sobolev 675e3470cc
gh-96357: Improve `typing.get_overloads` coverage (#96358) 2022-08-28 17:45:24 -07:00
Nikita Sobolev 1c01bd28a0
gh-95950: Add a test for both `csv.Dialect` and `kwargs` (#95951) 2022-08-28 17:43:32 -07:00
TW 023c51d9d8
gh-69142: add %:z strftime format code (gh-95983)
datetime.isoformat generates the tzoffset with colons, but there
was no format code to make strftime output the same format.

for simplicity and consistency the %:z formatting behaves mostly
as %z, with the exception of adding colons. this includes the
dynamic behaviour of adding seconds and microseconds only when
needed (when not 0).

this fixes the still open "generate" part of this issue:

https://github.com/python/cpython/issues/69142

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-08-28 14:27:42 -07:00
Vinay Sajip 6fbd889d6e
gh-89047: Fix msecs computation so you never end up with 1000 msecs. (GH-96340) 2022-08-27 13:33:24 +01:00
Irit Katriel ccf94a6289
gh-96280: suppress deprecation warning in test_importlib (GH-96281) 2022-08-26 22:44:33 +01:00
Carl Friedrich Bolz-Tereick 9c197bc8bf
GH-96172 fix unicodedata.east_asian_width being wrong on unassigned code points (#96207) 2022-08-26 19:29:39 +03:00
Kristján Valur Jónsson 771eff21a0
Port regression test for issue GH-93592 (GH-96208) 2022-08-26 15:07:31 +01:00
Irit Katriel 1e743616ac
gh-96276: suppress SyntaxWarning in test_compile (GH-96277) 2022-08-25 22:23:06 +01:00
Michael Droettboom ce1e73fbfd
gh-96272: Replace `test_source_encoding`'s `test_pep263` with `test_import_encoded_module` from `test_imp` (GH-96275)
Editors don't agree that `test_source_encoding.py` was valid koi8-r, making it
hard to edit that file without the editor breaking it in some way (see gh-96272).

Only one test actually relied on the koi8-r encoding and it was a duplicate of a
test from the deprecated `imp` module's `test_imp`, so here we replace
`test_pep263` with `test_import_encoded_module` stolen from `test_imp` and
set `test_source_encoding.py`'s encoding to utf-8 to make editing it easier
going forward.
2022-08-25 14:19:16 -05:00
Harry ad7340e8c5
gh-92445 Improve interaction between nargs="*" and choices() (GH-92565) 2022-08-25 06:18:38 -05:00
Sam Ezeh cd492d43a2
gh-76728: Coerce DictReader and DictWriter fieldnames argument to a list (GH-32225) 2022-08-25 05:13:24 -05:00
Ross Burton df11012697
gh-95243: Mitigate the race condition in testSockName (#96173)
find_unused_port() has an inherent race condition, but we can't use
bind_port() as that uses .getsockname() which this test is exercising.

Try binding to unused ports a few times before failing.

Signed-off-by: Ross Burton <ross.burton@arm.com>
2022-08-24 18:37:18 -07:00
Pablo Galindo Salgado e34c82abeb
GH-93503: Add thread-specific APIs to set profiling and tracing functions in the C-API (#93504)
* gh-93503: Add APIs to set profiling and tracing functions in all threads in the C-API

* Use a separate API

* Fix NEWS entry

* Add locks around the loop

* Document ignoring exceptions

* Use the new APIs in the sys module

* Update docs
2022-08-24 23:21:39 +01:00
Serhiy Storchaka 4de06e3cc0
gh-96021: Explicitly close the IsolatedAsyncioTestCase runner in tests (GH-96135)
Tests for IsolatedAsyncioTestCase.debug() rely on the runner be closed
in __del__. It makes tests depending on the GC an unreliable on other
implementations. It is better to close the runner explicitly even if
currently there is no a public API for this.
2022-08-24 15:07:20 +03:00
Irit Katriel 420f39f457
gh-93678: add _testinternalcapi.optimize_cfg() and test utils for compiler optimization unit tests (GH-96007) 2022-08-24 11:02:53 +01:00
Raymond Hettinger 1f0eafa844
GH-96145: Add AttrDict to JSON module for use with object_hook (#96146) 2022-08-23 16:22:00 -05:00
Michael Droettboom 054328f0dd
gh-96189: Fix test_invalid_utf8 on a number of build bots (GH-96190)
The clearing of the temporary directory is not working on some platforms and
leaving behind files.

This has been updated to use the pattern in test_cmd_line.py [1] using the
special TESTFN rather than a test directory.

[1] https://github.com/python/cpython/blob/main/Lib/test/test_cmd_line.py#L559
2022-08-23 13:52:55 -07:00
Kevin Kirsche 58f6953d6d
gh-96175: add missing self._localName assignment in `xml.dom.minidom.Attr` (#96176)
X-Ref: https://github.com/python/typeshed/pull/8590#discussion_r951473977

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-08-23 09:16:02 -07:00
Jeong YunWon ba7d4b9dc1
gh-96197: Add `del sys.breakpointhook` behavior test (gh-96198) 2022-08-23 17:58:38 +09:00
Kumar Aditya 079baee196
GH-96071: add regression test for #96071 (GH-96137)
Automerge-Triggered-By: GH:ericsnowcurrently
2022-08-22 11:40:23 -07:00
Terry Jan Reedy 216ccacda1
gh-96076: Change test_launcher to use non-admin location for py.ini (GH-96091)
Patch authored by Eryksun.
2022-08-22 17:23:27 +01:00
Christian Heimes 822955c166
gh-96125: Fix sys.thread_info.name on pthread platforms (GH-96126)
Automerge-Triggered-By: GH:tiran
2022-08-19 12:41:25 -07:00
Brandt Bucher 5bfb3c372b
GH-90997: Wrap yield from/await in a virtual try/except StopIteration (GH-96010) 2022-08-19 12:33:44 -07:00
Raymond Hettinger 29c8f80760
GH-95861: Add support for Spearman's rank correlation coefficient (GH-95863) 2022-08-18 13:48:27 -05:00
Dong-hee Na 157aef79b0
gh-95813: Improve HTMLParser from the view of inheritance (#95874)
* gh-95813: Improve HTMLParser from the view of inheritance

* gh-95813: Add unittest

* Address code review
2022-08-18 13:16:33 +02:00
Irit Katriel 1a720c6003
gh-95913: make the new internal classes pdb.ModuleTarget/ScriptTarget private (GH-96053) 2022-08-18 11:16:07 +01:00
Mark Shannon b73e3b6d4a
GH-95589: Dont crash when subclassing extension classes with multiple inheritance (GH-96028)
* Treat tp_weakref and tp_dictoffset like other opaque slots for multiple inheritance.

* Document Py_TPFLAGS_MANAGED_DICT and Py_TPFLAGS_MANAGED_WEAKREF in what's new.
2022-08-17 12:50:53 +01:00
Petr Viktorin 0f2b469ce1
gh-95991: Add some infrastructure for testing Limited API in _testcapi (GH-95992)
- Limited API needs to be enabled per source file
- Some builds don't support Limited API, so Limited API tests must be skipped on those builds
  (currently this is `Py_TRACE_REFS`, but that may change.)
- `Py_LIMITED_API` must be defined before `<Python.h>` is included.

This puts the hoop-jumping in `testcapi/parts.h`, so individual
test files can be relatively simple. (Currently that's only
`vectorcall_limited.c`, imagine more.)
2022-08-17 13:48:43 +02:00
Christian Heimes da0aa518bf
gh-96005: FreeBSD has ENOTCAPABLE, too (GH-96034) 2022-08-17 07:24:53 +02:00