Commit graph

52020 commits

Author SHA1 Message Date
Serhiy Storchaka d9d6909697
gh-115011: Improve support of __index__() in setters of members with unsigned integer type (GH-115029)
Setters for members with an unsigned integer type now support
the same range of valid values for objects that has a __index__()
method as for int.

Previously, Py_T_UINT, Py_T_ULONG and Py_T_ULLONG did not support
objects that has a __index__() method larger than LONG_MAX.

Py_T_ULLONG did not support negative ints. Now it supports them and
emits a RuntimeWarning.
2024-02-11 12:45:58 +02:00
Serhiy Storchaka d2c4baa41f
gh-97928: Partially restore the behavior of tkinter.Text.count() by default (GH-115031)
By default, it preserves an inconsistent behavior of older Python
versions: packs the count into a 1-tuple if only one or none
options are specified (including 'update'), returns None instead of 0.
Except that setting wantobjects to 0 no longer affects the result.

Add a new parameter return_ints: specifying return_ints=True makes
Text.count() always returning the single count as an integer
instead of a 1-tuple or None.
2024-02-11 12:43:14 +02:00
Serhiy Storchaka 5d2794a16b
gh-67837, gh-112998: Fix dirs creation in concurrent extraction (GH-115082)
Avoid race conditions in the creation of directories during concurrent
extraction in tarfile and zipfile.

