Commit Graph

53015 Commits

Author SHA1 Message Date
Kirill Podoprigora 1a84bdc237
gh-121163: Add "all" as an valid alias for "always" in warnings.simplefilter() (#121164)
Add support for ``all`` as an valid alias for ``always`` in ``warnings.simplefilter()``
and ``warnings.filterswarnings()``.
2024-06-30 19:48:00 +02:00
Sergey B Kirpichev 2cb84b107a
gh-119372: Recover inf's and zeros in _Py_c_quot (GH-119457)
In some cases, previously computed as (nan+nanj), we could
recover meaningful component values in the result, see
e.g. the C11, Annex G.5.2, routine _Cdivd().
2024-06-29 11:00:48 +03:00
blhsing 6d34938dc8
gh-120713: Normalize year with century for datetime.strftime (GH-120820) 2024-06-29 09:32:42 +03:00
Steve Dower 2894aa14f2
gh-121115: Skip __index__ in PyLong_AsNativeBytes by default (GH-121118) 2024-06-28 16:26:21 +01:00
Serhiy Storchaka 81a654a342
gh-121018: Fix more cases of exiting in argparse when exit_on_error=False (GH-121056)
* parse_intermixed_args() now raises ArgumentError instead of calling
  error() if exit_on_error is false.
* Internal code now always raises ArgumentError instead of calling
  error(). It is then caught at the higher level and error() is called if
  exit_on_error is true.
2024-06-28 17:21:59 +03:00
Victor Stinner 43709d5d54
Check for compiler warnings in test_cext on Windows (#121088)
On Windows, test_cext and test_cppext now pass /WX flag to the MSC
compiler to treat all compiler warnings as errors. In verbose mode,
these tests now log the compiler commands to help debugging.

Change Py_BUILD_ASSERT_EXPR implementation on Windows to avoid a
compiler warning about an unnamed structure.
2024-06-28 14:41:37 +02:00
Kumar Aditya ef3c400434
gh-120804: remove `is_active` method from internal child watchers implementation in asyncio (#121124) 2024-06-28 17:23:56 +05:30
Sam Gross 4a62a331de
gh-121065: Temporarily skip flaky test on free-threaded build (#121100) 2024-06-27 14:03:09 -04:00
Craig Robson e9b4ec614b
gh-105623 Fix performance degradation in logging RotatingFileHandler (GH-105887)
The check for whether the log file is a real file is expensive on NFS
filesystems.  This commit reorders the rollover condition checking to
not do the file type check if the expected file size is less than the
rotation threshold.

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2024-06-27 16:44:40 +00:00
Serhiy Storchaka db96edd6d1
gh-121027: Add a future warning in functools.partial.__get__ (#121086) 2024-06-27 11:47:20 +00:00
Victor Stinner b7a95dfee3
gh-120593: Check -Wcast-qual flag in test_cext (#121081)
Check the usage of the 'const' qualifier in the Python C API in
test_cext.
2024-06-27 10:22:48 +00:00
Pradyun Gedam 4999e0bda0
gh-120888: Bump bundled pip to 24.1.1 (#120889)
Co-authored-by: Pradyun Gedam <pradyunsg@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
2024-06-27 09:09:54 +00:00
Petr Viktorin 1167a9a30b
gh-119521: Remove _IncompleteInputError from the docs (GH-120993) 2024-06-27 09:09:22 +02:00
Janek Nouvertné 7d9c68513d
gh-120868: Fix breaking change in `logging.config` when using `QueueHandler` (GH-120872) 2024-06-27 08:09:01 +01:00
Ken Jin 22b0de2755
gh-117139: Convert the evaluation stack to stack refs (#118450)
This PR sets up tagged pointers for CPython.

The general idea is to create a separate struct _PyStackRef for everything on the evaluation stack to store the bits. This forces the C compiler to warn us if we try to cast things or pull things out of the struct directly.

Only for free threading: We tag the low bit if something is deferred - that means we skip incref and decref operations on it. This behavior may change in the future if Mark's plans to defer all objects in the interpreter loop pans out.

This implies a strict stack reference discipline is required. ALL incref and decref operations on stackrefs must use the stackref variants. It is unsafe to untag something then do normal incref/decref ops on it.

The new incref and decref variants are called dup and close. They mimic a "handle" API operating on these stackrefs.

Please read Include/internal/pycore_stackref.h for more information!

---------

Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com>
2024-06-27 03:10:43 +08:00
Łukasz Langa d611c4c8e9
gh-118908: Use __main__ for the default PyREPL namespace (#121054) 2024-06-26 15:01:10 -04:00
Victor Stinner 44eafd6688
gh-121008: Fix idlelib.run tests (#121046)
When testing IDLE, don't create a Tk to avoid side effects such as
installing a PyOS_InputHook hook.
2024-06-26 15:41:16 +02:00
devdanzin 9e45fd9858
gh-121016: Add test for `PYTHON_BASIC_REPL` envioronment variable (#121017) 2024-06-26 10:39:07 +00:00
Petr Viktorin 9056597224
gh-73991: Skip permission test if running as *nix superuser (GH-120994) 2024-06-26 11:36:09 +02:00
Bénédikt Tran d2646e3f45
gh-121025: Improve partialmethod.__repr__ (GH-121033)
It no longer contains redundant commas and spaces.
2024-06-26 12:08:27 +03:00
blhsing 0654336dd5
gh-121018: Ensure ArgumentParser.parse_args with exit_on_error=False raises instead of exiting when given unrecognized arguments (GH-121019) 2024-06-26 10:41:51 +03:00
Alex Waygood 2d3187bf20
gh-114053: Fix another edge case involving `get_type_hints`, PEP 695 and PEP 563 (#120272) 2024-06-25 16:53:18 +01:00
Mark Shannon 8f5a01707f
GH-120982: Add stack check assertions to generated interpreter code (GH-120992) 2024-06-25 16:42:29 +01:00
Jelle Zijlstra 42b2c9d78d
gh-120108: Fix deepcopying of AST trees with .parent attributes (#120114) 2024-06-25 08:12:11 -07:00
Victor Stinner 2e157851e3
gh-119182: Add PyUnicodeWriter_WriteUCS4() function (#120849) 2024-06-24 17:40:39 +02:00
Serhiy Storchaka 6eb23b1311
gh-70278: Fix PyUnicode_FromFormat() with precision for %s and %V (GH-120365)
PyUnicode_FromFormat() no longer produces the ending \ufffd
character for truncated C string when use precision with %s and %V.
It now truncates the string before the start of truncated multibyte sequences.
2024-06-24 18:07:07 +03:00
Itamar Oren b0e1c51882
gh-120373: Mark test_audit.test_http as requiring the network resource (#120374) 2024-06-24 07:18:46 -06:00
Pablo Galindo Salgado ac61d58db0
gh-119521: Rename IncompleteInputError to _IncompleteInputError and remove from public API/ABI (GH-119680)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-06-24 14:08:12 +02:00
Serhiy Storchaka c38e2f64d0
gh-119614: Fix truncation of strings with embedded null characters in Tkinter (GH-120909)
Now the null character is always represented as \xc0\x80 for
Tcl_NewStringObj().
2024-06-24 12:17:25 +03:00
Serhiy Storchaka 1500a23f33
gh-120683: Fix an error in logging.LogRecord timestamp (GH-120709)
The integer part of the timestamp can be rounded up, while the millisecond
calculation truncates, causing the log timestamp to be wrong by up to 999 ms
(affected roughly 1 in 8 million timestamps).
2024-06-24 09:50:39 +03:00
Barney Gale 35e998f560
GH-73991: Add `pathlib.Path.copytree()` (#120718)
Add `pathlib.Path.copytree()` method, which recursively copies one
directory to another.

This differs from `shutil.copytree()` in the following respects:

1. Our method has a *follow_symlinks* argument, whereas shutil's has a
   *symlinks* argument with an inverted meaning.
2. Our method lacks something like a *copy_function* argument. It always
   uses `Path.copy()` to copy files.
3. Our method lacks something like a *ignore_dangling_symlinks* argument.
   Instead, users can filter out danging symlinks with *ignore*, or
   ignore exceptions with *on_error*
4. Our *ignore* argument is a callable that accepts a single path object,
   whereas shutil's accepts a path and a list of child filenames.
5. We add an *on_error* argument, which is a callable that accepts
   an `OSError` instance. (`Path.walk()` also accepts such a callable).

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
2024-06-23 22:01:12 +01:00
Jason R. Coombs 1ba0bb21ed
gh-120910: Fix issue resolving relative paths outside site-packages. (#120911)
Incorporates changes from importlib_metadata 7.2.1.
2024-06-23 13:06:07 -04:00
Serhiy Storchaka f4ddaa3967
gh-101830: Fix Tcl_Obj to string conversion (GH-120884)
Accessing the Tkinter object's string representation no longer converts
the underlying Tcl object to a string on Windows.
2024-06-23 16:34:14 +03:00
Kumar Aditya 9d2e1ea386
GH-120804: Remove `PidfdChildWatcher`, `ThreadedChildWatcher` and `AbstractChildWatcher` from asyncio APIs (#120893) 2024-06-23 18:38:50 +05:30
Kumar Aditya 96ead91f0f
GH-120804: Remove `get_child_watcher` and `set_child_watcher` from asyncio (#120818) 2024-06-23 09:53:23 +05:30
Kumar Aditya 4717aaa1a7
GH-107803: double linked list implementation for asyncio tasks (GH-107804)
* linked list

* add tail optmiization to linked list

* wip

* wip

* wip

* more fixes

* finally it works

* add tests

* remove weakreflist

* add some comments

* reduce code duplication in _asynciomodule.c

* address some review comments

* add invariants about the state of the linked list

* add better explanation

* clinic regen

* reorder branches for better branch prediction

* Update Modules/_asynciomodule.c

* Apply suggestions from code review

Co-authored-by: Itamar Oren <itamarost@gmail.com>

* fix capturing of eager tasks

* add comment to task finalization

* fix tests and couple c implmentation to c task

improved linked-list logic and more comments

* fix test

---------

Co-authored-by: Itamar Oren <itamarost@gmail.com>
2024-06-22 10:58:35 -07:00
Serhiy Storchaka a046c848c1
gh-120873: Add tests for new widget options in Tk 8.7 (GH-120877) 2024-06-22 16:19:42 +03:00
Serhiy Storchaka 974a978631
gh-120873: Add test for "state" option in ttk.Scale (GH-120874)
Also refactor the "state" option tests for other ttk widgets.
2024-06-22 11:18:04 +00:00
Serhiy Storchaka 6ad26de6e8
gh-104855: Update Tkinter tests for Tcl/Tk 8.7 and 9.0 (GH-120824)
The tests are now passed with the current version of Tcl/Tk under
development (8.7b1+ and 9.0b3+).

The following changes were also made to make the tests more flexible:

* Helper methods like checkParam() now interpret the expected error message
  as a regular expression instead of a literal.
* Add support of new arguments in checkEnumParam():
  - allow_empty=True skips testing with empty string;
  - fullname= specifies the name for error message if it differs from the
    option name;
  - sort=True sorts values for error message.
* Add support of the allow_empty argument in checkReliefParam():
  allow_empty=True adds an empty string to the list of accepted values.
* Attributes _clip_highlightthickness, _clip_pad and  _clip_borderwidth
  specify how negative values of options -highlightthickness, -padx, -pady
  and -borderwidth are handled.
* Use global variables for some common error messages.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2024-06-22 09:53:24 +03:00
Victor Stinner 913a956d85
gh-119182: Rewrite PyUnicodeWriter tests in Python (#120845) 2024-06-21 20:15:06 +02:00
neonene a81d434c06
gh-120782: Update internal type cache when reloading datetime (#120829) 2024-06-21 22:39:33 +05:30
Petr Viktorin 6f1d448bc1
gh-113993: Allow interned strings to be mortal, and fix related issues (GH-120520)
* Add an InternalDocs file describing how interning should work and how to use it.

* Add internal functions to *explicitly* request what kind of interning is done:
  - `_PyUnicode_InternMortal`
  - `_PyUnicode_InternImmortal`
  - `_PyUnicode_InternStatic`

* Switch uses of `PyUnicode_InternInPlace` to those.

* Disallow using `_Py_SetImmortal` on strings directly.
  You should use `_PyUnicode_InternImmortal` instead:
  - Strings should be interned before immortalization, otherwise you're possibly
    interning a immortalizing copy.
  - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to
    `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in
    backports, as they are now part of public API and version-specific ABI.

* Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery.

* Make sure the statically allocated string singletons are unique. This means these sets are now disjoint:
  - `_Py_ID`
  - `_Py_STR` (including the empty string)
  - one-character latin-1 singletons

  Now, when you intern a singleton, that exact singleton will be interned.

* Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic).

* Intern `_Py_STR` singletons at startup.

* For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup.

* Beef up the tests. Cover internal details (marked with `@cpython_only`).

* Add lots of assertions

Co-Authored-By: Eric Snow <ericsnowcurrently@gmail.com>
2024-06-21 17:19:31 +02:00
Bénédikt Tran 7595e6743a
gh-120380: fix Python implementation of `pickle.Pickler` for `bytes` and `bytearray` objects in protocol version 5. (GH-120422) 2024-06-21 14:22:38 +02:00
Nikita Sobolev 8334a1b55c
gh-120384: Fix array-out-of-bounds crash in `list_ass_subscript` (#120442) 2024-06-21 13:48:38 +03:00
Kumar Aditya 733dac01b0
GH-120804: Remove SafeChildWatcher, FastChildWatcher and MultiLoopChildWatcher from asyncio (#120805)
Remove SafeChildWatcher, FastChildWatcher and MultiLoopChildWatcher from asyncio. These child watchers have been deprecated since Python 3.12. The tests are also removed and some more tests will be added after the rewrite of child watchers.
2024-06-21 10:23:10 +05:30
Jason R. Coombs 85d90b59e2
gh-120801: Refactor importlib.metadata fixtures. (#120803)
These changes released with importlib_metadata 7.2.0.
2024-06-20 19:00:39 +00:00
Tian Gao 31ce5c05a4
gh-120769: Add pdb meta command to print frame status. (#120770) 2024-06-20 10:38:07 -07:00
Jelle Zijlstra e8e151d471
gh-120780: Show attribute name for LOAD_SPECIAL in dis output (#120781) 2024-06-20 07:07:24 -07:00
Irit Katriel 55596ae044
gh-98442: fix locations of with statement's cleanup instructions (#120763)
gh-98442: fix location of with statement's cleanup instructions
2024-06-20 09:32:06 +01:00
Serhiy Storchaka 8bc76ae45f
gh-111259: Optimize complementary character sets in RE (GH-120742)
Patterns like "[\s\S]" or "\s|\S" which match any character are now compiled
to the same effective code as a dot with the DOTALL modifier ("(?s:.)").
2024-06-20 07:19:32 +00:00
Jelle Zijlstra 3846fcfb92
gh-119698: symtable: Fix merge race (#120779) 2024-06-20 05:42:30 +00:00
Bénédikt Tran b8a8e04fec
gh-119698: fix `symtable.Class.get_methods` and document its behaviour correctly (#120151)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-06-19 20:49:30 -07:00
Tian Gao 4bbb0273f2
gh-120606: Allow EOF to exit pdb commands definition (#120607) 2024-06-19 15:50:26 -07:00
Nikita Sobolev 1e4815692f
gh-120732: Fix `name` passing to `Mock`, when using kwargs to `create_autospec` (#120737) 2024-06-19 21:35:11 +01:00
Mark Shannon d1c673b658
GH-120097: Make FrameLocalsProxy a mapping (#120101)
* Register FrameLocalsProxy as a subclass of collections.abc.Mapping

* Allow FrameLocalsProxy to matching mapping patterns
2024-06-19 17:54:13 +01:00
Mark Shannon 00257c746c
GH-119462: Enforce invariants of type versioning (GH-120731)
* Remove uses of Py_TPFLAGS_VALID_VERSION_TAG
2024-06-19 17:38:45 +01:00
Victor Stinner 0f3e36454d
gh-120635: Avoid leaking processes in test_pyrepl (#120676)
If the child process takes longer than SHORT_TIMEOUT seconds to
complete, kill the process but then wait until it completes with no
timeout to not leak child processes.
2024-06-19 15:14:29 +02:00
Jelle Zijlstra d8f27cb114
gh-120722: Set position on RETURN_VALUE in lambda (#120724) 2024-06-19 05:56:36 -07:00
Kirill Podoprigora b8fb369193
gh-102797: Add more code snippets in test_ast (#102798)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Nineteendo <nineteendo19d0@gmail.com>
2024-06-19 09:51:43 +02:00
Wulian233 89f7208f67
gh-120633: Move scrollbar and remove tear-off menus in turtledemo (#120634)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2024-06-19 02:20:54 -04:00
Barney Gale 20d5b84f57
GH-73991: Add follow_symlinks argument to `pathlib.Path.copy()` (#120519)
Add support for not following symlinks in `pathlib.Path.copy()`.

On Windows we add the `COPY_FILE_COPY_SYMLINK` flag is following symlinks is disabled. If the source is symlink to a directory, this call will fail with `ERROR_ACCESS_DENIED`. In this case we add `COPY_FILE_DIRECTORY` to the flags and retry. This can fail on old Windowses, which we note in the docs.

No news as `copy()` was only just added.
2024-06-19 00:59:54 +00:00
Barney Gale 9f741e55c1
GH-73991: pathlib ABC tests: add `DummyPath.unlink()` and `rmdir()` (#120715)
In preparation for the addition of `PathBase.rmtree()`, implement
`DummyPath.unlink()` and `rmdir()`, and move corresponding tests into
`test_pathlib_abc` so they're run against `DummyPath`.
2024-06-18 22:13:45 +00:00
Irit Katriel b7f478948f
gh-120367: fix bug where compiler detects redundant jump after pseudo op replacement (#120714) 2024-06-18 22:09:23 +00:00
Barney Gale 69058e20e4
GH-73991: Use same signature for `shutil._rmtree_[un]safe()`. (#120517)
Preparatory work for moving `_rmtree_unsafe()` and `_rmtree_safe_fd()` to
`pathlib._os` so that they can be used from both `shutil` and `pathlib`.

Move implementation-specific setup from `rmtree()` into the safe/unsafe
functions, and give them the same signature `(path, dir_fd, onexc)`.

In the tests, mock `os.open` rather than `_rmtree_safe_fd()` to ensure the
FD-based walk is used, and replace a couple references to
`shutil._use_fd_functions` with `shutil.rmtree.avoids_symlink_attacks`
(which has the same value).

No change of behaviour.
2024-06-18 22:15:18 +01:00
devdanzin c81a5e6b5b
gh-119574: Add some missing environment variables to '--help-env'. (GH-120006) 2024-06-18 17:12:58 +00:00
Victor Stinner e9f4d80fa6
gh-120417: Add #noqa: F401 to tests (#120627)
Ignore linter "imported but unused" warnings in tests when the linter
doesn't understand how the import is used.
2024-06-18 15:51:47 +00:00
Nice Zombies 1035fe0cfb
gh-117953: Skip `test_interpreters` properly without GIL (#120689) 2024-06-18 15:22:24 +00:00
Victor Stinner f869bcfc5b
gh-120417: Use import_helper() in test_regrtest (#120680) 2024-06-18 17:15:04 +02:00
Bénédikt Tran d8cd0fa4e3
gh-120449: fix ``test_pyclbr`` introspection for mangled names (GH-120450) 2024-06-18 14:29:43 +00:00
Victor Stinner 16f8e22e7c
gh-120600: Make Py_TYPE() opaque in limited C API 3.14 (#120601)
In the limited C API 3.14 and newer, Py_TYPE() is now implemented as
an opaque function call to hide implementation details.
2024-06-18 14:28:48 +00:00
Sam Gross e8752d7b80
gh-118789: Add `PyUnstable_Object_ClearWeakRefsNoCallbacks` (#118807)
This exposes `PyUnstable_Object_ClearWeakRefsNoCallbacks` as an unstable
C-API function to provide a thread-safe mechanism for clearing weakrefs
without executing callbacks.

Some C-API extensions need to clear weakrefs without calling callbacks,
such as after running finalizers like we do in subtype_dealloc.
Previously they could use `_PyWeakref_ClearRef` on each weakref, but
that's not thread-safe in the free-threaded build.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-06-18 09:57:23 -04:00
Nice Zombies 360f14a493
gh-120659: Skip `test_freethreading` with GIL (#120660) 2024-06-18 15:56:20 +02:00
Victor Stinner d2e423114c
gh-120417: Move imports to doctests in test_doctest (#120679) 2024-06-18 15:54:53 +02:00
Jan Kaliszewski dacc5ac71a
gh-120381: Fix inspect.ismethoddescriptor() (#120383)
The `inspect.ismethoddescriptor()` function did not check for the lack of
`__delete__()` and, consequently, erroneously returned True when applied
to *data* descriptors with only `__get__()` and `__delete__()` defined.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
2024-06-18 12:19:43 +00:00
Mark Shannon 9cefcc0ee7
GH-120507: Lower the `BEFORE_WITH` and `BEFORE_ASYNC_WITH` instructions. (#120640)
* Remove BEFORE_WITH and BEFORE_ASYNC_WITH instructions.

* Add LOAD_SPECIAL instruction

* Reimplement `with` and `async with` statements using LOAD_SPECIAL
2024-06-18 12:17:46 +01:00
Irit Katriel 73dc1c678e
gh-119897: Add test for lambda generator invocation (#120658)
gh-120467: Add test for lambda generator invocation
2024-06-18 10:45:23 +01:00
Serhiy Storchaka 2cf47389e2
gh-120590: Fix test_pydoc in the refleak hunting mode (GH-120615)
Mocking only works if sys.modules['pydoc'] and pydoc are the same,
but some pydoc functions reload the module and change sys.modules.
Ensure that sys.modules['pydoc'] is always restored after the corresponding
tests.
2024-06-18 12:19:32 +03:00
Nice Zombies ac37a80601
gh-120560: Mark `zip64` tests in `test_zipimport` as CPU-heavy (GH-120564) 2024-06-17 15:18:51 -07:00
Eric Snow 2c66318cdc
gh-120524: Avoid a Race On _PyRuntime.types.managed_static.types[i].interp_count (gh-120529)
gh-120182 added new global state (interp_count), but didn't add thread-safety for it.  This change eliminates the possible race.
2024-06-17 13:16:00 -06:00
Victor Stinner e73c42e15c
gh-120417: Modify test_bdb to use the import (#120628)
Run test_module_for_bdb with a specific namespace.
2024-06-17 21:06:18 +02:00
Victor Stinner c608477532
gh-120417: Remove unused imports in tests (part 1) (#120629) 2024-06-17 21:05:56 +02:00
Victor Stinner 5a8a979aeb
gh-120417: Remove unused imports in tests (part 2) (#120630) 2024-06-17 21:05:37 +02:00
Victor Stinner f916b77fea
gh-120417: Remove unused imports in tests (part 3) (#120631) 2024-06-17 21:04:58 +02:00
Daniele Parmeggiani 362cd2680b
gh-117657: Fix `__slots__` thread safety in free-threaded build (#119368)
Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`.
These functions implement `__slots__` accesses for Python objects.
2024-06-17 18:44:54 +00:00
AN Long 28140d1f2d
gh-115649: Copy the filename into main interpreter before intern in import.c (#120315)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-06-17 21:27:22 +05:30
Victor Stinner f4d301d8b9
gh-120417: Remove unused imports in tests (part 4) (#120632) 2024-06-17 17:35:20 +02:00
Steele Farnsworth 2c7209a3bd
gh-114091: Reword error message for unawaitable types (#114090)
Reword error message for unawaitable types.
2024-06-17 20:18:17 +05:30
Bénédikt Tran 4bf17c381f
gh-119933: Improve ``SyntaxError`` message for invalid type parameters expressions (#119976)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-06-17 06:51:03 -07:00
Mark Shannon 274f844830
GH-120619: Clean up `RETURN_VALUE` instruction (GH-120624)
* Rename _POP_FRAME to _RETURN_VALUE as it returns a value as well as popping a frame.

* Remove remaining _POP_FRAMEs
2024-06-17 14:40:11 +01:00
Irit Katriel 21866c8ed2
gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (#120425) 2024-06-17 10:10:06 +00:00
Terry Jan Reedy bd4516d9ef
gh-120567: Clarify weekday return in calendar.monthrange docstring (#120570)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-06-16 16:43:57 -04:00
Idan Kapustian 192d17c3fd
gh-120485: Add an override of `allow_reuse_port` on classes subclassing `socketserver.TCPServer` (GH-120488)
Co-authored-by: Vinay Sajip <vinay_sajip@yahoo.co.uk>
2024-06-16 13:15:03 +01:00
Nikita Sobolev 0c0348adbf
gh-120579: Guard `_testcapi` import in `test_free_threading` (#120580) 2024-06-16 11:26:13 +03:00
Ruben Vorderman 08d09cf5ba
gh-112346: Always set OS byte to 255, simpler gzip.compress function. (GH-120486)
This matches the output behavior in 3.10 and earlier; the optimization in 3.11 allowed the zlib library's "os" value to be filled in instead in the circumstance when mtime was 0.  this keeps things consistent.
2024-06-15 18:46:39 +00:00
Serhiy Storchaka 31d1d72d7e
gh-120541: Improve the "less" prompt in pydoc (GH-120543)
When help() is called with non-string argument, use __qualname__ or
__name__ if available, otherwise use "{typename} object".
2024-06-15 20:56:40 +03:00
Alex Waygood 99d62f902e
Add some more edge-case tests for `inspect.get_annotations` with `eval_str=True` (#120550) 2024-06-15 12:51:58 +00:00
Wulian233 c501261c91
gh-120495: Fix incorrect exception handling in Tab Nanny (#120498)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-06-15 05:04:14 -06:00
Nikita Sobolev 42ebdd83bb
gh-120544: Add `else: fail()` to tests where exception is expected (#120545) 2024-06-15 10:33:14 +00:00
Russell Keith-Magee 5c58e728b1
gh-117398: Use the correct module loader for iOS in datetime CAPI test. (#120477)
Use the correct loader for iOS.
2024-06-15 08:05:30 +08:00
Russell Keith-Magee 92f6d400f7
gh-119819: Conditional skip of logging tests that require multiprocessing subprocess support (#120476)
Skip tests that require multiprocessing subprocess support.
2024-06-15 08:05:18 +08:00
Eric Snow e3b6cff331
gh-120524: Temporarily Skip test_create_many_threaded In test_interpreters.test_stress (gh-120525) 2024-06-14 22:12:35 +00:00
Eric Snow b2e71ff4f8
gh-120161: Fix a Crash in the _datetime Module (gh-120182)
In gh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown.  However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection.  The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection.  To avoid the problem for _datetime, I have applied a similar approach here.

Also, credit goes to @mgorny and @neonene for the new tests.

FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting.  I'll circle back to the cleaner approach with a future change on the main branch.
2024-06-14 13:29:09 -06:00
Victor Stinner 05df063ad8
gh-120417: Fix "imported but unused" linter warnings (#120461)
Add __all__ to the following modules:
importlib.machinery, importlib.util and xml.sax.

Add also "# noqa: F401" in collections.abc,
subprocess and xml.sax.

* Sort __all__; remove collections.abc.__all__; remove private names

* Add tests
2024-06-14 20:39:50 +02:00
Tian Gao ed60ab5fab
gh-119824: Print stack entry when user input is needed (#119882)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-06-14 11:25:23 -07:00
Nikita Sobolev 7fadfd82eb
gh-120361: Add `nonmember` test with enum flags inside to `test_enum` (GH-120364)
* gh-120361: Add `nonmember` test with enum flags inside to `test_enum`
2024-06-14 10:25:35 -07:00
Barney Gale 7c38097add
GH-73991: Add `pathlib.Path.copy()` (#119058)
Add a `Path.copy()` method that copies the content of one file to another.

This method is similar to `shutil.copyfile()` but differs in the following ways:

- Uses `fcntl.FICLONE` where available (see GH-81338)
- Uses `os.copy_file_range` where available (see GH-81340)
- Uses `_winapi.CopyFile2` where available, even though this copies more metadata than the other implementations. This makes `WindowsPath.copy()` more similar to `shutil.copy2()`.

The method is presently _less_ specified than the `shutil` functions to allow OS-specific optimizations that might copy more or less metadata.

Incorporates code from GH-81338 and GH-93152.

Co-authored-by: Eryk Sun <eryksun@gmail.com>
2024-06-14 17:15:49 +01:00
Raymond Hettinger 27419f1fce
Update tests for the itertools docs rough equivalents (#120509) 2024-06-14 11:00:46 -05:00
Raymond Hettinger 41554ef0e0
Stronger tests for the statistics kernel formulas (gh-120506) 2024-06-14 10:21:35 -05:00
Alex Waygood 42351c3b9a
gh-114053: Fix bad interaction of PEP 695, PEP 563 and `inspect.get_annotations` (#120270) 2024-06-13 21:16:40 +00:00
Bénédikt Tran a3711afefa
gh-120012: clarify the behaviour of `multiprocessing.Queue.empty` on closed queues. (GH-120102)
* improve doc for `multiprocessing.Queue.empty`
* add tests for checking emptiness of queues

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-06-13 19:03:01 +00:00
neonene 50a389565a
gh-117398: Add datetime C-API type check test for subinterpreters (gh-119604)
Check if the DateTime C-API type matches the datetime.date type on main and shared/isolated subinterpreters.
2024-06-13 12:05:03 -06:00
Victor Stinner 6ae254aaa0
gh-120417: Add #noqa to used imports in the stdlib (#120421)
Tools such as ruff can ignore "imported but unused" warnings if a
line ends with "# noqa: F401". It avoids the temptation to remove
an import which is used effectively.
2024-06-13 16:14:50 +02:00
Stefano Rivera 030b452e34
gh-120418: Don't assume wheeldata is deleted if `WHEEL_PKG_DIR` is set (#120419)
Remove wheeldata from both sides of the `assertEqual`, so that we're
*actually* ignoring it from the test set.

This test is only making assertions about the source tree, no code is
being executed that would do anything different based on the value of
`WHEEL_PKG_DIR`.
2024-06-12 21:19:36 +02:00
Pablo Galindo Salgado 3453362183
gh-118908: Protect the REPL subprocess with a timeout in tests (#120408) 2024-06-12 19:09:25 +00:00
Victor Stinner 4c6d4f5cb3
gh-120417: Remove unused imports in the stdlib (#120420) 2024-06-12 20:56:42 +02:00
Lysandros Nikolaou 4b5d3e0e72
gh-120343: Fix column offsets of multiline tokens in tokenize (#120391) 2024-06-12 20:52:55 +02:00
neonene 127c1d2771
gh-71587: Drop local reference cache to `_strptime` module in `_datetime` (gh-120224)
The _strptime module object was cached in a static local variable (in the datetime.strptime() implementation).  That's a problem when it crosses isolation boundaries, such as reinitializing the runtme or between interpreters.  This change fixes the problem by dropping the static variable, instead always relying on the normal sys.modules cache (via PyImport_Import()).
2024-06-12 10:46:39 -06:00
Nikita Sobolev fabcf6bc8f
gh-120388: Improve deprecation warning message, when test returns non-None (#120401)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-12 14:50:58 +00:00
Ken Jin e16aed63f6
gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
2024-06-12 20:41:07 +08:00
Xie Yanbo ce3879bd45
Fix typos in documentation (#120338) 2024-06-12 12:24:43 +00:00
Irit Katriel 97b69db167
gh-93691: fix too broad source locations of for statement iterators (#120330) 2024-06-12 12:53:19 +01:00
Bénédikt Tran 755dab719d
gh-120029: make `symtable.Symbol.__repr__` correctly reflect the compiler's flags, add methods (#120099)
Expose :class:`symtable.Symbol` methods :meth:`~symtable.Symbol.is_free_class`,
:meth:`~symtable.Symbol.is_comp_iter` and :meth:`~symtable.Symbol.is_comp_cell`.

---------

Co-authored-by: Carl Meyer <carl@oddbird.net>
2024-06-12 05:14:50 -06:00
Lysandros Nikolaou 02e74c3562
gh-118908: Fix completions after namespace change in REPL (#120370) 2024-06-12 10:21:53 +02:00
Pablo Galindo Salgado 34e4d3287e
gh-120221: Deliver real singals on Ctrl-C and Ctrl-Z in the new REPL (#120354) 2024-06-11 20:20:25 +01:00
Ken Jin 203565b2f9
gh-120198: Fix race condition when editing __class__ with an audit hook active (GH-120195) 2024-06-11 20:10:23 +01:00
Eugene Triguba 86a8a1c57a
gh-118908: Limit exposed globals from internal imports and definitions on new REPL startup (#119547) 2024-06-11 17:40:31 +00:00
Lysandros Nikolaou 1b62bcee94
gh-120343: Do not reset byte_col_offset_diff after multiline tokens (#120352)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2024-06-11 17:00:53 +00:00
Matt Wozniski 32a0faba43
gh-119517: Fixes for pasting in pyrepl (#120253)
* Remove pyrepl's optimization for self-insert

This will be replaced by a less specialized optimization.

* Use line-buffering when pyrepl echoes pastes

Previously echoing was totally suppressed until the entire command had
been pasted and the terminal ended paste mode, but this gives the user
no feedback to indicate that an operation is in progress. Drawing
something to the screen once per line strikes a balance between
perceived responsiveness and performance.

* Remove dead code from pyrepl

`msg_at_bottom` is always true.

* Speed up pyrepl's screen rendering computation

The Reader in pyrepl doesn't hold a complete representation of the
screen area being drawn as persistent state. Instead, it recomputes it,
on each keypress. This is fast enough for a few hundred bytes, but
incredibly slow as the input buffer grows into the kilobytes (likely
because of pasting).

Rather than making some expensive and expansive changes to the repl's
internal representation of the screen, add some caching: remember some
data from one refresh to the next about what was drawn to the screen
and, if we don't find anything that has invalidated the results that
were computed last time around, reuse them. To keep this caching as
simple as possible, all we'll do is look for lines in the buffer that
were above the cursor the last time we were asked to update the screen,
and that are still above the cursor now. We assume that nothing can
affect a line that comes before both the old and new cursor location
without us being informed. Based on this assumption, we can reuse old
lines, which drastically speeds up the overwhelmingly common case where
the user is typing near the end of the buffer.

* Speed up pyrepl prompt drawing

Cache the `can_colorize()` call rather than repeatedly recomputing it.
This call looks up an environment variable, and is called once per
character typed at the REPL. The environment variable lookup shows up as
a hot spot when profiling, and we don't expect this to change while the
REPL is running.

* Speed up pasting multiple lines into the REPL

Previously, we were checking whether the command should be accepted each
time a line break was encountered, but that's not the expected behavior.
In bracketed paste mode, we expect everything pasted to be part of
a single block of code, and encountering a newline shouldn't behave like
a user pressing <Enter> to execute a command. The user should always
have a chance to review the pasted command before running it.

* Use a read buffer for input in pyrepl

Previously we were reading one byte at a time, which causes much slower
IO than necessary. Instead, read in chunks, processing previously read
data before asking for more.

* Optimize finding width of a single character

`wlen` finds the width of a multi-character string by adding up the
width of each character, and then subtracting the width of any escape
sequences. It's often called for single character strings, however,
which can't possibly contain escape sequences. Optimize for that case.

* Optimize disp_str for ASCII characters

Since every ASCII character is known to display as single width, we can
avoid not only the Unicode data lookup in `disp_str` but also the one
hidden in `str_width` for them.

* Speed up cursor movements in long pyrepl commands

When the current pyrepl command buffer contains many lines, scrolling up
becomes slow. We have optimizations in place to reuse lines above the
cursor position from one refresh to the next, but don't currently try to
reuse lines below the cursor position in the same way, so we wind up
with quadratic behavior where all lines of the buffer below the cursor
are recomputed each time the cursor moves up another line.

Optimize this by only computing one screen's worth of lines beyond the
cursor position. Any lines beyond that can't possibly be shown by the
console, and bounding this makes scrolling up have linear time
complexity instead.

---------

Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2024-06-11 16:42:10 +00:00
Jelle Zijlstra 9b8611eeea
gh-119180: PEP 649 compiler changes (#119361) 2024-06-11 13:06:49 +00:00
Kirill Podoprigora 02c1dfff07
gh-120080: Mark test_round_with_none_arg_direct_call as cpython_only (#120328) 2024-06-11 09:56:38 +02:00
Nikita Sobolev 141babad9b
gh-120298: Fix use-after-free in `list_richcompare_impl` (#120303)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-11 10:04:27 +03:00
blhsing 9e9ee50421
gh-65454: avoid triggering call to a PropertyMock in NonCallableMock.__setattr__ (#120019) 2024-06-11 05:42:49 +00:00
Robert Collins 422c4fc855
gh-119600: mock: do not access attributes of original when new_callable is set (#119601)
In order to patch flask.g e.g. as in #84982, that
proxies getattr must not be invoked. For that,
mock must not try to read from the original
object. In some cases that is unavoidable, e.g.
when doing autospec. However, patch("flask.g",
new_callable=MagicMock) should be entirely safe.
2024-06-11 06:41:12 +01:00
Victor Stinner 7aff2de62b
gh-120057: Add os.environ.refresh() method (#120059) 2024-06-10 16:34:17 +00:00
Pieter Eendebak c3b6dbff2c
gh-115801: Only allow sequence of strings as input for difflib.unified_diff (GH-118333) 2024-06-10 14:06:18 +03:00
E. M. Bray 4829522b8d
bpo-24766: doc= argument to subclasses of property not handled correctly (GH-2487)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-06-10 08:55:49 +00:00
Carl Meyer 0ae8579b85
gh-119666: fix multiple class-scope comprehensions referencing __class__ (#120295) 2024-06-09 22:23:30 -04:00
Kirill Podoprigora 34f5ae69fe
gh-120268: Prohibit passing ``None`` to ``_pydatetime.date.fromtimestamp`` (#120269)
This makes the pure Python implementation consistent with the C implementation.
2024-06-08 16:45:57 -04:00
AN Long 5d59b870ef
gh-120121: Add InvalidStateError to concurrent.futures.__all__ (#120123)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-06-08 21:41:19 +05:30
Saul Shanabrook 55402d3232
gh-119258: Eliminate Type Guards in Tier 2 Optimizer with Watcher (GH-119365)
Co-authored-by: parmeggiani <parmeggiani@spaziodati.eu>
Co-authored-by: dpdani <git@danieleparmeggiani.me>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
Co-authored-by: Ken Jin <kenjin@python.org>
2024-06-08 17:41:45 +08:00
Enrico Tröger 2080425154
bpo-37755: Use configured output in pydoc instead of pager (GH-15105)
If the Helper() class was initialized with an output, the topics, keywords
and symbols help still use the pager instead of the output.
Change the behavior so  the output is used if available while keeping the
previous behavior if no output was configured.
2024-06-08 09:19:13 +00:00
Nikita Sobolev 95f4db88d5
gh-120242: Fix handling of `[setUp,tearDown]Class` in `test_datetime` (#120243) 2024-06-08 10:51:09 +03:00
Irit Katriel 4fc82b6d3b
gh-120225: fix crash in compiler on empty block at end of exception handler (#120235) 2024-06-07 22:37:35 +01:00
Eric Snow e6076d1e13
gh-119659: Get the datetime CAPI Tests Running Again (gh-120180)
The tests were accidentally disabled by 2da0dc0, which didn't handle classes correctly.

I considered updating no_rerun() to support classes, but the way test_datetime.py works would have made things fairly messy.  Plus, it looks like the refleaks we had encountered before have been resolved.
2024-06-07 11:44:56 -06:00
Barney Gale 242c7498e5
GH-116380: Move pathlib-specific code from `glob` to `pathlib._abc`. (#120011)
In `glob._Globber`, move pathlib-specific methods to `pathlib._abc.PathGlobber` and replace them with abstract methods. Rename `glob._Globber` to `glob._GlobberBase`. As a result, the `glob` module is no longer befouled by code that can only ever apply to pathlib.

No change of behaviour.
2024-06-07 17:59:34 +01:00
Xi Ruoyao a758424566
gh-120226: Fix test_sendfile_close_peer_in_the_middle_of_receiving on Linux >= 6.10 (#120227)
The worst case is that the kernel buffers 17 pages with a page size of 64k.
2024-06-07 08:51:32 -07:00
Nikita Sobolev 10fb1b8f36
gh-120200: Fix `inspect.iscoroutinefunction(inspect) is True` corner case (#120214) 2024-06-07 18:48:31 +03:00
Pieter Eendebak 9d6604222e
gh-114264: Optimize performance of copy.deepcopy by adding a fast path for atomic types (GH-114266) 2024-06-07 18:42:01 +03:00
Irit Katriel eca3f7762c
gh-93691: fix too broad source locations of with-statement instructions (#120125) 2024-06-07 14:06:24 +01:00
Serhiy Storchaka d68a22e7a6
gh-120211: Fix tkinter.ttk with Tcl/Tk 9.0 (GH-120213)
* Use new methods for tracing Tcl variable.
* Fix Combobox.current() for empty combobox.
2024-06-07 10:49:07 +00:00