Co-authored-by: Samantha Hughes <shughes-uk@users.noreply.github.com>
Co-authored-by: Peder Bergebakken Sundt <pbsds@hotmail.com>
2024-02-11 12:38:07 +02:00
Serhiy Storchaka aeffc7f895
gh-79382: Fix recursive glob() with trailing "**" (GH-115134)
Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
2024-02-11 12:24:13 +02:00
Serhiy Storchaka 4a08e7b343
gh-115133: Fix tests for XMLPullParser with Expat 2.6.0 (GH-115164)
Feeding the parser by too small chunks defers parsing to prevent
CVE-2023-52425. Future versions of Expat may be more reactive.
2024-02-11 12:08:39 +02:00
Hood Chatham 4b75032c88
gh-114807: multiprocessing: don't raise ImportError if _multiprocessing is missing (#114808)
`_multiprocessing` is only used under the `if _winapi:` block, this moves the import to be within the `_winapi` ImportError handling try/except for equivalent treatment.
2024-02-11 01:59:50 -08:00
Nikita Sobolev f8e9c57067
gh-115274: Fix direct invocation of testmock/testpatch.py (#115275) 2024-02-11 11:51:25 +03:00
Nikita Sobolev 1f23837277
gh-115249: Fix test_descr with -OO mode (#115250) 2024-02-11 11:00:44 +03:00
Sam Gross 1a6e213877
gh-115258: Temporarily disable test on Windows (#115269)
The "test_shutdown_all_methods_in_many_threads" test times out on the Windows CI.
This skips the test on Windows until we figure out the root cause.
2024-02-11 03:14:25 +00:00
Nikita Sobolev b70a68fbd6
gh-115254: Fix test_property with -00 mode (#115255) 2024-02-11 00:51:05 +03:00
Nikita Sobolev 33f56b7432
gh-115252: Fix test_enum with -OO mode (GH-115253) 2024-02-10 10:34:22 -08:00
Barney Gale 6f93b4df92
GH-115060: Speed up pathlib.Path.glob() by removing redundant regex matching (#115061)
When expanding and filtering paths for a `**` wildcard segment, build an `re.Pattern` object from the subsequent pattern parts, rather than the entire pattern, and match against the `os.DirEntry` object prior to instantiating a path object. Also skip compiling a pattern when expanding a `*` wildcard segment.
2024-02-10 18:12:34 +00:00
Mike Zimin 9d1a353230
gh-114894: add array.array.clear() method (#114919)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-02-10 07:59:46 -08:00
Kirill Podoprigora 5319c66550
gh-102840: Fix confused traceback when floordiv or mod operations happens between Fraction and complex objects (GH-102842) 2024-02-10 16:37:19 +02:00
Serhiy Storchaka 597fad07f7
gh-115059: Remove debugging code in test_io (GH-115240) 2024-02-10 13:17:33 +00:00
Serhiy Storchaka e2c4038924
gh-76763: Make chr() always raising ValueError for out-of-range values (GH-114882)
Previously it raised OverflowError for very large or very small values.
2024-02-10 12:21:35 +02:00
Nikita Sobolev e19103a346
gh-114552: Update __dir__ method docs: it allows returning an iterable (#114662) 2024-02-10 08:34:23 +00:00
Laurie O b2d9d134dc
gh-96471: Add shutdown() method to queue.Queue (#104750)
Co-authored-by: Duprat <yduprat@gmail.com>
2024-02-09 20:58:30 -08:00
dave-shawley 564385612c
gh-115165: Fix typing.Annotated for immutable types (#115213)
The return value from an annotated callable can raise any exception from
__setattr__ for the `__orig_class__` property.
2024-02-09 22:11:37 +00:00
Sam Gross a3af3cb4f4
gh-110481: Implement inter-thread queue for biased reference counting (#114824)
Biased reference counting maintains two refcount fields in each object:
`ob_ref_local` and `ob_ref_shared`. The true refcount is the sum of these two
fields. In some cases, when refcounting operations are split across threads,
the ob_ref_shared field can be negative (although the total refcount must be
at least zero). In this case, the thread that decremented the refcount
requests that the owning thread give up ownership and merge the refcount
fields.
2024-02-09 17:08:32 -05:00
Carl Meyer a225520af9
gh-112903: Handle non-types in _BaseGenericAlias.__mro_entries__() (#115191)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-02-09 12:19:09 -07:00
Kirill Podoprigora f8931adc59
gh-115142: Skip test_optimizer if _testinternalcapi module is not available (GH-115175) 2024-02-09 18:59:41 +02:00
Serhiy Storchaka 846fd721d5
gh-115059: Flush the underlying write buffer in io.BufferedRandom.read1() (GH-115163) 2024-02-09 12:36:12 +02:00
Shantanu 17689e3c41
gh-107944: Improve error message for getargs with bad keyword arguments (#114792) 2024-02-08 01:04:41 -08:00
Justin Applegate 4a7f63869a
gh-115146: Fix typo in pickletools.py documentation (GH-115148) 2024-02-08 10:12:58 +02:00
Carl Meyer fedbf77191
gh-114828: Fix __class__ in class-scope inlined comprehensions (#115139) 2024-02-07 16:56:16 +00:00
Mark Shannon 8a3c499ffe
GH-108362: Revert "GH-108362: Incremental GC implementation (GH-108038)" (#115132)
Revert "GH-108362: Incremental GC implementation (GH-108038)"

This reverts commit 36518e69d7.
2024-02-07 12:38:34 +00:00
Sam Gross b6228b521b
gh-115035: Mark ThreadHandles as non-joinable earlier after forking (#115042)
This marks dead ThreadHandles as non-joinable earlier in
`PyOS_AfterFork_Child()` before we execute any Python code. The handles
are stored in a global linked list in `_PyRuntimeState` because `fork()`
affects the entire process.
2024-02-06 14:45:04 -05:00
Artem Mukhin 71239d50b5
gh-103224: Resolve paths properly in test_sysconfig (GH-103292)
To pass tests when executed through a Python symlink.

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
2024-02-06 19:32:07 +00:00
Matthieu Caneill 76108b8b05
#gh-75705: Set unixfrom envelope in mailbox._mboxMMDF (GH-107117) 2024-02-06 20:44:12 +02:00
Sam Gross de61d4bd4d
gh-112066: Add PyDict_SetDefaultRef function. (#112123)
The `PyDict_SetDefaultRef` function is similar to `PyDict_SetDefault`,
but returns a strong reference through the optional `**result` pointer
instead of a borrowed reference.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-02-06 11:36:23 -05:00
Nikita Sobolev d7334e2c20
gh-106233: Fix stacklevel in zoneinfo.InvalidTZPathWarning (GH-106234) 2024-02-06 15:08:56 +02:00
Mariusz Felisiak 1a10437a14
gh-91602: Add iterdump() support for filtering database objects (#114501)
Add optional 'filter' parameter to iterdump() that allows a "LIKE"
pattern for filtering database objects to dump.

Co-authored-by: Erlend E. Aasland <erlend@python.org>
2024-02-06 12:34:56 +01:00
Barney Gale 1b1f8398d0
GH-106747: Make pathlib ABC globbing more consistent with glob.glob() (#115056)
When expanding `**` wildcards, ensure we add a trailing slash to the
topmost directory path. This matches `glob.glob()` behaviour:

    >>> glob.glob('dirA/**', recursive=True)
    ['dirA/', 'dirA/dirB', 'dirA/dirB/dirC']

This does not affect `pathlib.Path.glob()`, because trailing slashes aren't
supported in pathlib proper.
2024-02-06 02:48:18 +00:00
Serhiy Storchaka bb57ffdb38
gh-83648: Support deprecation of options, arguments and subcommands in argparse (GH-114086) 2024-02-06 00:41:34 +02:00
Serhiy Storchaka 652fbf88c4
gh-82626: Emit a warning when bool is used as a file descriptor (GH-111275) 2024-02-05 22:51:11 +02:00
Erlend E. Aasland 09096a1647
gh-115015: Argument Clinic: fix generated code for METH_METHOD methods without params (#115016) 2024-02-05 21:49:17 +01:00
Serhiy Storchaka 4aa4f0906d
gh-109475: Fix support of explicit option value "--" in argparse (GH-114814)
For example "--option=--".
2024-02-05 22:42:43 +02:00
Mark Shannon 36518e69d7
GH-108362: Incremental GC implementation (GH-108038) 2024-02-05 18:28:51 +00:00
Serhiy Storchaka b4ba0f73d6
gh-43457: Tkinter: fix design flaws in wm_attributes() (GH-111404)
* When called with a single argument to get a value, it allow to omit
  the minus prefix.
* It can be called with keyword arguments to set attributes.
* w.wm_attributes(return_python_dict=True) returns a dict instead of 
  a tuple (it will be the default in future).
* Setting wantobjects to 0 no longer affects the result.
2024-02-05 18:24:54 +02:00
Mark Shannon 992446dd5b
GH-113462: Limit the number of versions that a single class can use. (GH-114900) 2024-02-05 16:20:54 +00:00
Kirill Podoprigora f71bdd3408
gh-115020: Remove a debugging print in test_frame (GH-115021) 2024-02-05 12:20:34 +02:00
Terry Jan Reedy e207cc181f
gh-114628: Display csv.Error without context (#115005)
When cvs.Error is raised when TypeError is caught,
the TypeError display and 'During handling' note is just noise
with duplicate information.  Suppress with 'from None'.
2024-02-04 20:57:54 -05:00
Russell Keith-Magee 391659b3da
gh-114099: Add test exclusions to support running the test suite on iOS (#114889)
Add test annotations required to run the test suite on iOS (PEP 730).

The majority of the change involve annotating tests that use subprocess,
but are skipped on Emscripten/WASI for other reasons, and including
iOS/tvOS/watchOS under the same umbrella as macOS/darwin checks.

`is_apple` and `is_apple_mobile` test helpers have been added to
identify *any* Apple platform, and "any Apple platform except macOS",
respectively.
2024-02-05 01:04:57 +01:00
Serhiy Storchaka 15f6f048a6
gh-114392: Improve test_capi.test_structmembers (GH-114393)
Test all integer member types with extreme values and values outside of
the valid range. Test support of integer-like objects. Test warnings for
wrapped out values.
2024-02-04 22:19:06 +02:00
Nikita Sobolev 929d44e15a
gh-114685: PyBuffer_FillInfo() now raises on PyBUF_{READ,WRITE} (GH-114802) 2024-02-04 19:16:43 +00:00
Dai Wentao da8f9fb2ea
gh-113803: Fix inaccurate documentation for shutil.move when dst is an existing directory (#113837)
* fix the usage of dst and destination in shutil.move doc
* update shutil.move doc
2024-02-04 13:42:58 -05:00
Serhiy Storchaka 7e42fddf60
gh-113951: Tkinter: "tag_unbind(tag, sequence, funcid)" now only unbinds "funcid" (GH-113955)
Previously, "tag_unbind(tag, sequence, funcid)" methods of Text and
Canvas widgets destroyed the current binding for "sequence", leaving
"sequence" unbound, and deleted the "funcid" command.

Now they remove only "funcid" from the binding for "sequence", keeping
other commands, and delete the "funcid" command.
They leave "sequence" unbound only if "funcid" was the last bound command.
2024-02-04 17:49:42 +02:00
Serhiy Storchaka 3ddc515255
gh-114388: Fix warnings when assign an unsigned integer member (GH-114391)
* Fix a RuntimeWarning emitted when assign an integer-like value that
  is not an instance of int to an attribute that corresponds to a C
  struct member of type T_UINT and T_ULONG.
* Fix a double RuntimeWarning emitted when assign a negative integer value
  to an attribute that corresponds to a C struct member of type T_UINT.
2024-02-04 17:32:25 +02:00
Serhiy Storchaka 0ea366240b
gh-113280: Always close socket if SSLSocket creation failed (GH-114659)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2024-02-04 15:28:07 +00:00
Serhiy Storchaka ecabff98c4
gh-113267: Revert "gh-106584: Fix exit code for unittest in Python 3.12 (#106588)" (GH-114470)
This reverts commit 8fc071345b.
2024-02-04 17:27:42 +02:00
Serhiy Storchaka ca715e56a1
gh-69893: Add the close() method for xml.etree.ElementTree.iterparse() iterator (GH-114534) 2024-02-04 17:25:21 +02:00
Serhiy Storchaka fc06096911
gh-83383: Always mark the dbm.dumb database as unmodified after open() and sync() (GH-114560)
The directory file for a newly created database is now created
immediately after opening instead of deferring this until synchronizing
or closing.
2024-02-04 17:23:26 +02:00
Ethan Furman ff7588b729
gh-114071: [Enum] update docs and code for tuples/subclasses (GH-114871)
Update documentation with `__new__` and `__init__` entries.

Support use of `auto()` in tuple subclasses on member assignment lines.  Previously, auto() was only supported on the member definition line either solo or as part of a tuple:

    RED = auto()
    BLUE = auto(), 'azul'

However, since Python itself supports using tuple subclasses where tuples are expected, e.g.:

    from collections import namedtuple
    T = namedtuple('T', 'first second third')

    def test(one, two, three):
        print(one, two, three)

    test(*T(4, 5, 6))
    # 4 5 6

it made sense to also support tuple subclasses in enum definitions.
2024-02-04 07:22:55 -08:00
Stéphane Bidoul a4c298c149
gh-114965: Updated bundled pip to 24.0 (gh-114966)
Updated bundled pip to 24.0
2024-02-03 17:45:09 +00:00
Travis Howse 94ec2b9c9c
gh-114887 Reject only sockets of type SOCK_STREAM in create_datagram_endpoint() (#114893)
Also improve exception message.

Co-authored-by: Donghee Na <donghee.na92@gmail.com>
2024-02-03 17:14:02 +00:00
Kristján Valur Jónsson 6b53d5fe04
gh-112202: Ensure that condition.notify() succeeds even when racing with Task.cancel() (#112201)
Also did a general cleanup of asyncio locks.py comments and docstrings.
2024-02-03 08:19:37 -08:00
Serhiy Storchaka 96bce033c4
gh-114959: tarfile: do not ignore errors when extract a directory on top of a file (GH-114960)
Also, add tests common to tarfile and zipfile.
2024-02-03 16:18:46 +00:00
Jokimax c4a2e8a2c5
gh-101599: argparse: simplify the option help string (GH-103372)
If the option with argument has short and long names,
output argument only once, after the long name:

   -o, --option ARG    description

instead of

   -o ARG, --option ARG    description
2024-02-02 22:13:00 +00:00
Alex Waygood 920b89f627
Bump ruff to 0.2.0 (#114932) 2024-02-02 21:04:15 +00:00
GILGAMESH 7e2703bbff
Update venv activate.bat to escape custom PROMPT variables on Windows (GH-114885) 2024-02-02 18:59:53 +00:00
Sam Gross d0f1307580
gh-114329: Add PyList_GetItemRef function (GH-114504)
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returns
a strong reference instead of a borrowed reference. Additionally, if the
passed "list" object is not a list, the function sets a `TypeError`
instead of calling `PyErr_BadInternalCall()`.
2024-02-02 14:03:15 +01:00
Mark Shannon 0e71a295e9
GH-113710: Add a "globals to constants" pass (GH-114592)
Converts specializations of `LOAD_GLOBAL` into constants during tier 2 optimization.
2024-02-02 12:14:34 +00:00
Irit Katriel 2091fb2a85
gh-107901: make compiler inline basic blocks with no line number and no fallthrough (#114750) 2024-02-02 11:26:31 +00:00
Christopher Chavez d25d4ee60c
gh-103820: IDLE: Do not interpret buttons 4/5 as scrolling on non-X11 (GH-103821)
Also fix test_mousewheel: do not skip a check which was broken due to incorrect
delta on Aqua and XQuartz, and probably not because of `.update_idletasks()`.
2024-02-02 10:38:43 +00:00
Sam Gross 587d480203
gh-112529: Remove PyGC_Head from object pre-header in free-threaded build (#114564)
* gh-112529: Remove PyGC_Head from object pre-header in free-threaded build

This avoids allocating space for PyGC_Head in the free-threaded build.
The GC implementation for free-threaded CPython does not use the
PyGC_Head structure.

 * The trashcan mechanism uses the `ob_tid` field instead of `_gc_prev`
   in the free-threaded build.
 * The GDB libpython.py file now determines the offset of the managed
   dict field based on whether the running process is a free-threaded
   build. Those are identified by the `ob_ref_local` field in PyObject.
 * Fixes `_PySys_GetSizeOf()` which incorrectly incorrectly included the
   size of `PyGC_Head` in the size of static `PyTypeObject`.
2024-02-01 12:29:19 -08:00
Mark Shannon e66d0399cc
GH-114806. Don't specialize calls to classes with metaclasses. (GH-114870) 2024-02-01 19:39:32 +00:00
Ayappan Perumal 4dbb198d27
gh-105089: Fix test_create_directory_with_write test failure in AIX (GH-105228) 2024-02-01 11:52:54 +00:00
Tomas R 0bf42dae7e
gh-107461 ctypes: Add a testcase for nested _as_parameter_ lookup (GH-107462) 2024-02-01 13:49:01 +02:00
Jamie Phan 80aa7b3688
gh-109534: fix reference leak when SSL handshake fails (#114074) 2024-01-31 16:42:17 -08:00
Albert Zeyer 78c254582b
gh-113939: Frame clear, clear locals (#113940) 2024-01-31 19:14:44 +00:00
Nachtalb b905fad838
gh-111741: Recognise image/webp as a standard format in the mimetypes module (GH-111742)
Previously it was supported as a non-standard type.
2024-01-31 17:33:46 +02:00
Tian Gao 765b9ce9fb
gh-59013: Set breakpoint on the first executable line of function when using break func in pdb (#112470) 2024-01-31 13:03:05 +00:00
Sam Gross 66f95ea6a6
gh-114737: Revert change to ElementTree.iterparse "root" attribute (GH-114755)
Prior to gh-114269, the iterator returned by ElementTree.iterparse was
initialized with the root attribute as None. This restores the previous
behavior.
2024-01-31 13:22:24 +02:00
Serhiy Storchaka b7688ef71e
gh-114685: Check flags in PyObject_GetBuffer() (GH-114707)
PyObject_GetBuffer() now raises a SystemError if called with
PyBUF_READ or PyBUF_WRITE as flags. These flags should
only be used with the PyMemoryView_* C API.
2024-01-31 13:11:35 +02:00
Daniel Hollas 5e390a0fc8
gh-109653: Speedup import of threading module (#114509)
Avoiding an import of functools leads to 50% speedup of import time.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-01-31 09:29:44 +00:00
Brett Cannon 2ed8f924ee
GH-114743: Set a low recursion limit for test_main_recursion_error() in test_runpy (GH-114772)
This can fail under a debug build of WASI when directly executing test.test_runpy.
2024-01-31 01:49:27 +00:00
Barney Gale 574291963f
pathlib ABCs: drop partial, broken, untested support for bytes paths. (#114777)
Methods like `full_match()`, `glob()`, etc, are difficult to make work with
byte paths, and it's not worth the effort. This patch makes `PurePathBase`
raise `TypeError` when given non-`str` path segments.
2024-01-31 00:59:33 +00:00
Barney Gale 1667c28686
pathlib ABCs: raise UnsupportedOperation directly. (#114776)
Raise `UnsupportedOperation` directly, rather than via an `_unsupported()`
helper, to give human readers and IDEs/typecheckers/etc a bigger hint that
these methods are abstract.
2024-01-31 00:38:01 +00:00
Serhiy Storchaka dc4cd2c9ba
gh-106392: Fix inconsistency in deprecation warnings in datetime module (GH-114761) 2024-01-30 22:15:33 +00:00
Barney Gale fda7445ca5
GH-70303: Make pathlib.Path.glob('**') return both files and directories (#114684)
Return files and directories from `pathlib.Path.glob()` if the pattern ends
with `**`. This is more compatible with `PurePath.full_match()` and with
other glob implementations such as bash and `glob.glob()`. Users can add a
trailing slash to match only directories.

In my previous patch I added a `FutureWarning` with the intention of fixing
this in Python 3.15. Upon further reflection I think this was an
unnecessarily cautious remedy to a clear bug.
2024-01-30 19:52:53 +00:00
Kirill Podoprigora 6de8aa31f3
`importlib/_bootstrap.py: Reduce size of _List` instances (GH-114747)
Reduce size of _List instances
2024-01-30 10:44:09 -08:00
Pablo Galindo Salgado 39d102c2ee
gh-113744: Add a new IncompleteInputError exception to improve incomplete input detection in the codeop module (#113745)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
2024-01-30 16:21:30 +00:00
Barney Gale 809eed4805
GH-114610: Fix pathlib._abc.PurePathBase.with_suffix('.ext') handling of stems (#114613)
Raise `ValueError` if `with_suffix('.ext')` is called on a path without a
stem. Paths may only have a non-empty suffix if they also have a non-empty
stem.

ABC-only bugfix; no effect on public classes.
2024-01-30 14:25:16 +00:00
Vinay Sajip e21754d7f8
gh-114706: Allow QueueListener.stop() to be called more than once. (GH-114748) 2024-01-30 12:34:18 +00:00
Serhiy Storchaka ea30a28c3e
gh-113732: Fix support of QUOTE_NOTNULL and QUOTE_STRINGS in csv.reader (GH-113738) 2024-01-30 14:21:12 +02:00
Sviatoslav Sydorenko (Святослав Сидоренко) 963904335e
GH-80789: Get rid of the `ensurepip` infra for many wheels (#109245)
Co-authored-by: vstinner@python.org
Co-authored-by: Pradyun Gedam <pradyunsg@gmail.com>
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2024-01-30 01:25:31 +00:00
Matan Perelman 29952c86f3
TaskGroup: Use explicit None check for cancellation error (#114708) 2024-01-29 11:12:33 -08:00
Serhiy Storchaka aa3402ad45
gh-114678: Fix incorrect deprecation warning for 'N' specifier in Decimal format (GH-114683)
Co-authored-by: Stefan Krah <skrah@bytereef.org>
2024-01-29 19:58:31 +02:00
Steven Ward 2c089b09ac
gh-112240: Add option to calendar module CLI to specify the weekday to start each week (GH-112241) 2024-01-29 16:58:21 +00:00
Soumendra Ganguly e351ca3c20
gh-85984: Add POSIX pseudo-terminal functions. (GH-102413)
Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-01-29 16:10:28 +00:00
Steven Ward 0f54ee4c6c
Remove limit in calendar CLI help message for year arg (GH-114719)
The limit was removed in 66c88ce30c (GH-4109).
2024-01-29 18:00:15 +02:00
Petr Viktorin 15fe8cea17
gh-91325: Skip Stable ABI checks with Py_TRACE_REFS special build (GH-92046)
Skip Stable ABI checks with Py_TRACE_REFS special build

This build is not compatible with Py_LIMITED_API nor with
the stable ABI.
2024-01-29 16:45:31 +01:00
Shantanu 2124a3ddcc
gh-109653: Improve import time of importlib.metadata / email.utils (#114664)
My criterion for delayed imports is that they're only worth it if the
majority of users of the module would benefit from it, otherwise you're
just moving latency around unpredictably.

mktime_tz is not used anywhere in the standard library and grep.app
indicates it's not got much use in the ecosystem either.

Distribution.files is not nearly as widely used as other
importlib.metadata APIs, so we defer the csv import.

Before:
```
λ hyperfine -w 8 './python -c "import importlib.metadata"'
Benchmark 1: ./python -c "import importlib.metadata"
  Time (mean ± σ):      65.1 ms ±   0.5 ms    [User: 55.3 ms, System: 9.8 ms]
  Range (min … max):    64.4 ms …  66.4 ms    44 runs
```

After:
```
λ hyperfine -w 8 './python -c "import importlib.metadata"'
Benchmark 1: ./python -c "import importlib.metadata"
  Time (mean ± σ):      62.0 ms ±   0.3 ms    [User: 52.5 ms, System: 9.6 ms]
  Range (min … max):    61.3 ms …  62.8 ms    46 runs
```

for about a 3ms saving with warm disk cache, maybe 7-11ms with cold disk
cache.
2024-01-29 01:30:22 -08:00
Furkan Onder f7c05d7ad3
gh-55664: Add warning when creating a type using a namespace dictionary with non-string keys. (GH-105338)
Co-authored-by: Daniel Urban <durban@users.noreply.github.com>
2024-01-29 01:05:29 +02:00
Ville Skyttä a768e12f09
Use bool in fileinput.input() docstring and tests for the inplace argument (GH-111998)
The `.rst` docs, most tests, and typeshed already use bool for it.
2024-01-27 23:47:55 +02:00
Barney Gale 823a38a960
GH-79634: Speed up pathlib globbing by removing joinpath() call. (#114623)
Remove `self.joinpath('')` call that should have been removed in 6313cdde.

This makes `PathBase.glob('')` yield itself *without* adding a trailing slash. It's hard to say whether this is more or less correct, but at least everything else is faster, and there's no behaviour change in the public classes where empty glob patterns are disallowed.
2024-01-27 19:59:51 +00:00
Serhiy Storchaka 7a470541e2
gh-114100: Remove superfluous writing to fd 1 in test_pty (GH-114647) 2024-01-27 18:38:17 +02:00
NewUserHa 547c135d70
Simplify concurrent.futures.process code by using itertools.batched() (GH-114221) 2024-01-27 10:29:38 +02:00
Barney Gale 2d08af34b8
Cover OS-specific behaviour in PurePathBase and PathBase tests. (#114633)
Wherever possible, move tests for OS-specific behaviour from `PurePathTest`
and `PathTest` to `DummyPurePathTest` and `DummyPathTest`.
2024-01-27 02:16:17 +00:00
Barney Gale fe5905e21a
Cover OS-specific behaviour in PurePath and Path tests (#114632)
Test Posix- and Windows-specific behaviour from `PurePathTest` and `PathTest`.
2024-01-27 01:30:25 +00:00
Barney Gale 7a9727e10c
pathlib tests: annotate tests needing symlinks with decorator (#114625)
Add `@needs_symlinks` decorator for tests that require symlink support in
the path class.

Also add `@needs_windows` and `@needs_posix` decorators for tests that
require a specific a specific path flavour. These aren't much used yet, but
will be later.
2024-01-26 22:29:28 +00:00
Aiden Fox Ivey b5c7c84673
gh-114490: Add check for Mach-O linkage in Lib/platform.py (#114491)
``platform.architecture()`` now returns the format of binaries (e.g. Mach-O) instead of the default empty string.

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-01-26 21:36:50 +01:00
Tristan Pank 07236f5b39
gh-114494: Change logging docstring to bool for exec_info (GH=114558) 2024-01-26 21:48:22 +02:00
Barney Gale 7e31d6dea2
gh-88569: add ntpath.isreserved() (#95486)
Add `ntpath.isreserved()`, which identifies reserved pathnames such as "NUL", "AUX" and "CON".

Deprecate `pathlib.PurePath.is_reserved()`.

---------

Co-authored-by: Eryk Sun <eryksun@gmail.com>
Co-authored-by: Brett Cannon <brett@python.org>
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2024-01-26 18:14:24 +00:00
Steve Dower d91ddff5de
gh-114435: Allow test_stat_inaccessible_file() to have matching ino/dev (GH-114571)
This may occur if Windows allows reading stat information from a file even if the current user does not have access.
2024-01-26 17:33:44 +00:00
Rito Takeuchi 504334c7be
gh-77749: Fix inconsistent behavior of non-ASCII handling in EmailPolicy.fold() (GH-6986)
It now always encodes non-ASCII characters in headers if utf8 is false.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-01-26 15:19:41 +00:00
Steve Dower 442a299af0
gh-114272: Allow _wmi audit test to succeed even if it times out (GH-114602) 2024-01-26 14:38:24 +00:00
Mariusz Felisiak 456e274578
gh-112451: Prohibit subclassing of datetime.timezone. (#114190)
This is consistent with C-extension datetime.timezone.
2024-01-26 09:33:13 +01:00
Barney Gale b69548a0f5
GH-73435: Add pathlib.PurePath.full_match() (#114350)
In 49f90ba we added support for the recursive wildcard `**` in
`pathlib.PurePath.match()`. This should allow arbitrary prefix and suffix
matching, like `p.match('foo/**')` or `p.match('**/foo')`, but there's a
problem: for relative patterns only, `match()` implicitly inserts a `**`
token on the left hand side, causing all patterns to match from the right.
As a result, it's impossible to match relative patterns from the left:
`PurePath('foo/bar').match('bar/**')` is true!

This commit reverts the changes to `match()`, and instead adds a new
`full_match()` method that:

- Allows empty patterns
- Supports the recursive wildcard `**`
- Matches the *entire* path when given a relative pattern
2024-01-26 01:12:46 +00:00
Kirill Podoprigora 33ae9895d4
gh-114561: Mark some tests in `test_wincosoleio with requires_resource('console')` decorator (GH-114565) 2024-01-25 20:00:52 +00:00
Nikita Sobolev d96358ff9d
gh-114315: Make threading.Lock a real class, not a factory function (#114479)
`threading.Lock` is now the underlying class and is constructable rather than the old
factory function. This allows for type annotations to refer to it which had no non-ugly
way to be expressed prior to this.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-01-25 19:46:32 +00:00
Sam Gross b52fc70d1a
gh-112529: Implement GC for free-threaded builds (#114262)
* gh-112529: Implement GC for free-threaded builds

This implements a mark and sweep GC for the free-threaded builds of
CPython. The implementation relies on mimalloc to find GC tracked
objects (i.e., "containers").
2024-01-25 10:27:36 -08:00
Tian Gao 8278fa2f56
gh-111051: Check if file is modifed during debugging in pdb (#111052) 2024-01-25 16:48:50 +00:00
AN Long e721adf4bd
gh-77465: Increase test coverage for the numbers module (GH-111738)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-01-25 16:35:05 +02:00
Irit Katriel 0315941441
gh-114265: remove i_loc_propagated, jump threading does not consider line numbers anymore (#114535) 2024-01-25 12:54:19 +00:00
Michael Droettboom ea3cd0498c
gh-114312: Collect stats for unlikely events (GH-114493) 2024-01-25 11:10:51 +00:00
Steve Dower c63c6142f9
gh-114272: Fix or skip tests that fail due to spaces in paths (GH-114451) 2024-01-25 00:38:34 +00:00
Mark Shannon 981d172f7f
GH-112354: END_FOR instruction to only pop one value. (GH-114247)
* Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
2024-01-24 15:10:17 +00:00
Serhiy Storchaka ce75b4c26d
gh-113205: test_multiprocessing.test_terminate: Give tasks a chance to start (GH-114249) 2024-01-24 09:13:09 +02:00
Brett Cannon f59f90b5bc
GH-114456: lower the recursion limit under WASI for debug builds (GH-114457)
Testing under wasmtime 16.0.0 w/ code from https://github.com/python/cpython/issues/114413 is how the value was found.
2024-01-23 15:48:14 -08:00
Sam Gross ce01ab536f
gh-101438: Avoid reference cycle in ElementTree.iterparse. (GH-114269)
The iterator returned by ElementTree.iterparse() may hold on to a file
descriptor. The reference cycle prevented prompt clean-up of the file
descriptor if the returned iterator was not exhausted.
2024-01-23 20:14:46 +00:00
Nikita Sobolev ba253a4794
gh-108303: Move .whl test files to Lib/test/wheeldata/ (#114343) 2024-01-23 16:33:12 +01:00
Fabio Zadrozny 5a1ecc8cc7
gh-114423: Remove DummyThread from threading._active when thread dies (GH-114424) 2024-01-23 14:12:50 +02:00
Jim Porter 8edc8029de
gh-89427: Provide the original prompt value for VIRTUAL_ENV_PROMPT (GH-106726)
This improves the implementation in gh-106643.

Previously, venv passed "(<prompt>) " to the activation scripts, but we want
to provide the original value so that users can inspect it in the
$VIRTUAL_ENV_PROMPT env var.

Note: Lib/venv/scripts/common/Activate.ps1 surrounded the prompt value with
parens a second time, so no change was necessary in that file.
2024-01-23 08:53:04 +00:00
AN Long 7fc51c3f6b
gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394) 2024-01-22 17:15:29 +00:00
Irit Katriel ed30a3c337
gh-114083: apply optimization of LOAD_CONST instructions to the whole CFG before optimize_basic_block. (#114408) 2024-01-22 17:12:06 +00:00
Serhiy Storchaka a53e56e7d8
gh-75128: Ignore EADDRNOTAVAIL error in asyncio.BaseEventLoop.create_server() (GH-114420)
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
2024-01-22 18:40:35 +02:00
Nikita Sobolev 2ef520ebec
gh-108303: Remove Lib/test/shadowed_super.py (#114372)
Move code into Lib/test/test_super.py.
2024-01-22 16:09:10 +01:00
Serhiy Storchaka 49785b06de
gh-102512: Turn _DummyThread into _MainThread after os.fork() called from a foreign thread (GH-113261)
Always set a _MainThread as a main thread after os.fork() is called from
a thread started not by the threading module.

A new _MainThread was already set as a new main thread after fork if
threading.current_thread() was not called for a foreign thread before fork.
Now, if it was called before fork, the implicitly created _DummyThread will
be turned into _MainThread after fork.

It fixes, in particularly, an incompatibility of _DummyThread with
the threading shutdown logic which relies on the main thread
having tstate_lock.

Co-authored-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2024-01-22 16:14:42 +02:00
Nikita Sobolev 8f5e7d739f
gh-108303: Move smtpd to test.support (#114368)
Update test_logging.py and test_smtplib.py.
2024-01-22 14:36:29 +01:00
Serhiy Storchaka c8351a617b
gh-113796: Add more validation checks in the csv.Dialect constructor (GH-113797)
ValueError is now raised if the same character is used in different roles.
2024-01-22 15:34:16 +02:00
Gregory P. Smith fd49e22670
gh-114328: tty cbreak mode should not alter ICRNL (#114335)
The terminal CR -> NL mapping setting should be inherited in cbreak mode as OSes do not specify altering it as part of their stty cbreak mode definition.
2024-01-21 15:25:52 -08:00
Serhiy Storchaka db1c18eb62
gh-111803: Make test_deep_nesting from test_plistlib more strict (GH-114026)
It is no longer silently passed if RecursionError was raised for low
recursion depth.
2024-01-21 22:29:51 +02:00
Serhiy Storchaka 42d72b23dd
gh-114241: Fix and improve the ftplib CLI (GH-114242)
* Fix writing the retrieved binary file to stdout.
* Add a newline after writing warnings to stderr.
* Fix a TypeError if the netrc file doesn't contain a host/default entry.
* Improve the usage message.
2024-01-21 22:16:45 +02:00
Ronald Oussoren 5adff3f86f
gh-80931: Skip some socket tests while hunting for refleaks on macOS (#114057)
Some socket tests related to sending file descriptors cause a file descriptor leak on macOS, all of them tests that send one or more descriptors than cannot be received on the read end.  This appears to be a platform bug.

This PR skips those tests when doing a refleak test run to avoid hiding other problems.
2024-01-21 11:25:15 +01:00
Hugo van Kemenade 52eade2223
Remove deleted time_hashlib.py from Lib/test/.ruff.toml (#114355) 2024-01-20 14:10:43 -07:00
Gregory P. Smith c48b8f8db8
Remove the non-test Lib/test/time_hashlib.py. (#114354)
I believe I added this while chasing some performance of hash functions
when I first created hashlib.  It hasn't been used since, is frankly
trivial, and not a test.
2024-01-20 12:09:50 -08:00
Nikita Sobolev 0554a9594e
gh-114281: Remove incorrect type hints from asyncio.staggered (#114282)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-01-20 16:49:48 +00:00
Barney Gale 1e610fb05f
GH-113225: Speed up pathlib.Path.walk(top_down=False) (#113693)
Use `_make_child_entry()` rather than `_make_child_relpath()` to retrieve
path objects for directories to visit. This saves the allocation of one
path object per directory in user subclasses of `PathBase`, and avoids a
second loop.

This trick does not apply when walking top-down, because users can affect
the walk by modifying *dirnames* in-place.

A side effect of this change is that, in bottom-up mode, subdirectories of
each directory are visited in reverse order, and that this order doesn't
match that of the names in *dirnames*. I suspect this is fine as the
order is arbitrary anyway.
2024-01-20 03:06:00 +00:00
Barney Gale 6313cdde58
GH-79634: Accept path-like objects as pathlib glob patterns. (#114017)
Allow `os.PathLike` objects to be passed as patterns to `pathlib.Path.glob()` and `rglob()`. (It's already possible to use them in `PurePath.match()`)

While we're in the area:

- Allow empty glob patterns in `PathBase` (but not `Path`)
- Speed up globbing in `PathBase` by generating paths with trailing slashes only as a final step, rather than for every intermediate directory.
- Simplify and speed up handling of rare patterns involving both `**` and `..` segments.
2024-01-20 02:10:25 +00:00
Irit Katriel 7e49f27b41
gh-114265: move line number propagation before cfg optimization, remove guarantee_lineno_for_exits (#114267) 2024-01-19 14:49:26 +00:00
Nikita Sobolev efb81a60f5
gh-114275: Skip doctests that use asyncio in test_pdb for WASI builds (#114309) 2024-01-19 14:00:34 +01:00
Skip Montanaro 72abb8c5d4
gh-114123: Migrate docstring from _csv to csv (#114124)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Éric <merwok@netwok.org>
2024-01-18 22:18:42 +00:00
keithasaurus 2d3f6b56c5
gh-114087: Speed up dataclasses._asdict_inner (#114088) 2024-01-18 09:03:20 -07:00
Phillip Schanely 339fc3c224
gh-114198: Rename dataclass __replace__ argument to 'self' (gh-114251)
This change renames the dataclass __replace__ method's first argument
name from 'obj' to 'self'.
2024-01-18 11:01:17 -05:00
Nikita Sobolev 9c93350f58
gh-108303: Move all doctest related files and tests to Lib/test/test_doctest/ (#112109)
Co-authored-by: Brett Cannon <brett@python.org>
2024-01-18 16:58:11 +01:00
Christopher Chavez b8f29b1293
gh-110345: show Tcl/Tk patchlevel in tkinter._test() (GH-110350) 2024-01-18 17:46:58 +02:00
kcatss a571a2fd3f
gh-114050: Fix crash when more than two arguments are passed to int() (GH-114067)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-01-18 13:27:44 +02:00
Serhiy Storchaka 311d1e2701
gh-104522: Fix test_subprocess failure when build Python in the root home directory (GH-114236)
* gh-104522: Fix test_subprocess failure when build Python in the root home directory

EPERM is raised when setreuid() fails.
EACCES is set in execve() when the test user has not access to sys.executable.
2024-01-18 10:52:59 +00:00