repo
stringclasses
1 value
instance_id
stringlengths
20
22
problem_statement
stringlengths
126
60.8k
merge_commit
stringlengths
40
40
base_commit
stringlengths
40
40
python/cpython
python__cpython-111655
# redundant decref on the eval stack value in LOAD_FROM_DICT_OR_DEREF in error path # Crash report ### What happened? With these codes bellow, a `NameError` will be raised as expected, but there will be a runtime crash when GC happens. ```python def xxx(): class MyComplex: MyComplex xxx() ``` Error logs: ``` Traceback (most recent call last): File "C:\Users\xxxxx\Source\cpython\a.py", line 71, in <module> xxx() File "C:\Users\xxxxx\Source\cpython\a.py", line 66, in xxx class MyComplex: File "C:\Users\xxxxx\Source\cpython\a.py", line 67, in MyComplex MyComplex NameError: cannot access free variable 'MyComplex' where it is not associated with a value in enclosing scope. Did you mean: 'complex'? C:\Users\xxxxx\Source\cpython\Objects\frameobject.c:889: _Py_NegativeRefcount: Assertion failed: object has negative ref count <object at 00000150D0CDA990 is freed> Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed Python runtime state: finalizing (tstate=0x00007ffc567001f8) Current thread 0x00003564 (most recent call first): <no Python frame> ``` ### CPython versions tested on: 3.12, CPython main branch ### Operating systems tested on: _No response_ ### Output from running 'python -VV' on the command line: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111655 * gh-111674 <!-- /gh-linked-prs -->
3a1b09e6d070778d78d81084f88d37377d38ee9b
93206d19a35106f64a1aef5fa25eb18966970534
python/cpython
python__cpython-111653
# --enable-pystats compile broken on main # Bug report ### Bug description: Compiling with `--enable-pystats` is currently broken. ``` gcc -c -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I./Include/internal/mimalloc -I. -I./Include -DPy_BUILD_CORE -o Python/ceval.o Python/ceval.c In file included from ./Include/internal/pycore_interp.h:16, from ./Include/internal/pycore_runtime.h:17, from ./Include/internal/pycore_pystate.h:11, from ./Include/internal/pycore_call.h:12, from Python/ceval.c:7: Python/ceval.c: In function ‘_PyEval_EvalFrameDefault’: ./Include/internal/pycore_code.h:291:26: error: implicit declaration of function ‘_Py_bit_length’; did you mean ‘Py_mp_length’? [-Werror=implicit-function-declaration] 291 | int bucket = _Py_bit_length(length >= 1 ? length - 1 : 0); \ | ^~~~~~~~~~~~~~ Python/ceval.c:1049:5: note: in expansion of macro ‘OPT_HIST’ 1049 | OPT_HIST(trace_uop_execution_counter, trace_run_length_hist); | ^~~~~~~~ ``` ### CPython versions tested on: CPython main branch ### Operating systems tested on: Linux <!-- gh-linked-prs --> ### Linked PRs * gh-111653 <!-- /gh-linked-prs -->
2bc01cc0c72a3d91bdcce09886efa987a90396d9
5add7a6724cbff6c9f0597f0257b64c4f0978c14
python/cpython
python__cpython-111647
# The requirement to keep micro-ops dense while optimizing is harmful. The tier 2 executor creation requires optimization passes to compact the micro-ops, which is onerous and error-prone. We should make it part of the job of creating the executor to compact the micro-ops. We will want to modify the tier 2 instruction format, so we will need to do this anyway at some point. <!-- gh-linked-prs --> ### Linked PRs * gh-111647 <!-- /gh-linked-prs -->
d78c872e0d680f6e63afa6661df5021775a03690
c8faa3568afd255708096f6aa8df0afa80cf7697
python/cpython
python__cpython-111713
# test_asyncio: test_unhandled_exceptions() fails on x86-64 macOS 3.x buildbot Apparently, the test is new and was added by PR #111601. cc @kumaraditya303 Logs: ``` test_unhandled_exceptions (test.test_asyncio.test_streams.StreamTests.test_unhandled_exceptions) ... Warning -- threading_cleanup() failed to cleanup 1 threads (count: 1, dangling: 2) Warning -- Dangling thread: <_MainThread(MainThread, started 4648830464)> ok ``` build: https://buildbot.python.org/all/#/builders/366/builds/5796 <!-- gh-linked-prs --> ### Linked PRs * gh-111713 * gh-111714 * gh-111716 * gh-111717 * gh-111718 <!-- /gh-linked-prs -->
ac01e2243a1104b2154c0d1bdbc9f8d5b3ada778
f62c7ccf9abf6e0493978da9cf9ca43adcd403f9
python/cpython
python__cpython-129546
# Extension for MIME type is not recognized # Bug report ### Bug description: I currently have a problem with guessing file extensions from the MIME type, unfortunately. I understood that only files with a registry at IANA can be guessed and checked the linked page. As I understand, my affected data is registered with IANA. The IANA link: https://www.iana.org/assignments/media-types/application/vnd.openxmlformats-officedocument.wordprocessingml.document ```python Python 3.11.5 (main, Sep 2 2023, 14:16:33) [GCC 13.2.1 20230801] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import mimetypes >>> print(mimetypes.guess_extension("vnd.openxmlformats-officedocument.wordprocessingml.document")) None ``` I hoped to see `.docx` as a return value ### CPython versions tested on: 3.11 ### Operating systems tested on: Linux, Windows <!-- gh-linked-prs --> ### Linked PRs * gh-129546 <!-- /gh-linked-prs -->
bb5c6875d6e84bf2b4e134ed482141a51d223f09
75b628adebd4594529da25ea9915600f2872fc2b
python/cpython
python__cpython-111626
# DOC: fix link redirect and correct spelling of Info-ZIP # Documentation [Download the documentation](https://docs.python.org/3.13/download.html) page links to http://www.info-zip.org/ which then redirects to the correct homepage https://infozip.sourceforge.net/ for Info-ZIP. Also, "InfoZIP" should be spelled as "Info-ZIP". [zipfile](https://docs.python.org/3.13/library/zipfile.html) uses correct spelling for "Info-ZIP" and correct URL for its homepage: https://infozip.sourceforge.net/ <!-- gh-linked-prs --> ### Linked PRs * gh-111626 * gh-111639 * gh-111640 <!-- /gh-linked-prs -->
6a0d7b43df12ab4426badd09d2796e66838129ac
7215f173f5881f53728679d03b0f513716d8c099
python/cpython
python__cpython-111628
# Enable cross-interpreter sharing of tuples # Feature or enhancement ### Proposal: This issue is for adding support of sharing tuples (and tuples of tuples) through the crossinterp API and the interpreters module when that arrives. The data structure will have to have a variable length. ```c struct _shared_tuple_data { Py_ssize_t len; _PyCrossInterpreterData **data; }; ``` It will use the xid registry to lookup the type values in the tuple, then encode them using the crossinterpdatafunc callbacks. This should work recursively if the tuple contains a tuple. PR to follow. ### Has this already been discussed elsewhere? No response given ### Links to previous discussion of this feature: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111628 <!-- /gh-linked-prs -->
178861b19324c94d98478e4c2bba075964c3baa4
70afb8d7324bc74fe64141e1af5c602bf6c0c4dd
python/cpython
python__cpython-112051
# `dict` items views have set like operations even when the values are not hashable. # Documentation > Keys views are set-like since their entries are unique and [:term:`hashable`](https://github.com/python/cpython/blob/main/Doc/library/stdtypes.rst#id650). If all values are hashable, so that (key, value) pairs are unique and hashable, then the items view is also set-like. (Values views are not treated as set-like since the entries are generally not unique.) For set-like views, all of the operations defined for the abstract base class [:class:`collections.abc.Set`](https://github.com/python/cpython/blob/main/Doc/library/stdtypes.rst#id652) are available (for example, ==, <, or ^). While using set operators, set-like views accept any iterable as the other operand, unlike sets which only accept sets as the input. ``` > {1:2, 3:4}.items() >= {1:2}.items() True > {1:[2], 3:4}.items() >= {1:[2]}.items() True > set({1:[2], 3:4}.items()) TypeError: unhashable type: 'list' ``` It seems like this documentation is not accurate. `dict.items()` does have set operations even when the values are not hashable. See also: https://stackoverflow.com/questions/77399592/set-like-behaviour-of-dict-items-for-non-hashable-values <!-- gh-linked-prs --> ### Linked PRs * gh-112051 * gh-112052 <!-- /gh-linked-prs -->
e31d65e0b7bb6d6fee4e8df54e10976b4cfab1de
31ad7e061ebebc484e00ed3ad5ff61061341c35e
python/cpython
python__cpython-111638
# Python 3.12 breaks backwards compatibility for logging configuration # Bug report ### Bug description: This worked fine on previous versions: ```python import logging import logging.config import logging.handlers import multiprocessing as mp def main(): config = { 'version': 1, 'handlers': { 'sink': { 'class': 'logging.handlers.QueueHandler', 'queue': mp.get_context('spawn').Queue(), }, }, 'root': { 'handlers': ['sink'], 'level': 'DEBUG', }, } logging.config.dictConfig(config) if __name__ == '__main__': main() ``` With Python 3.12, it drops an error: ``` Traceback (most recent call last): File "/home/egor/.pyenv/versions/3.12-dev/lib/python3.12/logging/config.py", line 581, in configure handler = self.configure_handler(handlers[name]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/egor/.pyenv/versions/3.12-dev/lib/python3.12/logging/config.py", line 786, in configure_handler raise ValueError('No handlers specified for a QueueHandler') ValueError: No handlers specified for a QueueHandler The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/egor/workspace/personal/cimple/../test.py", line 25, in <module> main() File "/home/egor/workspace/personal/cimple/../test.py", line 21, in main logging.config.dictConfig(config) File "/home/egor/.pyenv/versions/3.12-dev/lib/python3.12/logging/config.py", line 912, in dictConfig dictConfigClass(config).configure() File "/home/egor/.pyenv/versions/3.12-dev/lib/python3.12/logging/config.py", line 588, in configure raise ValueError('Unable to configure handler ' ValueError: Unable to configure handler 'sink' ``` More than that, even the example in the Logging Cookbook is broken now: https://docs.python.org/3/howto/logging-cookbook.html#a-more-elaborate-multiprocessing-example (fails with the same error). Version info: ``` # python -VV Python 3.12.0+ (heads/3.12:f108785, Nov 1 2023, 19:47:19) [GCC 13.2.1 20230801] ``` ### CPython versions tested on: 3.12 ### Operating systems tested on: Linux <!-- gh-linked-prs --> ### Linked PRs * gh-111638 * gh-113507 <!-- /gh-linked-prs -->
67655d8ad5de8666c97b0a377c6141a6abf66350
00cdd416fc60876ff21d9eafdc5d5d7a91737db5
python/cpython
python__cpython-111578
# Improve documention for tkinter.messagebox <!-- gh-linked-prs --> ### Linked PRs * gh-111578 * gh-111597 * gh-111598 <!-- /gh-linked-prs -->
eaf67e37a2da28c1241362e3b4ff1202945c83c5
33ed5fa69dbe25d64a910c450be527f4db9dc5dd
python/cpython
python__cpython-111571
# Implement Python Critical Sections from PEP 703 # Feature or enhancement [PEP 703](https://peps.python.org/pep-0703/) introduces the concept of ["Python Critical Sections"](https://peps.python.org/pep-0703/#python-critical-sections), which are an abstraction to help replace the GIL with finer grained locking. The key ideas is to replace the GIL with per-object locks and *implicitly* release these locks in the same places where the GIL would have been released. The mechanism is: 1) Keep track of locked mutexes in a per-thread stack 2) When the thread ["detaches"](https://peps.python.org/pep-0703/#thread-states) from the interpreter (i.e., [`_PyThreadState_Detach()`](https://github.com/python/cpython/blob/244567398370bfa62a332676762bb1db395c02fc/Include/internal/pycore_pystate.h#L143-L147)), unlock all of the thread's locked mutexes 3) When the thread re-["attaches"](https://peps.python.org/pep-0703/#thread-states) to the interpreter, re-lock the top-most mutex or mutexes. The "public" [^public] API consists of four macros: ```c Py_BEGIN_CRITICAL_SECTION(object); Py_END_CRITICAL_SECTION; Py_BEGIN_CRITICAL_SECTION2(object1, object2); Py_END_CRITICAL_SECTION2; ``` These will be no-ops in the default build of CPython. Note that if you need to operate on two objects at once, then you must use the `Py_BEGIN_CRITICAL_SECTION2` macro. Nesting two calls to `Py_BEGIN_CRITICAL_SECTION` does not guarantee that both objects are locked because the inner calls may suspend the outer critical section. [^public]: At least at the start, even these "public" macros will still be internal-only (i.e., in `Include/internal`). I expect that we will eventually want to make them public so that C-API extensions can make use of them. <!-- gh-linked-prs --> ### Linked PRs * gh-111571 * gh-111897 <!-- /gh-linked-prs -->
31c90d5838e8d6e4c47d98500a34810ccb33a6d4
0b718e6407da65b838576a2459d630824ca62155
python/cpython
python__cpython-112063
# Make `_Py_HashDouble` public again as "unstable" API In NumPy we use `_Py_HashDouble` for our floating point hashing needs and that seems like a pretty good candiate for the unstable API to me: https://github.com/python/cpython/issues/91744#issuecomment-1111990057 and https://github.com/python/cpython/issues/101101#issue-1536645235. However, the function is currently removed rather than made unstable (to my understanding). While it should probably be easy enough to vendor what we needed, I would prefer the unstable API tier, it gives a better sense of having the required identical hashing. NumPy issue: https://github.com/numpy/numpy/issues/25035 _Originally reported by @ngoldbaum in https://github.com/python/cpython/issues/111418#issuecomment-1785929387_ <!-- gh-linked-prs --> ### Linked PRs * gh-112063 * gh-112095 * gh-112096 * gh-112098 * gh-112449 * gh-112476 * gh-112647 * gh-113115 <!-- /gh-linked-prs -->
62802b6228f001e1a4af6ac668a21d2dcec0ce57
9302f05f9af07332c414b3c19003efd1b1763cf3
python/cpython
python__cpython-111593
# AIX build breaks due to syscall.h not found # Bug report ### Bug description: AIX build breaks because of the recent commit #109914 gcc -pthread -maix64 -c -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I./Include/internal/mimalloc -I. -I./Include -DPy_BUILD_CORE -o Objects/obmalloc.o Objects/obmalloc.c In file included from Objects/mimalloc/prim/prim.c:22, from Objects/mimalloc/static.c:37, from Objects/obmalloc.c:15: Objects/mimalloc/prim/unix/prim.c:55:12: fatal error: sys/syscall.h: No such file or directory 55 | #include <sys/syscall.h> | ^~~~~~~~~~~~~~~ compilation terminated. AIX don't have syscall.h. ### CPython versions tested on: CPython main branch ### Operating systems tested on: Other <!-- gh-linked-prs --> ### Linked PRs * gh-111593 <!-- /gh-linked-prs -->
794dff2fb1d9efe73a724640192c34b25f4fae85
230e8e924dbafe093fd1cc7b6c510dc0b9ec0caf
python/cpython
python__cpython-111600
# New warning: `unused variable ‘this_instr’` in `generated_cases.c.h` # Bug report Introduced in https://github.com/python/cpython/commit/d27acd4461ee603bcf6f4a81ca6afccc9fc87331 <img width="403" alt="Снимок экрана 2023-10-31 в 13 52 14" src="https://github.com/python/cpython/assets/4660275/8e817a04-c061-4e8b-a915-fd39bc5ebabc"> <!-- gh-linked-prs --> ### Linked PRs * gh-111600 <!-- /gh-linked-prs -->
5697fc2d4bff000b2b1dac493d45872ca648490b
b14e882428ceda1e5852a1c22772e7f88927bded
python/cpython
python__cpython-111533
# test_tkinter leaks references on Windows * Latest successful build: https://buildbot.python.org/all/#/builders/920/builds/543 * First failing build: https://buildbot.python.org/all/#/builders/920/builds/549 ``` test_tkinter leaked [336, 336, 337] references, sum=1009 test_tkinter leaked [151, 151, 152] memory blocks, sum=454 ``` <!-- gh-linked-prs --> ### Linked PRs * gh-111533 * gh-111535 * gh-111536 <!-- /gh-linked-prs -->
e3353c498d79f0f3f108a9baf8807a12e77c2ebe
3dbaed3caa00062087a848740b6e713ad55b0aed
python/cpython
python__cpython-111428
# Merge Tier 1 and 2 interpreters into a single function Currently the Tier 2 interpreter lives in a separate function. This looks clean but makes switching between tiers complicated. See https://github.com/faster-cpython/ideas/issues/631. So let's make `_PyEval_EvalFrameDefault()` into a single function that contains both interpreter loops. <!-- gh-linked-prs --> ### Linked PRs * gh-111428 * gh-111813 <!-- /gh-linked-prs -->
7e135a48d619407cd4b2a6d80a4ce204b2f5f938
5d6db168b9cda58b4897763041a6109b93e421cb
python/cpython
python__cpython-120021
# PYTHONMALLOCSTATS=1 fails with fatal error at Python exit `Py_FinalizeEx()` calls `_PyObject_DebugMallocStats()` which calls indirectly `_PyInterpreterState_GET()`. Problem: at this point, there is no "interpreter" anymore, and so `_PyInterpreterState_GET()` fails with a fatal error. It's a regression introduced by commit df3173d28ef25a0f97d2cca8cf4e64e062a08d06. Python 3.12 is also affected. Reproducer: ``` $ PYTHONMALLOCSTATS=1 ./python -c pass Small block threshold = 512, in 32 size classes. (...) Total = 262,144 Small block threshold = 512, in 32 size classes. (...) Total = 655,360 Fatal Python error: _PyInterpreterState_GET: the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL) Python runtime state: finalizing (tstate=0x0000000000ae7550) Abandon (core dumped) ``` cc @ericsnowcurrently <!-- gh-linked-prs --> ### Linked PRs * gh-120021 * gh-120022 * gh-120023 <!-- /gh-linked-prs -->
5a1205b641df133932ed4c65b9a4ff5724e89963
26e5c6e8351adb1a77a88920ff33fc8ebee9a99e
python/cpython
python__cpython-111496
# Add more C API tests - [x] Add tests for PyBytes C API - [x] Add tests for PyByteArray C API - [x] Add tests for PyFloat C API - [x] Add tests for PyComplex C API - [x] Add tests for PyLong C API - [x] Add tests for PyNumber C API - [x] Add tests for PyTuple C API - [x] Add tests for PyList C API - [x] Add tests for PyCodec C API - [x] Add tests for PyFile C API <!-- gh-linked-prs --> ### Linked PRs * gh-111496 * gh-111562 * gh-111586 * gh-111591 * gh-111592 * gh-111606 * gh-111607 * gh-111624 * gh-111631 * gh-111709 * gh-111731 * gh-111752 * gh-111753 * gh-111861 * gh-111996 * gh-118757 * gh-122789 * gh-122833 * gh-122851 * gh-123338 * gh-123343 * gh-123371 * gh-123375 * gh-123376 * gh-123379 * gh-124915 * gh-126030 * gh-128987 * gh-129023 * gh-129449 * gh-129477 * gh-129501 <!-- /gh-linked-prs -->
97b3cd38d105fd891ba46dd27d08f03d1c6dd348
937872e8ea740e22ff571eec474e38312e09bd68
python/cpython
python__cpython-111491
# `test_pyexpat` has strange `assertRaises` check # Bug report Look at this test: https://github.com/python/cpython/blob/940ee962a8a1e87543fd36338228e526e7f35067/Lib/test/test_pyexpat.py#L531-L547 It sets up a specific error class, does all the overriding just to check that raw `Exception` is raised? It is problematic, because some different exception type might be raised there, like `TypeError`, not `SpecificError`, I don't see a reason to keep this test so forgiving. <!-- gh-linked-prs --> ### Linked PRs * gh-111491 <!-- /gh-linked-prs -->
7bcf184dacf5cfbcb16b4c2735472314b03a009e
26c0e5e03a8603eccfd98045bc69fde2e24682e3
python/cpython
python__cpython-113656
# Confusing `SyntaxError` message for `x for x if range(1)` # Bug report Today I made a typo: instead of `in` I wrote `if`. I was quite interested to see the error message: ```python >>> [x for x if range(1)] File "<stdin>", line 1 [x for x if range(1)] ^^^^^^^^^^^^^ SyntaxError: expected 'else' after 'if' expression ``` I don't think that this error message is correct. Why? Because even if we follow the rabbit hole and use `else`, we won't be ever correct: ```python >>> [x for (x if range(1) else y) in range(1)] File "<stdin>", line 1 [x for (x if range(1) else y) in range(1)] ^^^^^^^^^^^^^^^^^^^^ SyntaxError: cannot assign to conditional expression ``` So, maybe we should change it to be something like: ```python >>> [x for x if range(1)] File "<stdin>", line 1 [x for x if range(1)] ^^ SyntaxError: expected 'in', got 'if' ``` Suggestions about wording are welcome :) If others agree, I would like to work on this. <!-- gh-linked-prs --> ### Linked PRs * gh-113656 <!-- /gh-linked-prs -->
bb4c16706059f2b10f077dce6a9f9f04e146d424
bbf214df23be3ee5daead119e8a2506d810d7d1f
python/cpython
python__cpython-111486
# The code generated for the interpreter(s) is too fragile Changing the name of an instruction, or slight changes in cache size can cause the generated code to be incorrect in odd ways. This is a result of there being too many special cases and undocumented assumptions built in to the code generator. This was a natural result of getting the thing working and was, until now, acceptable technical debt. However, as we want to generate abstract interpreters, a new combiner tier-1/tier-2 interpreter and possible tail-calling interprtet/JIT compiler pair, things are too fragile. We need to: * Reduce the number of ad-hoc special cases in the tools to zero. * Minimize and very clearly specify any special markers and variables we use in `bytecodes.c` * Clarify the in-memory state and transitions of execution. * Document the representation of that state in the various tiers and components. <!-- gh-linked-prs --> ### Linked PRs * gh-111486 * gh-111540 * gh-111547 * gh-111561 * gh-111619 * gh-111697 * gh-111812 * gh-112299 * gh-112315 * gh-112831 * gh-112877 * gh-112968 * gh-113101 * gh-113155 * gh-113169 * gh-113252 * gh-113287 * gh-113319 * gh-113321 * gh-113324 * gh-113394 <!-- /gh-linked-prs -->
d27acd4461ee603bcf6f4a81ca6afccc9fc87331
e3353c498d79f0f3f108a9baf8807a12e77c2ebe
python/cpython
python__cpython-111641
# time.clock_gettime_ns() is too slow # Feature or enhancement ### Proposal: Actually, this is a performance bug. Not a feature/enhancement. `clock_gettime_ns()` does not use floating point operations and should be faster than old `gettimeofday()`. Unfotunately in Python it's not so. Checked in Linux X86_64 kernel 6.5.7, CPython 3.11.6 ```python In [11]: timeit time.clock_gettime_ns(0) # CLOCK_REALTIME 55.4 ns ± 1.22 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) In [12]: timeit time.clock_gettime_ns(5) # CLOCK_REALTIME_COARSE 45 ns ± 0.324 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) In [13]: timeit time.time() 36.7 ns ± 0.953 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) ``` ### Has this already been discussed elsewhere? This is a minor feature, which does not need previous discussion elsewhere ### Links to previous discussion of this feature: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111641 * gh-112170 <!-- /gh-linked-prs -->
4fe22c73770fe86b01ef7a4f1f38e7e925c0e090
6a0d7b43df12ab4426badd09d2796e66838129ac
python/cpython
python__cpython-111878
# Restore ncurses widechar support on macOS # Bug report ### Bug description: Python 3.12 dropped ncurses wide char support on macOS, so for example `curses.get_wch()` is not available anymore. I believe this was an unintended consequence of https://github.com/python/cpython/pull/94452, because the change is not documented anywhere. After that PR, HAVE_NCURSESW is never defined on Darwin. It looks like this bit of logic was not ported from setup.py to configure.ac: https://github.com/python/cpython/blob/ec5e253556875640b1ac514e85c545346ac3f1e0/setup.py#L1121-L1124 In fact, wide char support is always available when using Apple-provided ncurses, and it used to work correctly in the 3.11 builds that I tested. @tiran can you confirm that this was unintended? cc @sobolevn who interpreted this as an intended change in https://github.com/python/typeshed/pull/10808. ### CPython versions tested on: 3.12, 3.13 ### Operating systems tested on: macOS <!-- gh-linked-prs --> ### Linked PRs * gh-111878 * gh-112034 <!-- /gh-linked-prs -->
d2f305dfd183025a95592319b280fcf4b20c8694
1447af797048e62049d00bbd96d8daee3929f527
python/cpython
python__cpython-111439
# Support sharing of float types in sub interpreters # Feature or enhancement ### Proposal: The interpreters API supports sharing of `int` but not the `float` type. ### Has this already been discussed elsewhere? This is a minor feature, which does not need previous discussion elsewhere ### Links to previous discussion of this feature: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111439 <!-- /gh-linked-prs -->
ad6380bc340900e0977ce54928b0d3e166c7cf99
2904d99839cd4620818fd0556a1c0b0229944abc
python/cpython
python__cpython-111436
# Support sharing of bool objects in sub interpreters # Feature or enhancement ### Proposal: Bool is not a shareable type in the interpreters API. ```python Python 3.13.0a1+ (heads/master-dirty:66bea2555d, Oct 29 2023, 11:16:00) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import _xxsubinterpreters >>> _xxsubinterpreters.is_shareable(True) False ``` ### Has this already been discussed elsewhere? This is a minor feature, which does not need previous discussion elsewhere ### Links to previous discussion of this feature: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111436 <!-- /gh-linked-prs -->
230e8e924dbafe093fd1cc7b6c510dc0b9ec0caf
9322ce90ac8f4d4647a59bbfab48fad6f4e4e856
python/cpython
python__cpython-111431
# Speed up `pathlib.PurePath.[is_]relative_to()` Both methods call `self.with_segments()` unconditionally. This can be skipped if the *other* argument is already an instance of `PurePath`, and no further (deprecated) positional arguments are given. Also, `relative_to()` can inline the core of the `is_relative_to()` check to avoid the type/deprecated args checks. <!-- gh-linked-prs --> ### Linked PRs * gh-111431 <!-- /gh-linked-prs -->
d7cef7bc7ea5478abb90a37c8ffb0792cc6e7518
b2af50cb0266f654cff126c7a78a4a7755bc3fbe
python/cpython
python__cpython-111427
# `test_cmd` has `test_coverage` that does not work # Bug report https://github.com/python/cpython/blob/26553695592ad399f735d4dbaf32fd871d0bb1e1/Lib/test/test_cmd.py#L251-L262 Output: ``` » ./python.exe Lib/test/test_cmd.py -c Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython2/Lib/test/test_cmd.py", line 262, in <module> test_coverage('/tmp/cmd.cover') File "/Users/sobolev/Desktop/cpython2/Lib/test/test_cmd.py", line 252, in test_coverage trace = support.import_module('trace') ^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'test.support' has no attribute 'import_module' ``` Even, if refactored to: ```python def test_coverage(coverdir): from test.support import import_helper trace = import_helper.import_module('trace') tracer=trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,], trace=0, count=1) tracer.run('import unittest; unittest.main()') r=tracer.results() print("Writing coverage results...") r.write_results(show_missing=True, summary=True, coverdir=coverdir) ``` It still does not work, no file is generated. I propose to remove it, since `-T` works just fine: ``` » ./python.exe -m test -T test_cmd Using random seed: 2974785131 0:00:00 load avg: 1.22 Run 1 test sequentially 0:00:00 load avg: 1.22 [1/1] test_cmd == Tests result: SUCCESS == 1 test OK. Total duration: 78 ms Total tests: run=3 Total test files: run=1/1 Result: SUCCESS lines cov% module (path) ... 236 63% cmd (/Users/sobolev/Desktop/cpython2/Lib/cmd.py) ... ``` I have a PR ready. related https://github.com/python/cpython/issues/111348 <!-- gh-linked-prs --> ### Linked PRs * gh-111427 * gh-111432 * gh-111433 <!-- /gh-linked-prs -->
66bea2555dc7b3dd18282cc699fe9a22dea50de3
81bc802a46f6f2725913ac31b4cec0ec3a0e3732
python/cpython
python__cpython-111468
# ast.parse(type_comments=True) fails on some parenthesized context managers # Bug report ### Bug description: `ast.parse(..., type_comments=True)` doesn't deal well with parenthesized context managers, as introduced by PEP-617. ``` >>> ast.dump(ast.parse("with (a as b): # type: something\n pass", type_comments=True)) Traceback (most recent call last): File "<stdin>", line 1, in <module> ast.dump(ast.parse("with (a as b): # type: something\n pass", type_comments=True)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jelle/py/cpython/Lib/ast.py", line 61, in parse return compile( ^^^^^^^^ File "<unknown>", line 1 with (a as b): # type: something ^^^^^^^^^ SyntaxError: invalid syntax ``` But this works without the parentheses: ``` >>> ast.dump(ast.parse("with a as b: # type: something\n pass", type_comments=True)) "Module(body=[With(items=[withitem(context_expr=Name(id='a', ctx=Load()), optional_vars=Name(id='b', ctx=Store()))], body=[Pass()], type_comment='something')], type_ignores=[])" ``` This code gets interpreted incorrectly: ``` >>> ast.dump(ast.parse("with (a, b): # type: something\n pass", type_comments=True)) "Module(body=[With(items=[withitem(context_expr=Tuple(elts=[Name(id='a', ctx=Load()), Name(id='b', ctx=Load())], ctx=Load()))], body=[Pass()], type_comment='something')], type_ignores=[])" ``` There is a single `withitem` containing a tuple, when it should instead be two withitems, as happens without the comment: ``` >>> ast.dump(ast.parse("with (a, b):\n pass", type_comments=True)) "Module(body=[With(items=[withitem(context_expr=Name(id='a', ctx=Load())), withitem(context_expr=Name(id='b', ctx=Load()))], body=[Pass()])], type_ignores=[])" ``` Found this while looking into psf/black#3677. ### CPython versions tested on: CPython main branch ### Operating systems tested on: macOS <!-- gh-linked-prs --> ### Linked PRs * gh-111468 <!-- /gh-linked-prs -->
453e96e3020d38cfcaebf82b24cb681c6384fa82
faa5f6053d7334a3ecc513c64947ac026439c03a
python/cpython
python__cpython-111454
# Useless code block in math.trunc() ? # Bug report ### Bug description: The math.trunc function has: https://github.com/python/cpython/blob/f013b475047b2e9d377feda9f2e16e5cdef824d7/Modules/mathmodule.c#L2073-L2076 c.f. [math.ceil](https://github.com/python/cpython/blob/f013b475047b2e9d377feda9f2e16e5cdef824d7/Modules/mathmodule.c#L1124-L1148) or [math.floor](https://github.com/python/cpython/blob/f013b475047b2e9d377feda9f2e16e5cdef824d7/Modules/mathmodule.c#L1193-L1217). This seems to be a history artifact: the function was introduced in https://github.com/python/cpython/commit/400adb030a78c3fcb1eb458b25c990449fbf3c93 as a moved __builtins__.trunc(), while math.ceil/floor were here from the initial revision. I think it's safe to remove mentioned block. PS: Issue opened per @serhiy-storchaka suggestion in #110000. ### CPython versions tested on: CPython main branch ### Operating systems tested on: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111454 <!-- /gh-linked-prs -->
efc489021c2a5dba46979bd304563aee0c479a31
28bb2961ba2f650452c949fcfc75ccfe0b5517e9
python/cpython
python__cpython-111407
# Link to bpython's website is broken # Documentation I noticed a broken link on this page: https://docs.python.org/3/tutorial/interactive.html It links to https://www.bpython-interpreter.org/, which does not exist: ```bash $ rh HEAD https://www.bpython-interpreter.org/ -s Error: error sending request for url (https://www.bpython-interpreter.org/): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known ``` https://bpython-interpreter.org/ does, though: ```bash $ rh HEAD https://bpython-interpreter.org/ -s HTTP/2.0 200 OK ``` <!-- gh-linked-prs --> ### Linked PRs * gh-111407 * gh-111408 * gh-111409 <!-- /gh-linked-prs -->
8a158a753c48d166ebceae0687e88ae0c0725c02
9a2f2f46caa556eae4c3ac3b45efa85bd91cc807
python/cpython
python__cpython-111418
# Consider restoring _PyHASH_INF/BITS/MODULUS/IMAG as public This is used to implement CPython-like hashing of numeric types e.g. [in Sage](https://github.com/sagemath/sage/blob/07a2afd65fb4b0a1c9cbc43ede7d4a18c921a000/src/sage/libs/gmp/pylong.pyx#L35-L52) or [in gmpy2](https://github.com/aleaxit/gmpy/blob/master/src/gmpy2_hash.c). Actually, the same info is available via ``sys.hash_info``, so I don't see reasons to hide this in Python.h. See #106320 and #107026. <!-- gh-linked-prs --> ### Linked PRs * gh-111418 * gh-119214 * gh-119334 <!-- /gh-linked-prs -->
1e68c4b87633b17da1b602b86f5d23bbe106398f
b9cb855621c0813846421e4ced97260a32e57063
python/cpython
python__cpython-111390
# Add `show_group` param to `traceback.format_exception_only` function # Feature or enhancement This function does not have this param: https://github.com/python/cpython/blob/7f9a99e8549b792662f2cd28bf38a4d4625bd402/Lib/traceback.py#L151-L166 While the `format_exception_only` method of `TracebackException` does have this param. So, in order to proceed with https://github.com/python/cpython/issues/104150 I need this function to give me `ExceptionGroup` information. I have a PR ready. <!-- gh-linked-prs --> ### Linked PRs * gh-111390 <!-- /gh-linked-prs -->
aa732459c5a69435f13a2730a057ce9d2087873b
6d42759c5e47ab62d60a72b4ff15d29864554579
python/cpython
python__cpython-111387
# New warning: `'=': conversion from 'unsigned __int64' to 'uint16_t'` in `generated_cases.c.h` # Bug report <img width="987" alt="Снимок экрана 2023-10-27 в 08 59 30" src="https://github.com/python/cpython/assets/4660275/8cabd18f-253a-42fd-bca1-770bdc85b60a"> This line was last changed in https://github.com/python/cpython/pull/109095 I will try to fix it right now. <!-- gh-linked-prs --> ### Linked PRs * gh-111387 <!-- /gh-linked-prs -->
524a701d0742d2ae469771a065c62e41656a5dc7
aa732459c5a69435f13a2730a057ce9d2087873b
python/cpython
python__cpython-111381
# Some SyntaxWarning in strings are shown twice in the presence of SyntaxErrors Example: ``` ❯ ./python.exe -Wall Python 3.13.0a1+ (heads/main:78e6d72e38e, Oct 27 2023, 11:50:08) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> '\e' $ <stdin>:1: SyntaxWarning: invalid escape sequence '\e' <stdin>:1: SyntaxWarning: invalid escape sequence '\e' File "<stdin>", line 1 '\e' $ ^ SyntaxError: invalid syntax ``` <!-- gh-linked-prs --> ### Linked PRs * gh-111381 * gh-111382 * gh-111383 <!-- /gh-linked-prs -->
3d2f1f0b830d86f16f42c42b54d3ea4453dac318
a254120f2f1dd99fa64f12594d1ed19c67df7d64
python/cpython
python__cpython-111411
# Support configuring -X frozen_modules=on|off using an environment variable. # Feature or enhancement ### Proposal: Most of the `-X` options (https://docs.python.org/3/using/cmdline.html#cmdoption-X) can be configured via an environment variable, but not `-X frozen_modules`. This makes it harder for environments that you don't have the control over the flags passed to the Python interpreter. https://github.com/python/cpython/issues/98697 also includes a use case for [crossenv](https://github.com/benfogle/crossenv), but the issue was closed because it was not in time for Python 3.11. I'm proposing a ~~`PYTHONFROZENMODULES`~~ `PYTHON_FROZEN_MODULES` environment variable to be added for Python 3.13, which has the equivalent meaning of using `-X frozen_modules`. ### Has this already been discussed elsewhere? This is a minor feature, which does not need previous discussion elsewhere ### Links to previous discussion of this feature: https://github.com/python/cpython/issues/98697 is the same request, but closed due to not in time for Python 3.11. <!-- gh-linked-prs --> ### Linked PRs * gh-111411 <!-- /gh-linked-prs -->
486d5370653d86aba4348067bd61b973297c22c3
2433cc79d79d9c1db8e53d4b9bde26e9a47fb0b9
python/cpython
python__cpython-111384
# Uninformative syntax errors from codeop._maybe_compile (IDLE Shell) ```py >>> def function(duplicate, duplicate): ... pass # Expected error message: SyntaxError: duplicate argument 'duplicate' in function definition # Actual error message: SyntaxError: incomplete input ``` ```py >>> def global_and_parameter(argument, /): ... global argument # It may not be clear for less experienced coders # that a name cannot be global and parameter SyntaxError: incomplete input # However when executed with exec(): SyntaxError: name 'argument' is parameter and global ``` <!-- gh-linked-prs --> ### Linked PRs * gh-111384 * gh-111516 * gh-111517 <!-- /gh-linked-prs -->
cd6e0a04a16535d8bc727c84f73730c53267184e
624ace5a2f02715d084c29eaf2211cd0dd550690
python/cpython
python__cpython-112031
# Mention that unicodedata is updated for Unicode 15.1.0 in What's new in Python 3.13 # Documentation In Python 3.13 `unicodedata` is updated for Unicode 15.1.0 (https://github.com/python/cpython/commit/def828995a35a289c9f03500903b5917df93465f). It would be nice to have this explicitly mentioned on the [What's new in Python 3.13](https://docs.python.org/3.13/whatsnew/3.13.html) page. <!-- gh-linked-prs --> ### Linked PRs * gh-112031 <!-- /gh-linked-prs -->
d857d5331a3326c77f867d837014d774841017a9
4c483e011379aee9258db2e8abe479448109fd7b
python/cpython
python__cpython-111370
# text_encoding() is missing from io.__all__ # Bug report ### Bug description: The public [`io.text_encoding()`](https://docs.python.org/3/library/io.html?highlight=text_encoding#io.text_encoding) function is missing from `io.__all__`. ```python >>> import io >>> "text_encoding" in io.__all___ False ``` ### CPython versions tested on: 3.10, 3.11, 3.12 ### Operating systems tested on: macOS <!-- gh-linked-prs --> ### Linked PRs * gh-111370 * gh-111935 * gh-111936 <!-- /gh-linked-prs -->
baeb7718f8981319c5cb1fbdd46d162ded7964ea
289af8612283508b67d7969d7182070381b4349b
python/cpython
python__cpython-111365
# remove hacks in genobject.c Refactor Objects/genobject.c to get rid of these hacks/issues: - ~~`gen_close` accesses `instr_ptr - 1`~~ - `_PyGen_yf` peeks into the execution stack - Comparisons with enum values - ``result`` arg reused in ``gen_send_ex2`` for two different purposes (one of which is not the result) <!-- gh-linked-prs --> ### Linked PRs * gh-111365 * gh-111368 * gh-111459 * gh-111648 * gh-111708 <!-- /gh-linked-prs -->
a0c414c35d0dc0d44a885fda448652e23de2482c
309efb39dc005a834bb67e9a6f27b6689f00ec9d
python/cpython
python__cpython-111349
# `test_doctest` cannot be run directly: let's remove this option # Bug report When running `./python.exe Lib/test/test_doctest.py` you get: ``` » ./python.exe Lib/test/test_doctest.py .....................................F................FF......... ====================================================================== FAIL: basics (__main__.test_DocTestFinder) Doctest: __main__.test_DocTestFinder.basics ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 2353, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for __main__.test_DocTestFinder.basics File "/Users/sobolev/Desktop/cpython/Lib/test/test_doctest.py", line 445, in basics ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/test_doctest.py", line 469, in __main__.test_DocTestFinder.basics Failed example: print(tests) # doctest: +ELLIPSIS Expected: [<DocTest sample_func from test_doctest.py:32 (1 example)>] Got: [<DocTest sample_func from /Users/sobolev/Desktop/cpython/Lib/test/test_doctest.py:32 (1 example)>] ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/test_doctest.py", line 576, in __main__.test_DocTestFinder.basics Failed example: for t in tests: print('%2s %s' % (len(t.examples), t.name)) Expected: 1 some_module 3 some_module.SampleClass 3 some_module.SampleClass.NestedClass 1 some_module.SampleClass.NestedClass.__init__ 1 some_module.SampleClass.__init__ 1 some_module.SampleClass.a_cached_property 2 some_module.SampleClass.a_classmethod 1 some_module.SampleClass.a_classmethod_property 1 some_module.SampleClass.a_property 1 some_module.SampleClass.a_staticmethod 1 some_module.SampleClass.double 1 some_module.SampleClass.get 1 some_module.__test__.c 2 some_module.__test__.d 1 some_module.sample_func Got: 1 some_module 1 some_module.__test__.c 2 some_module.__test__.d ====================================================================== FAIL: test_pdb_set_trace (__main__) Doctest: __main__.test_pdb_set_trace ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 2353, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for __main__.test_pdb_set_trace File "/Users/sobolev/Desktop/cpython/Lib/test/test_doctest.py", line 1984, in test_pdb_set_trace ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/test_doctest.py", line 2043, in __main__.test_pdb_set_trace Failed example: try: runner.run(test) finally: sys.stdin = real_stdin Expected: --Return-- > <doctest test.test_doctest.test_pdb_set_trace[7]>(3)calls_set_trace()->None -> import pdb; pdb.set_trace() (Pdb) print(y) 2 (Pdb) up > <doctest foo-bar@baz[1]>(1)<module>() -> calls_set_trace() (Pdb) print(x) 1 (Pdb) continue TestResults(failed=0, attempted=2) Got: --Return-- > <doctest __main__.test_pdb_set_trace[7]>(3)calls_set_trace()->None -> import pdb; pdb.set_trace() (Pdb) print(y) 2 (Pdb) up > <doctest foo-bar@baz[1]>(1)<module>() -> calls_set_trace() (Pdb) print(x) 1 (Pdb) continue TestResults(failed=0, attempted=2) ====================================================================== FAIL: test_pdb_set_trace_nested (__main__) Doctest: __main__.test_pdb_set_trace_nested ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 2353, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for __main__.test_pdb_set_trace_nested File "/Users/sobolev/Desktop/cpython/Lib/test/test_doctest.py", line 2118, in test_pdb_set_trace_nested ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/test_doctest.py", line 2154, in __main__.test_pdb_set_trace_nested Failed example: try: runner.run(test) finally: sys.stdin = real_stdin # doctest: +REPORT_NDIFF Differences (ndiff with -expected +actual): - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(5)calls_set_trace() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(5)calls_set_trace() ? ^^^^^^^ -> self.f1() (Pdb) print(y) 1 (Pdb) step --Call-- - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(7)f1() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(7)f1() ? ^^^^^^^ -> def f1(self): (Pdb) step - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(8)f1() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(8)f1() ? ^^^^^^^ -> x = 1 (Pdb) step - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(9)f1() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(9)f1() ? ^^^^^^^ -> self.f2() (Pdb) step --Call-- - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(11)f2() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(11)f2() ? ^^^^^^^ -> def f2(self): (Pdb) step - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(12)f2() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(12)f2() ? ^^^^^^^ -> z = 1 (Pdb) step - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(13)f2() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(13)f2() ? ^^^^^^^ -> z = 2 (Pdb) print(z) 1 (Pdb) up - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(9)f1() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(9)f1() ? ^^^^^^^ -> self.f2() (Pdb) print(x) 1 (Pdb) up - > <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(5)calls_set_trace() ? --------- ^^^^^^^ + > <doctest __main__.test_pdb_set_trace_nested[0]>(5)calls_set_trace() ? ^^^^^^^ -> self.f1() (Pdb) print(y) 1 (Pdb) up > <doctest foo-bar@baz[1]>(1)<module>() -> calls_set_trace() (Pdb) print(foo) *** NameError: name 'foo' is not defined (Pdb) continue TestResults(failed=0, attempted=2) ---------------------------------------------------------------------- Ran 65 tests in 0.942s FAILED (failures=3) ``` These issues are not easy to fix. Moreover, since they are literally written in docstrings, it is not very readable. The second problem is that `-c` option is claimed to be supported: https://github.com/python/cpython/blob/78e6d72e38ef4b490f0098b644454031f20ae361/Lib/test/test_doctest.py#L3365-L3380 However: - `test_main` is not defined, so it fails - When changed to `unittest.main()` (with all of the other test failures fixed), it still does not work on macos sonoma, no file is created, nothing I propose to: - raise an exception that running `test_doctest` directly is not supported - remove `test_coverage` <!-- gh-linked-prs --> ### Linked PRs * gh-111349 * gh-111359 * gh-111360 <!-- /gh-linked-prs -->
31c05b72c15885ad5ff298de39456d8baed28448
b0699aa5446eb576ed8ab96989d4f60c7a2a04f8
python/cpython
python__cpython-111377
# test_asyncio: test_sendfile failed on ReFS, Windows 11 Dev Drive # Bug report ### Bug description: The full name of the failed test case is: ```text test.test_asyncio.test_sendfile.ProactorEventLoopTests.test_sendfile_close_peer_in_the_middle_of_receiving ``` Test output: ```text ====================================================================== FAIL: test_sendfile_close_peer_in_the_middle_of_receiving (test.test_asyncio.test_sendfile.ProactorEventLoopTests.test_sendfile_close_peer_in_the_middle_of_receiving) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\cpython\Lib\test\test_asyncio\test_sendfile.py", line 473, in test_sendfile_close_peer_in_the_middle_of_receiving self.assertTrue(1024 <= self.file.tell() < len(self.DATA), AssertionError: False is not true : 0 ---------------------------------------------------------------------- ``` Based on my comprehension, I re-wrote and simplified the test case, as shown below. ```python import asyncio import logging import socket class MySendFileProto(asyncio.Protocol): def __init__(self, file_size=0, loop=None): self.transport = None self.nbytes = 0 self.data = bytearray() self.file_size = file_size if loop: self.done = loop.create_future() def connection_made(self, transport): self.transport = transport def data_received(self, data): self.transport.close() self.nbytes += len(data) self.data.extend(data) print('RECV: {}, TOTAL: {}'.format(len(data), self.nbytes)) super().data_received(data) def connection_lost(self, exc): if not self.done.done(): self.done.set_result(self.nbytes) def main(): logging.basicConfig(level='DEBUG') port = 8075 size = 1024000 file_name = 'tmp.txt' loop = asyncio.ProactorEventLoop() srv_proto = MySendFileProto(file_size=size, loop=loop) srv_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) srv_sock.bind(('localhost', port)) server_creation = loop.create_server(lambda: srv_proto, sock=srv_sock, ssl=None) server = loop.run_until_complete(server_creation) cli_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) cli_sock.connect(('localhost', port)) cli_proto = MySendFileProto(loop=loop) client_creation = loop.create_connection(lambda: cli_proto, sock=cli_sock, ssl=None, server_hostname=None) loop.run_until_complete(client_creation) with open(file_name, 'wb') as file: file.write(b'x' * size) with open(file_name, 'rb') as file: sendfile_future = loop.sendfile(cli_proto.transport, file) try: loop.run_until_complete(sendfile_future) except ConnectionError as e: print('ConnectionError happy: {}'.format(e)) loop.run_until_complete(srv_proto.done) print(file.tell()) srv_proto.transport.close() cli_proto.transport.close() loop.run_until_complete(srv_proto.done) loop.run_until_complete(cli_proto.done) server.close() if __name__ == '__main__': main() ``` Output: 1. NTFS + `loop = asyncio.SelectorEventLoop()` ```text DEBUG:asyncio:Using selector: SelectSelector RECV: 16384, TOTAL: 16384 ConnectionError happy: Connection closed by peer 49152 ``` 2. ReFS + `loop = asyncio.SelectorEventLoop()` ```text DEBUG:asyncio:Using selector: SelectSelector RECV: 16384, TOTAL: 16384 ConnectionError happy: Connection closed by peer 49152 ``` 3. NTFS + `loop = asyncio.ProactorEventLoop()` ```text DEBUG:asyncio:Using proactor: IocpProactor RECV: 32768, TOTAL: 32768 RECV: 65536, TOTAL: 98304 ConnectionError happy: [WinError 64] 指定的网络名不再可用。 32768 ERROR:asyncio:Task was destroyed but it is pending! task: <Task pending name='Task-4' coro=<IocpProactor.accept.<locals>.accept_coro() running at C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.240.0_x64__qbz5n2kfra8p0\Lib\asyncio\windows_events.py:561> wait_for=<_OverlappedFuture cancelled>> ``` 4. ReFS + `loop = asyncio.ProactorEventLoop()` ```text DEBUG:asyncio:Using proactor: IocpProactor RECV: 32768, TOTAL: 32768 RECV: 65536, TOTAL: 98304 ConnectionError happy: [WinError 64] 指定的网络名不再可用。 0 ERROR:asyncio:Task was destroyed but it is pending! task: <Task pending name='Task-4' coro=<IocpProactor.accept.<locals>.accept_coro() running at C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.240.0_x64__qbz5n2kfra8p0\Lib\asyncio\windows_events.py:561> wait_for=<_OverlappedFuture cancelled>> ``` Because `file.tell()` is `0`, the test case fails. However, even though the test case passes on NTFS, it does not mean correctness. I guess that the main purpose of [test_sendfile.py:473](/python/cpython/blob/78e6d72e38ef4b490f0098b644454031f20ae361/Lib/test/test_asyncio/test_sendfile.py#L473) is to check the number of bytes sent by the client. When `SelectorEventLoop` is used on Windows, Python will firstly try `sendfile` syscall, which will fail, and then fallback to [`_sendfile_fallback`](/python/cpython/blob/78e6d72e38ef4b490f0098b644454031f20ae361/Lib/asyncio/base_events.py#L1242), which uses [POSIX-read](https://learn.microsoft.com/zh-cn/cpp/c-runtime-library/reference/posix-read?view=msvc-170) function in a loop. After each [read](https://learn.microsoft.com/zh-cn/cpp/c-runtime-library/reference/posix-read?view=msvc-170), the file offset is sure to increase. When `ProactorEventLoop` is used on Windows, Python will call [`transmitFile`](https://learn.microsoft.com/zh-cn/windows/win32/api/mswsock/nf-mswsock-transmitfile) function. However, this function does not tell us how it will modify the file offset. In fact, on NTFS, `file.tell()` is 32768, but at least 98304 bytes have been sent and received. In conclusion, the statement on [test_sendfile.py:473](/python/cpython/blob/78e6d72e38ef4b490f0098b644454031f20ae361/Lib/test/test_asyncio/test_sendfile.py#L473) does not work on Windows. Either another method needs to be found to check the number of bytes sent, or the line needs to be removed ([test_sendfile.py:471](/python/cpython/blob/78e6d72e38ef4b490f0098b644454031f20ae361/Lib/test/test_asyncio/test_sendfile.py#L471) may be enough, I think). **Windows Version:** 22631.2500 with Windows Feature Experience Pack 1000.22677.1000.0 ### CPython versions tested on: 3.12, CPython main branch ### Operating systems tested on: Windows <!-- gh-linked-prs --> ### Linked PRs * gh-111377 * gh-111461 * gh-111462 <!-- /gh-linked-prs -->
fa35b9e89b2e207fc8bae9eb0284260d0d922e7a
14ab5e51c14e4f6298826823ea94cf51252da2d5
python/cpython
python__cpython-111344
# `itertools.rst` says that `start` is a required argument for `count`, while it is not # Bug report <img width="810" alt="Снимок экрана 2023-10-26 в 10 04 40" src="https://github.com/python/cpython/assets/4660275/ae236f93-f637-4861-8ac0-630471097b84"> However, ```python >>> import itertools >>> itertools.count() count(0) >>> next(itertools.count()) 0 ``` I propose that we use `[start, step]` instead. <!-- gh-linked-prs --> ### Linked PRs * gh-111344 * gh-111385 <!-- /gh-linked-prs -->
ee2d22f06d8a4ca13b2dba5e8a7a639a3997cc69
21f068d80c6cc5de75f9df70fdd733d0ce9c70de
python/cpython
python__cpython-111416
# Typo in math_sumprod_impl() https://github.com/python/cpython/blob/3f84a19e6291db682fc9a570e7612e80e2ffbbb5/Modules/mathmodule.c#L2835 Obviously, should be ``p_i`` in the last OR operand, c.f. [L2824](https://github.com/python/cpython/blob/3f84a19e6291db682fc9a570e7612e80e2ffbbb5/Modules/mathmodule.c#L2824). Factored out from #110000. I think this should be fixed regardless on the fate of that pr. 052d7de867 has also simple test for this if. <!-- gh-linked-prs --> ### Linked PRs * gh-111416 * gh-111419 <!-- /gh-linked-prs -->
9dc4fb820439db26b223edce30e5313a2e3182ff
c3bb10c9303503e7b55a7bdf9acfa6b3bcb699c6
python/cpython
python__cpython-111350
# Crashes and errors in test_embed with PYTHONUOPS=1 For a detailed report see https://github.com/python/cpython/pull/110384#issuecomment-1777657115 (a comment by @brandtbucher on a merged PR by @markshannon ). I am keeping notes about what I'm learning about this (though Mark said it's his). --- The issue seems intermittent. I can repro it by running this command repeatedly on my Mac: ``` PYTHONUOPS=1 ./Programs/_testembed test_run_main_loop ``` Usually it passes (printing 5 lines of output); occasionally I get this error: ``` Py_RunMain(): sys.argv=['-c', 'arg2'] Assertion failed: (PyUnicode_CheckExact(ep->me_key)), function unicodekeys_lookup_unicode, file dictobject.c, line 938. Abort trap: 6 ``` --- ~I can only repro this with PYTHONUOPS=1, but it never prints any uops debug output. Could it be that the issue is in the code for checking the env var?~ <!-- gh-linked-prs --> ### Linked PRs * gh-111350 * gh-111430 <!-- /gh-linked-prs -->
5c9d4497abd2923b4655cee2510208be8540b117
78e6d72e38ef4b490f0098b644454031f20ae361
python/cpython
python__cpython-111509
# What's new in Python 3.13: move importlib.resources removals under the `Removed` section # Documentation There is some obsolete information in the section [Pending Removal in Future Versions](https://docs.python.org/3.13/whatsnew/3.13.html#pending-removal-in-future-versions) of the What's new in Python 3.13 document. 1. There are listed: > [importlib.resources](https://docs.python.org/3.13/library/importlib.resources.html#module-importlib.resources) deprecated methods: > contents() > is_resource() > open_binary() > open_text() > path() > read_binary() > read_text() These were already removed from Python 3.13. 2. There is listed: > [importlib.resources](https://docs.python.org/3.13/library/importlib.resources.html#module-importlib.resources): First parameter to files is renamed to ‘anchor’. This has already changed in Python 3.12 <!-- gh-linked-prs --> ### Linked PRs * gh-111509 * gh-111512 * gh-111534 * gh-111630 * gh-114187 <!-- /gh-linked-prs -->
3dbaed3caa00062087a848740b6e713ad55b0aed
997683435693876e687cf09d3553abde18787d2e
python/cpython
python__cpython-111296
# `timemodule.c` does not handle errors on module creation # Bug report Here are the problematic lines: https://github.com/python/cpython/blob/8b44f3c54bb4f99445c108bc0240c458adae9c6f/Modules/timemodule.c#L1766-L1772 https://github.com/python/cpython/blob/8b44f3c54bb4f99445c108bc0240c458adae9c6f/Modules/timemodule.c#L1831-L1833 https://github.com/python/cpython/blob/8b44f3c54bb4f99445c108bc0240c458adae9c6f/Modules/timemodule.c#L1836-L1838 However, in some cases it uses the correct approach: https://github.com/python/cpython/blob/8b44f3c54bb4f99445c108bc0240c458adae9c6f/Modules/timemodule.c#L1985-L1987 <!-- gh-linked-prs --> ### Linked PRs * gh-111296 * gh-111300 <!-- /gh-linked-prs -->
81b03e78101c97c1d3fe5f90908bbf94e83d7df1
2838c550f729f3fccedb3d65c6695cb0b78045ab
python/cpython
python__cpython-111294
# test_os: test_attributes failed on ReFS, Windows 11 Dev Drive # Bug report ### Bug description: PowerShell command: ```text PS D:\cpython> .\PCbuild\build.bat -t CleanAll PS D:\cpython> .\PCbuild\build.bat -e -d PS D:\cpython> .\python.bat -m test -j1 ``` Test output: ```text 0:26:00 load avg: 0.52 [285/469/2] test_os failed (1 failure) test test_os failed -- Traceback (most recent call last): File "D:\cpython\Lib\test\test_os.py", line 4696, in test_attributes self.check_entry(entry, 'dir', True, False, False) File "D:\cpython\Lib\test\test_os.py", line 4645, in check_entry self.assertEqual(entry.inode(), AssertionError: 0 != 887860239011714428829696 ``` The output indicates that `test_attributes` failed. Given that `os.link` and `os.symlink` can both success, I **summarized** the test below (may be slightly different from the original), shown in Python code: ```python import os def create_file(file_name, content=b'content'): with open(file_name, 'xb', 0) as fp: fp.write(content) return file_name if __name__ == '__main__': dirname = 'D:\\test-py' os.mkdir(dirname) filename = create_file('D:\\file.txt') os.link(filename, 'D:\\link_file.txt') os.symlink(dirname, 'D:\\symlink_dir', True) os.symlink(filename, 'D:\\symlink_file.txt') for entry in os.scandir('D:\\'): print(entry.name) print(entry.inode()) print(os.stat(entry.path, follow_symlinks=False).st_ino) print('') ``` Output: ```text $RECYCLE.BIN 0 121914531583146426630144 aspnetcore 0 37170189308524746506240 cpython 0 461777344397171205603328 Euler 0 459231693714999287480320 file.txt 18 28334198897217871282194 gobook 0 458438483719829776760832 gobook2 0 458752078369082839138304 gopl.io 0 455523898156183667605504 leveldb 0 445249061707127447355392 link_file.txt 18 28334198897217871282194 oceanbase 0 413631342364789275885568 source 0 121951425071293845733376 symlink_dir 0 1057588731233916013248512 symlink_file.txt 19 28334198897217871282195 System Volume Information 0 0 test-py 0 1057570284489842303696896 ``` The above output indicates that: - `entry.inode()` returns a small integer for a file, `0` for a folder; - `os.stat(entry.path, follow_symlinks=False).st_ino` returns a large number, same as `fsutil file queryFileID` on Windows Because they are different, the test fails. **Note:** This issue will not appear on NTFS. This issue can only be reproduced on ReFS. ### CPython versions tested on: CPython main branch ### Operating systems tested on: Windows <!-- gh-linked-prs --> ### Linked PRs * gh-111294 * gh-111367 <!-- /gh-linked-prs -->
b468538d356552f0242763fe44a17b1939e8bd55
a0c414c35d0dc0d44a885fda448652e23de2482c
python/cpython
python__cpython-111285
# test_async_timeout makes multiprocessing tests with threads slow I noticed an interesting effect. When run all tests in `test.test_multiprocessing_spawn.test_threads`, progress lingers (on 30 almost seconds) on `test_terminate`. But when run only `test_terminate`, it completes quickly. Further research revealed that it is only slow after `test_async_timeout`. If run `test_async_timeout` only, it completes quickly, but then Python freezes on 30 seconds (in `tearDownClass`). It is because `test_async_timeout` runs a long task in a thread, and then either `test_terminate` or `tearDownClass` need to wait until it is finished. This slow task can also affect all other tests, because it monopolizes one worker. The solution is to use a new pool for `test_async_timeout` and terminate it immediately after testing. It does not help for threads, but in that case we can unblock the slow task using Event. There is other issue with `test_terminate`: it terminates the pool that is global for the class, so no other tests that uses the pool can be run after it. It only worked because `test_terminate` was at the end of sorted methods list. The solution is to use new pool in `test_terminate`. It saves 1.5 minutes and makes tests more robust. <!-- gh-linked-prs --> ### Linked PRs * gh-111285 * gh-111510 * gh-111511 <!-- /gh-linked-prs -->
624ace5a2f02715d084c29eaf2211cd0dd550690
55df2deb1aeb182f30026bde5e8b5ea575a2dab8
python/cpython
python__cpython-111283
# Error in example of `tempfile` module # Documentation The third example in [Examples](https://docs.python.org/3.13/library/tempfile.html#examples) section of `tempfile` module shows creating `TemporaryFile` with `delete_on_close` parameter, however the parameter is present only in `NamedTemporaryFile` class. Also, a colon is missing several lines below. The [Examples](https://docs.python.org/3.12/library/tempfile.html) in 3.12 version is the same, so both 3.13 and 3.12 versions are affected. <!-- gh-linked-prs --> ### Linked PRs * gh-111283 * gh-111579 <!-- /gh-linked-prs -->
102685c4c8481ec5d9c132fcf06b46057e815969
770530679e89b06f33655b34a8c466ed906842fe
python/cpython
python__cpython-111278
# summarize_stats.py script should output error, not fail, if denominator is unexpectedly 0 # Bug report ### Bug description: The `summarize_stats.py` script will currently throw an exception if a ratio has a non-zero numerator over a zero denominator. While this is an error, it would be better to output this error to the output markdown rather than hard fail. ### CPython versions tested on: CPython main branch ### Operating systems tested on: Linux <!-- gh-linked-prs --> ### Linked PRs * gh-111278 <!-- /gh-linked-prs -->
9495bcaf599e0961b45447b8fab7f8446945ba1a
84b4533e8446cbff3325fffe939c87f7120a3ffd
python/cpython
python__cpython-111319
# LC_CTYPE incorrectly references case sensitivity of "the functions of module `string`" # Documentation https://docs.python.org/3.12/library/locale.html#locale.LC_CTYPE says: > Locale category for the character type functions. Depending on the settings of this category, the functions of module [string](https://docs.python.org/3.12/library/string.html#module-string) dealing with case change their behaviour. I believe this is referring to Python 2.7's ['`string.lower`](https://docs.python.org/2.7/library/string.html?highlight=string#string.lower) et. al., which have been gone for quite some time. I think since Python 3.3 unicode case-conversion functions have quite intentionally been locale-independent. Confusion about this issue seems pervasive, even in CPython itself; consider this bit of code with a somewhat misleading comment: https://github.com/python/cpython/blob/b180120468c100e8c77696ed90b892db59c699c7/Lib/logging/handlers.py#L836-L847 So it would be good to clean up the docs. Earlier in the same document it does say: > There is no way to perform case conversions and character classifications according to the locale. For (Unicode) text strings these are done according to the character value only, while for byte strings, the conversions and classifications are done according to the ASCII value of the byte, and bytes whose high bit is set (i.e., non-ASCII bytes) are never converted or considered part of a character class such as letter or whitespace. <!-- gh-linked-prs --> ### Linked PRs * gh-111319 * gh-111391 * gh-111392 <!-- /gh-linked-prs -->
6d42759c5e47ab62d60a72b4ff15d29864554579
74f0772892c85b6e7bdfa0f44a5ff89002b0734d
python/cpython
python__cpython-111303
# Complementary re patterns such as [\s\S] or [\w\W] are much slower than . with DOTALL # Bug report ### Bug description: ```python import re from time import perf_counter as time p1 = re.compile(r"[\s\S]*") p2 = re.compile(".*", re.DOTALL) s = "a"*10000 for p in (p1,p2): t0 = time() for i in range(10000): _=p.match(s) print(time()-t0) ``` Runtimes are 0.44 s vs 0.0016 s on my system. Instead of simplification, the [\s\S] is stepped through one after another. \s does not match so then \S is checked (the order [\S\s] is twice as fast for the string here). This is not solely an issue for larger matches. A 40 char string is processed half as fast when using [\s\S]. Even 10 chars take about 25% longer to process. I'm not completely sure whether this qualifies as a bug or an issue with documentation. Other languages don't have the DOTALL option and always rely on the first option. Plenty of posts on SO and elsewhere will thus advocate using [\s\S] as an all-matching regex pattern. Unsuspecting Python programmers such as @barneygale may expect [\s\S] to be identical to using a dot with DOTALL as seen below. @serhiy-storchaka https://github.com/python/cpython/blob/9bb202a1a90ef0edce20c495c9426d9766df11bb/Lib/pathlib.py#L126-L133 ### CPython versions tested on: 3.11, 3.13 ### Operating systems tested on: Linux, Windows <!-- gh-linked-prs --> ### Linked PRs * gh-111303 * gh-120742 * gh-120745 * gh-120813 * gh-120814 <!-- /gh-linked-prs -->
309efb39dc005a834bb67e9a6f27b6689f00ec9d
67a91f78e4395148afcc33e5cd6f3f0a9623e63a
python/cpython
python__cpython-111254
# `socketmodule.c` does not handle errors on module creation extension-modules # Bug report It handles most with a specialized macro: https://github.com/python/cpython/blob/81eba7645082a192c027e739b8eb99a94b4c0eec/Modules/socketmodule.c#L7716-L7722 but not these ones: https://github.com/python/cpython/blob/81eba7645082a192c027e739b8eb99a94b4c0eec/Modules/socketmodule.c#L7724-L7731 Introduced in https://github.com/python/cpython/pull/96536 <!-- gh-linked-prs --> ### Linked PRs * gh-111254 * gh-111299 <!-- /gh-linked-prs -->
3052c098ca2779c2d9ab9800dabe66d0efa01794
86887a2084618d1ea1afe756b24a930df7dd3543
python/cpython
python__cpython-111252
# `blake2module.c` does not handle errors on module creation # Bug report It does it in some parts: - https://github.com/python/cpython/blob/81eba7645082a192c027e739b8eb99a94b4c0eec/Modules/_blake2/blake2module.c#L88-L90 - https://github.com/python/cpython/blob/81eba7645082a192c027e739b8eb99a94b4c0eec/Modules/_blake2/blake2module.c#L66-L75 But, not in others: - https://github.com/python/cpython/blob/81eba7645082a192c027e739b8eb99a94b4c0eec/Modules/_blake2/blake2module.c#L98-L101 - https://github.com/python/cpython/blob/81eba7645082a192c027e739b8eb99a94b4c0eec/Modules/_blake2/blake2module.c#L120-L123 This is similar to: - https://github.com/python/cpython/issues/111233 - https://github.com/python/cpython/issues/111230 <!-- gh-linked-prs --> ### Linked PRs * gh-111252 * gh-111297 * gh-111298 <!-- /gh-linked-prs -->
86887a2084618d1ea1afe756b24a930df7dd3543
3211d5793f4437f86cd2fa11e86b4fd958932881
python/cpython
python__cpython-111483
# Listening asyncio UNIX socket isn't removed on close # Bug report ### Bug description: After creating a UNIX socket server with `loop.create_unix_server()` and then closing it using `Server.close()`, then the UNIX socket file is still left on disk. Although asyncio itself can handle this on the next startup since #72585, it's still a bit rude (and confusing) to leave stale things around on the file system. Callers can make sure to pair `Server.close()` with an `os.unlink()`. But it would be a lot neater if Python could automatically do this, as basically everyone should do it anyway. ### CPython versions tested on: 3.9 ### Operating systems tested on: Linux <!-- gh-linked-prs --> ### Linked PRs * gh-111483 <!-- /gh-linked-prs -->
74b868f636a8af9e5540e3315de666500147d47a
f88caab467eb57cfe293cdf9fb7cce29b24fda7f
python/cpython
python__cpython-111234
# `_selectmodule.c` does not handle errors when creating a module # Bug report It is documented that `PyModule_AddIntMacro` can raise an error (and it can in fact): ```rst .. c:macro:: PyModule_AddIntMacro(module, macro) Return ``-1`` on error, ``0`` on success. ``` But, some calls are not checked for errors: https://github.com/python/cpython/blob/96cbd1e1db3447a33e5cc5cc2886ce79b61cc6eb/Modules/selectmodule.c#L2471-L2476 <!-- gh-linked-prs --> ### Linked PRs * gh-111234 <!-- /gh-linked-prs -->
2838c550f729f3fccedb3d65c6695cb0b78045ab
3052c098ca2779c2d9ab9800dabe66d0efa01794
python/cpython
python__cpython-111232
# `_ssl.c` does not handle errors on module creation # Bug report `sslmodule_init_constants` does not return `-1` when any of `PyModule_Add*` calls fail. For example, `PyModule_AddIntConstant` returns `-1` on error, but it is never checked: https://github.com/python/cpython/blob/96cbd1e1db3447a33e5cc5cc2886ce79b61cc6eb/Modules/_ssl.c#L5790-L5831 Other ``sslmodule_init_*` functions do check for errors correctly. I have a PR ready. <!-- gh-linked-prs --> ### Linked PRs * gh-111232 <!-- /gh-linked-prs -->
f6304949bb9937e798ecac8b414606dc01bc6d3c
9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b
python/cpython
python__cpython-115780
# Cross Compile for Android and issues with PyExc_OSError # Bug report ### Bug description: In trying to run Python 3.12 on Android. I have been cross-compiling Python for a number of years. Having built a 64bit version I am getting the following error when I try to run I get the following error at runtime. ImportError('dlopen failed: cannot locate symbol "PyExc_OSError" referenced by "/data/data/com.myapp/files/Python64/lib-dynload/_socket.cpython-312.so"...') I have verified that the _socket.cpython-3.12.so exists. I'm not really sure what other info would be beneficial for people to help me understand this error so I will start with this and happily add more details if requested. ### CPython versions tested on: 3.12 ### Operating systems tested on: Other <!-- gh-linked-prs --> ### Linked PRs * gh-115780 <!-- /gh-linked-prs -->
7f5e3f04f838686d65f1053a5e47f5d3faf0b228
113687a8381d6dde179aeede607bcbca5c09d182
python/cpython
python__cpython-111216
# Errors in stats # Bug report ### Bug description: In the [Specialization effectiveness](https://github.com/faster-cpython/benchmarking/blob/main/results/bm-20231021-3.13.0a1%2B-6c23635/bm-20231021-azure-x86_64-python-main-3.13.0a1%2B-6c23635-pystats.md#specialization-effectiveness) section, there are a few issues. * The deferred by instruction stats for `RESUME` are way off. * We count misses as specialization failures. They are not. * We treat `JUMP_BACKWARDS` as a specializable instruction as it has a counter. It is not. ### CPython versions tested on: CPython main branch ### Operating systems tested on: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111216 <!-- /gh-linked-prs -->
b0699aa5446eb576ed8ab96989d4f60c7a2a04f8
5c9d4497abd2923b4655cee2510208be8540b117
python/cpython
python__cpython-111567
# A new Python REPL This issue will track all the different steps to bootstrap a new Python REPL with many new features. The target of this issue is that we can reach a point where new contributions can be made easily to the REPL once is written in pure Python. This issue only coveres the initial ground work to reach this status. Tasks to be done: - [x] Redirect the parser and the main module to a new Python module. - [x] Fallback to the previous tokenizer-based REPL if the terminal is not a tty (and for backwards compat reasons) - [x] Bootstrap a new REPL module (based on a trimmed version pypy's pyrepl module). - [x] Ensure that the basic features work: - [x] History - [x] Completions - [x] Ctrl-r and Ctrl-s <!-- gh-linked-prs --> ### Linked PRs * gh-111567 * gh-118616 * gh-118635 * gh-118638 * gh-118653 * gh-118700 * gh-118705 * gh-118712 * gh-119262 * gh-119274 * gh-119341 * gh-119348 * gh-119403 * gh-119405 * gh-119427 * gh-119432 * gh-119439 * gh-119559 * gh-119606 * gh-119833 * gh-119834 * gh-119848 * gh-119850 * gh-119924 * gh-123196 * gh-123764 <!-- /gh-linked-prs -->
f27f8c790af1233d499b795af1c0d1b36aaecaf5
40cc809902304f60c6e1c933191dd4d64e570e28
python/cpython
python__cpython-111188
# Postpone removal version for locale.getdefaultlocale() `locale.getdefaultlocale()` was deprecated in Python 3.11 and originally planned for removal in 3.13 (gh-90817). It's now time for 3.13 changes, but we decided to postpone its removal to 3.15 as it's still used by many projects. Re: * https://github.com/python/cpython/pull/104784#issuecomment-1558552650 * https://github.com/python/cpython/issues/104783#issuecomment-1773986960 <!-- gh-linked-prs --> ### Linked PRs * gh-111188 * gh-111323 * gh-111326 <!-- /gh-linked-prs -->
81ed80d843b3f6f0109e7ad854af2c5de27e1a89
f6304949bb9937e798ecac8b414606dc01bc6d3c
python/cpython
python__cpython-111180
# `enum` doctests are silently skipped when run with libregrtest # Bug report `test_enum` has these lines: https://github.com/python/cpython/blob/663cf513b0e973ab7aa4a8609d6616ad2c283f22/Lib/test/test_enum.py#L27-L39 They are problematic, because they are not executed when run as `./python.exe -m test test_enum`. Only when run with `./python.exe Lib/test/test_enum.py` Difference (on `main` branch): ``` » ./python.exe -m test test_enum Using random seed: 1578294160 0:00:00 load avg: 1.98 Run 1 test sequentially 0:00:00 load avg: 1.98 [1/1] test_enum == Tests result: SUCCESS == 1 test OK. Total duration: 856 ms Total tests: run=1,060 skipped=4 Total test files: run=1/1 Result: SUCCESS ``` and: ``` » ./python.exe Lib/test/test_enum.py ...............................................................................................................................................................................................................................s.s..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................s..........................................s........................................................................................................................................FF ====================================================================== FAIL: /Users/sobolev/Desktop/cpython/Lib/test/../../Doc/library/enum.rst Doctest: enum.rst ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 2263, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for enum.rst File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/library/enum.rst", line 0 ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/library/enum.rst", line 301, in enum.rst Failed example: dir(Weekday.SATURDAY) Expected: ['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value'] Got: ['FRIDAY', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'WEDNESDAY', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value'] ====================================================================== FAIL: /Users/sobolev/Desktop/cpython/Lib/test/../../Doc/howto/enum.rst Doctest: enum.rst ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 2263, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for enum.rst File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/howto/enum.rst", line 0 ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/howto/enum.rst", line 486, in enum.rst Failed example: @dataclass class CreatureDataMixin: size: str legs: int tail: bool = field(repr=False, default=True) Exception raised: Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 1374, in __run exec(compile(example.source, filename, "single", File "<doctest enum.rst[64]>", line 1, in <module> @dataclass ^^^^^^^^^ NameError: name 'dataclass' is not defined ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/howto/enum.rst", line 492, in enum.rst Failed example: class Creature(CreatureDataMixin, Enum): BEETLE = 'small', 6 DOG = 'medium', 4 Exception raised: Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 1374, in __run exec(compile(example.source, filename, "single", File "<doctest enum.rst[65]>", line 1, in <module> class Creature(CreatureDataMixin, Enum): ^^^^^^^^^^^^^^^^^ NameError: name 'CreatureDataMixin' is not defined ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/howto/enum.rst", line 496, in enum.rst Failed example: Creature.DOG Exception raised: Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 1374, in __run exec(compile(example.source, filename, "single", File "<doctest enum.rst[66]>", line 1, in <module> Creature.DOG ^^^^^^^^ NameError: name 'Creature' is not defined ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/howto/enum.rst", line 530, in enum.rst Failed example: class MyEnum(Enum): __reduce_ex__ = enum.pickle_by_enum_name Exception raised: Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 1374, in __run exec(compile(example.source, filename, "single", File "<doctest enum.rst[70]>", line 1, in <module> class MyEnum(Enum): File "<doctest enum.rst[70]>", line 2, in MyEnum __reduce_ex__ = enum.pickle_by_enum_name ^^^^ NameError: name 'enum' is not defined. Did you mean: 'Enum'? Or did you forget to import 'enum'? ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/howto/enum.rst", line 773, in enum.rst Failed example: Perm.X | 8 Expected: 9 Got: <Perm.X|8: 9> ---------------------------------------------------------------------- File "/Users/sobolev/Desktop/cpython/Lib/test/../../Doc/howto/enum.rst", line 1431, in enum.rst Failed example: class Color(DuplicateFreeEnum): RED = 1 GREEN = 2 BLUE = 3 GRENE = 2 Expected: Traceback (most recent call last): ... ValueError: aliases not allowed in DuplicateFreeEnum: 'GRENE' --> 'GREEN' Got: Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 1374, in __run exec(compile(example.source, filename, "single", File "<doctest enum.rst[162]>", line 1, in <module> class Color(DuplicateFreeEnum): File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 570, in __new__ enum_class = super().__new__(metacls, cls, bases, classdict, **kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/sobolev/Desktop/cpython/Lib/enum.py", line 278, in __set_name__ enum_member.__init__(*args) File "<doctest enum.rst[161]>", line 7, in __init__ raise ValueError( ValueError: aliases not allowed in DuplicateFreeEnum: 'GRENE' --> 'GREEN' Error calling __set_name__ on '_proto_member' instance 'GRENE' in 'Color' ---------------------------------------------------------------------- Ran 1062 tests in 0.876s FAILED (failures=2, skipped=4) ``` Why? Because of https://github.com/python/cpython/blob/663cf513b0e973ab7aa4a8609d6616ad2c283f22/Lib/test/test_enum.py#L29 checks. This file does not exist when executed via `-m test`, here what `os.getcwd()` shows for `-m test`: `.../cpython/build/test_python_worker_45291æ` But, with `./python.exe Lib/test/test_enum.py` it is: `/Users/sobolev/Desktop/cpython` I've made a PR https://github.com/python/cpython/pull/111180 with fixes that will satisfy doctest, but I am not sure they are correct. CC @ethanfurman <!-- gh-linked-prs --> ### Linked PRs * gh-111180 * gh-111518 * gh-111617 <!-- /gh-linked-prs -->
c4dc5a6ae8aa13abb743182df088f1a3526d1bcd
cd6e0a04a16535d8bc727c84f73730c53267184e
python/cpython
python__cpython-124733
# UBSan: Calling a function through pointer to incorrect function type is undefined behavior # Bug report ### Bug description: UBSan (UndefinedBehaviorSanitizer) in LLVM.org Clang 17 makes [`-fsanitize=function`](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks) available for C; previously, it was only for C++. (So it may also be made available in future Apple Xcode clang and GCC.) By default, it is implied by <tt>-fsanitize=undefined</tt> (which is what `./configure --with-undefined-behavior-sanitizer` uses), but it can be disabled using <tt>-fno-sanitize=function</tt>. For a project such as CPython, which has long relied on function pointers for callbacks, yet seems to have only required that callbacks behave as expected under typical ABI calling conventions, rather than more strictly be declared/defined as a type compatible with the function pointer they will be called as, this leads to *numerous* errors from UBSan. <details> <summary>Examples when starting Python REPL:</summary> <pre> % ./python.exe Objects/object.c:2731:5: runtime error: call to function list_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' listobject.c:347: note: list_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:2731:5 in Objects/object.c:878:16: runtime error: call to function long_hash through pointer to incorrect function type 'long (*)(struct _object *)' longobject.c:3295: note: long_hash defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:878:16 in Include/internal/pycore_object.h:365:43: runtime error: call to function type_is_gc through pointer to incorrect function type 'int (*)(struct _object *)' typeobject.c:5347: note: type_is_gc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Include/internal/pycore_object.h:365:43 in Objects/abstract.c:157:26: runtime error: call to function dict_subscript through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' dictobject.c:2511: note: dict_subscript defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:157:26 in Objects/abstract.c:2954:14: runtime error: call to function tupleiter_next through pointer to incorrect function type 'struct _object *(*)(struct _object *)' tupleobject.c:999: note: tupleiter_next defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:2954:14 in Objects/abstract.c:236:19: runtime error: call to function dict_ass_sub through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, struct _object *)' dictobject.c:2546: note: dict_ass_sub defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:236:19 in Objects/call.c:242:18: runtime error: call to function type_call through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' typeobject.c:1647: note: type_call defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/call.c:242:18 in Objects/typeobject.c:10309:24: runtime error: call to function classmethod_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' descrobject.c:94: note: classmethod_get defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:10309:24 in Modules/gcmodule.c:493:16: runtime error: call to function list_traverse through pointer to incorrect function type 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)' listobject.c:2704: note: list_traverse defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/gcmodule.c:493:16 in Modules/gcmodule.c:605:20: runtime error: call to function list_traverse through pointer to incorrect function type 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)' listobject.c:2704: note: list_traverse defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/gcmodule.c:605:20 in Objects/dictobject.c:3569:17: runtime error: call to function visit_reachable through pointer to incorrect function type 'int (*)(struct _object *, void *)' gcmodule.c:502: note: visit_reachable defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/dictobject.c:3569:17 in Objects/descrobject.c:694:5: runtime error: call to function visit_reachable through pointer to incorrect function type 'int (*)(struct _object *, void *)' gcmodule.c:502: note: visit_reachable defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/descrobject.c:694:5 in […] Objects/typeobject.c:4892:19: runtime error: call to function classmethod_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' descrobject.c:94: note: classmethod_get defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:4892:19 in Python/generated_cases.c.h:3859:17: runtime error: call to function func_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' funcobject.c:913: note: func_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3859:17 in Objects/object.c:1442:19: runtime error: call to function member_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' descrobject.c:160: note: member_get defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1442:19 in Objects/object.c:1503:15: runtime error: call to function method_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' descrobject.c:136: note: method_get defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1503:15 in Python/generated_cases.c.h:3857:13: runtime error: call to function meth_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' methodobject.c:160: note: meth_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3857:13 in Objects/typeobject.c:2212:19: runtime error: call to function method_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' descrobject.c:136: note: method_get defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:2212:19 in Objects/descrobject.c:188:16: runtime error: call to function func_get_name through pointer to incorrect function type 'struct _object *(*)(struct _object *, void *)' funcobject.c:582: note: func_get_name defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/descrobject.c:188:16 in Python/generated_cases.c.h:3248:20: runtime error: call to function tupleiter_next through pointer to incorrect function type 'struct _object *(*)(struct _object *)' tupleobject.c:999: note: tupleiter_next defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3248:20 in Objects/object.c:1564:19: runtime error: call to function member_set through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, struct _object *)' descrobject.c:227: note: member_set defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1564:19 in Objects/descrobject.c:241:16: runtime error: call to function func_set_name through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, void *)' funcobject.c:588: note: func_set_name defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/descrobject.c:241:16 in Python/generated_cases.c.h:3364:21: runtime error: call to function tupleiter_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:984: note: tupleiter_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3364:21 in Python/ceval.c:591:5: runtime error: call to function func_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' funcobject.c:913: note: func_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/ceval.c:591:5 in Objects/object.c:1031:18: runtime error: call to function _Py_module_getattro through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' moduleobject.c:877: note: _Py_module_getattro defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1031:18 in Objects/abstract.c:2895:25: runtime error: call to function dictitems_iter through pointer to incorrect function type 'struct _object *(*)(struct _object *)' dictobject.c:5180: note: dictitems_iter defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:2895:25 in Python/generated_cases.c.h:3193:13: runtime error: call to function dictview_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' dictobject.c:4587: note: dictview_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3193:13 in Python/ceval.c:1929:13: runtime error: call to function tupleiter_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:984: note: tupleiter_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/ceval.c:1929:13 in Objects/abstract.c:2334:19: runtime error: call to function tuplecontains through pointer to incorrect function type 'int (*)(struct _object *, struct _object *)' tupleobject.c:354: note: tuplecontains defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:2334:19 in Objects/typeobject.c:1698:19: runtime error: call to function AttributeError_init through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, struct _object *)' exceptions.c:2279: note: AttributeError_init defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:1698:19 in Python/generated_cases.c.h:1351:13: runtime error: call to function AttributeError_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' exceptions.c:2315: note: AttributeError_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:1351:13 in Python/generated_cases.c.h:623:13: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:623:13 in Python/generated_cases.c.h:749:13: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:749:13 in Python/generated_cases.c.h:3809:17: runtime error: call to function method_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' classobject.c:236: note: method_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3809:17 in Objects/descrobject.c:393:24: runtime error: call to function dict_pop through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *const *, long)' dictobject.c.h:138: note: dict_pop defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/descrobject.c:393:24 in Python/generated_cases.c.h:3260:17: runtime error: call to function dictiter_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' dictobject.c:4047: note: dictiter_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3260:17 in Objects/object.c:1699:15: runtime error: call to function long_bool through pointer to incorrect function type 'int (*)(struct _object *)' longobject.c:4890: note: long_bool defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1699:15 in Python/generated_cases.c.h:4816:13: runtime error: call to function dict_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' dictobject.c:2373: note: dict_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4816:13 in Python/generated_cases.c.h:3896:17: runtime error: call to function method_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' classobject.c:236: note: method_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3896:17 in Python/generated_cases.c.h:4625:19: runtime error: call to function dict_pop through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *const *, long)' dictobject.c.h:138: note: dict_pop defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4625:19 in Objects/descrobject.c:467:24: runtime error: call to function list_append through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' listobject.c:842: note: list_append defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/descrobject.c:467:24 in Include/internal/pycore_object.h:142:9: runtime error: call to function PyObject_Free through pointer to incorrect function type 'void (*)(struct _object *)' obmalloc.c:829: note: PyObject_Free defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Include/internal/pycore_object.h:142:9 in Objects/call.c:361:18: runtime error: call to function type_call through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' typeobject.c:1647: note: type_call defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/call.c:361:18 in Python/generated_cases.c.h:2931:13: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2931:13 in Python/generated_cases.c.h:3362:25: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3362:25 in Python/generated_cases.c.h:928:13: runtime error: call to function list_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' listobject.c:347: note: list_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:928:13 in Python/ceval.c:1604:5: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/ceval.c:1604:5 in Python/bltinmodule.c:378:16: runtime error: call to function gen_iternext through pointer to incorrect function type 'struct _object *(*)(struct _object *)' genobject.c:609: note: gen_iternext defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/bltinmodule.c:378:16 in Objects/object.c:1702:15: runtime error: call to function list_length through pointer to incorrect function type 'long (*)(struct _object *)' listobject.c:438: note: list_length defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1702:15 in Python/generated_cases.c.h:3519:13: runtime error: call to function method_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' classobject.c:236: note: method_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3519:13 in Objects/methodobject.c:540:18: runtime error: call to function rlock_acquire through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' _threadmodule.c:314: note: rlock_acquire defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/methodobject.c:540:18 in Python/generated_cases.c.h:2767:13: runtime error: call to function list_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' listobject.c:347: note: list_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2767:13 in Objects/methodobject.c:551:18: runtime error: call to function rlock_release through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' _threadmodule.c:364: note: rlock_release defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/methodobject.c:551:18 in Objects/typeobject.c:2096:5: runtime error: call to function list_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' listobject.c:347: note: list_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:2096:5 in Python/generated_cases.c.h:130:13: runtime error: call to function method_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' classobject.c:236: note: method_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:130:13 in Objects/object.c:1181:15: runtime error: call to function type_setattro through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, struct _object *)' typeobject.c:4938: note: type_setattro defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1181:15 in Python/generated_cases.c.h:1510:13: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:1510:13 in Python/generated_cases.c.h:164:13: runtime error: call to function listiter_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' listobject.c:3222: note: listiter_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:164:13 in […] Modules/gcmodule.c:1033:24: runtime error: call to function _list_clear through pointer to incorrect function type 'int (*)(struct _object *)' listobject.c:597: note: _list_clear defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/gcmodule.c:1033:24 in Objects/abstract.c:62:26: runtime error: call to function list_length through pointer to incorrect function type 'long (*)(struct _object *)' listobject.c:438: note: list_length defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:62:26 in Objects/abstract.c:270:19: runtime error: call to function dict_ass_sub through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, struct _object *)' dictobject.c:2546: note: dict_ass_sub defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:270:19 in Python/bltinmodule.c:329:16: runtime error: call to function gen_iternext through pointer to incorrect function type 'struct _object *(*)(struct _object *)' genobject.c:609: note: gen_iternext defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/bltinmodule.c:329:16 in Objects/abstract.c:1141:18: runtime error: call to function tupleconcat through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' tupleobject.c:443: note: tupleconcat defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:1141:18 in Objects/abstract.c:440:15: runtime error: call to function bytes_buffer_getbuffer through pointer to incorrect function type 'int (*)(struct _object *, Py_buffer *, int)' bytesobject.c:1663: note: bytes_buffer_getbuffer defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:440:15 in Objects/methodobject.c:441:24: runtime error: call to function int_from_bytes through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *const *, long, struct _object *)' longobject.c.h:396: note: int_from_bytes defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/methodobject.c:441:24 in […] Python/generated_cases.c.h:4814:13: runtime error: call to function method_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' classobject.c:236: note: method_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4814:13 in Python/generated_cases.c.h:4815:13: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4815:13 in Python/generated_cases.c.h:1529:13: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:1529:13 in Python/generated_cases.c.h:648:17: runtime error: call to function slice_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' sliceobject.c:359: note: slice_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:648:17 in Objects/abstract.c:953:13: runtime error: call to function long_add through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' longobject.c:3473: note: long_add defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:953:13 in Python/generated_cases.c.h:3322:21: runtime error: call to function listiter_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' listobject.c:3222: note: listiter_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3322:21 in Python/generated_cases.c.h:2821:13: runtime error: call to function PyObject_Free through pointer to incorrect function type 'void (*)(struct _object *)' obmalloc.c:829: note: PyObject_Free defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2821:13 in Objects/listobject.c:946:26: runtime error: call to function gen_iternext through pointer to incorrect function type 'struct _object *(*)(struct _object *)' genobject.c:609: note: gen_iternext defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/listobject.c:946:26 in Python/generated_cases.c.h:4503:19: runtime error: call to function list_extend through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' listobject.c:861: note: list_extend defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4503:19 in Python/generated_cases.c.h:4507:13: runtime error: call to function gen_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' genobject.c:128: note: gen_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4507:13 in Python/generated_cases.c.h:2378:17: runtime error: call to function structseq_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' structseq.c:119: note: structseq_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2378:17 in Python/ceval.c:1605:5: runtime error: call to function dict_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' dictobject.c:2373: note: dict_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/ceval.c:1605:5 in Python/generated_cases.c.h:1548:13: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:1548:13 in Objects/descrobject.c:439:24: runtime error: call to function _io_FileIO_isatty through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' fileio.c.h:532: note: _io_FileIO_isatty defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/descrobject.c:439:24 in Objects/methodobject.c:484:24: runtime error: call to function _io_FileIO_readall through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)' fileio.c.h:284: note: _io_FileIO_readall defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/methodobject.c:484:24 in Objects/descrobject.c:372:24: runtime error: call to function _io_FileIO_close through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _typeobject *, struct _object *const *, unsigned long, struct _object *)' fileio.c.h:29: note: _io_FileIO_close defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/descrobject.c:372:24 in Objects/object.c:783:15: runtime error: call to function bytes_richcompare through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, int)' bytesobject.c:1524: note: bytes_richcompare defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:783:15 in Python/generated_cases.c.h:650:13: runtime error: call to function memory_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' memoryobject.c:1141: note: memory_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:650:13 in Objects/abstract.c:804:9: runtime error: call to function memory_releasebuf through pointer to incorrect function type 'void (*)(struct _object *, Py_buffer *)' memoryobject.c:1593: note: memory_releasebuf defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:804:9 in Objects/abstract.c:1950:25: runtime error: call to function list_item through pointer to incorrect function type 'struct _object *(*)(struct _object *, long)' listobject.c:460: note: list_item defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:1950:25 in Modules/timemodule.c:2087:5: runtime error: call to function visit_reachable through pointer to incorrect function type 'int (*)(struct _object *, void *)' gcmodule.c:502: note: visit_reachable defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/timemodule.c:2087:5 in Python/generated_cases.c.h:2660:21: runtime error: call to function set_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' setobject.c:489: note: set_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2660:21 in Python/generated_cases.c.h:4440:13: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)' tupleobject.c:187: note: tupledealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4440:13 in Python/generated_cases.c.h:2822:13: runtime error: call to function PyObject_Free through pointer to incorrect function type 'void (*)(struct _object *)' obmalloc.c:829: note: PyObject_Free defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2822:13 in Python/generated_cases.c.h:2157:13: runtime error: call to function dict_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' dictobject.c:2373: note: dict_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2157:13 in Objects/typeobject.c:4872:19: runtime error: call to function getset_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' descrobject.c:180: note: getset_get defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:4872:19 in Python/generated_cases.c.h:4730:17: runtime error: call to function func_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' funcobject.c:913: note: func_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4730:17 in Objects/typeobject.c:4905:15: runtime error: call to function method_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)' descrobject.c:136: note: method_get defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:4905:15 in Objects/typeobject.c:1863:16: runtime error: call to function tupletraverse through pointer to incorrect function type 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)' tupleobject.c:606: note: tupletraverse defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:1863:16 in […] Include/internal/pycore_call.h:187:11: runtime error: call to function range_vectorcall through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *const *, unsigned long, struct _object *)' rangeobject.c:148: note: range_vectorcall defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Include/internal/pycore_call.h:187:11 in Python/generated_cases.c.h:2878:13: runtime error: call to function mappingproxy_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' descrobject.c:1160: note: mappingproxy_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2878:13 in Python/generated_cases.c.h:3320:25: runtime error: call to function list_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' listobject.c:347: note: list_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3320:25 in Python/generated_cases.c.h:2766:13: runtime error: call to function set_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' setobject.c:489: note: set_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2766:13 in Modules/_abc.c:52:5: runtime error: call to function visit_reachable through pointer to incorrect function type 'int (*)(struct _object *, void *)' gcmodule.c:502: note: visit_reachable defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/_abc.c:52:5 in Python/bltinmodule.c:1408:25: runtime error: call to function tupleiter_next through pointer to incorrect function type 'struct _object *(*)(struct _object *)' tupleobject.c:999: note: tupleiter_next defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/bltinmodule.c:1408:25 in Python/generated_cases.c.h:673:17: runtime error: call to function slice_dealloc through pointer to incorrect function type 'void (*)(struct _object *)' sliceobject.c:359: note: slice_dealloc defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:673:17 in <br /> (Omitting remaining errors due to GitHub comment length limit.) <br /> Python 3.13.0a1+ (heads/patch-103194-dirty:0a6e69f9a2, Oct 21 2023, 14:45:09) [Clang 17.0.3 ] on darwin Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; </pre> </details> Example workaround for the first error and likely many others, where instead of casting functions to incompatible pointers, the functions use compatible signatures and cast their parameter(s): ```diff --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -343,8 +343,9 @@ PyList_Append(PyObject *op, PyObject *newitem) /* Methods */ static void -list_dealloc(PyListObject *op) +list_dealloc(PyObject *self) { + PyListObject *op = (PyListObject *)self; Py_ssize_t i; PyObject_GC_UnTrack(op); Py_TRASHCAN_BEGIN(op, list_dealloc) @@ -3104,7 +3105,7 @@ PyTypeObject PyList_Type = { "list", sizeof(PyListObject), 0, - (destructor)list_dealloc, /* tp_dealloc */ + list_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ ``` In other cases, it may be less disruptive to introduce a wrapper function with the correct signature: ```diff @@ -615,6 +617,13 @@ _list_clear(PyListObject *a) return 0; } +static int +_list_clear_wrap(PyObject *self) +{ + PyListObject *a = (PyListObject *)self; + return _list_clear(a); +} + /* a[ilow:ihigh] = v if v != NULL. * del a[ilow:ihigh] if v == NULL. * @@ -3123,7 +3133,7 @@ PyTypeObject PyList_Type = { _Py_TPFLAGS_MATCH_SELF | Py_TPFLAGS_SEQUENCE, /* tp_flags */ list___init____doc__, /* tp_doc */ (traverseproc)list_traverse, /* tp_traverse */ - (inquiry)_list_clear, /* tp_clear */ + _list_clear_wrap, /* tp_clear */ list_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ list_iter, /* tp_iter */ ``` Likely instances of this can be found at compile time using e.g. `-Wcast-function-type` (although this emits false positives for when the function pointer is cast back to the correct type before called, and this warning is suppressed by intermediate casts through `(void *)`): ``` Objects/listobject.c:3162:5: warning: cast from 'void (*)(PyListObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict] 3162 | (destructor)list_dealloc, /* tp_dealloc */ | ^~~~~~~~~~~~~~~~~~~~~~~~ ``` I would be interested in combing through and replacing similar instances. But I would not be surprised if sooner or later I encounter an instance that is won’t-fix because it involves a stable API, or if I am told that this problem should be ignored because fixing it is too disruptive or requires disproportionate review effort. I am not aware how immediate any danger is from optimizing compilers exploiting this type of undefined behavior. ### CPython versions tested on: CPython main branch ### Operating systems tested on: macOS --- Written by @picnixz: See https://github.com/python/cpython/issues/111178#issuecomment-2642725837 for the remaining files to fix. For detecting the UBSan failures, contributors may configure Python with: ```sh ./configure \ --with-pydebug \ --prefix="$(pwd)/build" \ CC=clang LD=clang \ CFLAGS="-fsanitize=function -fsanitize-recover" \ LDFLAGS="-fsanitize=function -fsanitize-recover" ``` The complete list of failures can be retrieved as follows: ```sh PAT='runtime error: call to function (\w+) through pointer' && \ make -j12 2>&1 >/dev/null | \ grep -E "$PAT" | \ sed -r "s#^(.+): $PAT.+#\1@\2#g" | \ sort -k1,2 -t@ -u | \ awk 'BEGIN { PROCINFO["sorted_in"]="@ind_num_asc"; FS=SUBSEP="@" } { A[$1][length(A[$1])+1]=$2 } END { for (m in A) { for (i in A[m]) { if (i == 1) printf "%s\n", m; print "#", A[m][i] } print "" } }' | \ sed -r "s#"$(pwd)"/?(\./)?(.+)#\2#g" ``` Note that different builds should be configured in order to hunt all UBSan failures (e.g., `--with-trace-refs` or `--disable-gil` to expose conditional compiled code guarded by macros). --- Note by @encukou: We use the macro `_Py_NO_SANITIZE_UNDEFINED` to disable the UB sanitizer in some hard-to-fix cases, so that we can get a stable, regression-monitoring checker sooner. This issue should only be closed after the macro is removed. --- <!-- gh-linked-prs --> ### Linked PRs * python/cpython#112687 * python/cpython#112752 * python/cpython#112782 * python/cpython#112742 * python/cpython#112792 * python/cpython#112793 * python/cpython#112820 * python/cpython#112861 * python/cpython#112863 * python/cpython#112892 * python/cpython#112893 * python/cpython#122972 * python/cpython#123004 * gh-124733 * gh-124763 * gh-124804 * gh-124806 * gh-124888 * gh-124895 * gh-124896 * gh-124900 * gh-124902 * gh-124903 * gh-124908 * gh-124940 * gh-124942 * gh-124943 * gh-124964 * gh-124970 * gh-125043 * gh-125180 * gh-125182 * gh-127982 * gh-128154 * gh-128178 * gh-128235 * gh-128236 * gh-128237 * gh-128238 * gh-128239 * gh-128240 * gh-128241 * gh-128242 * gh-128243 * gh-128244 * gh-128245 * gh-128246 * gh-128247 * gh-128248 * gh-128249 * gh-128250 * gh-128251 * gh-128252 * gh-128253 * gh-128259 * gh-128447 * gh-129060 * gh-129071 * gh-129074 * gh-129083 * gh-129084 * gh-129087 * gh-129088 * gh-129090 * gh-129100 * gh-129101 * gh-129772 * gh-129773 * gh-129774 * gh-129775 * gh-129776 * gh-129777 * gh-129778 * gh-129779 * gh-129780 * gh-129781 * gh-129782 * gh-129783 * gh-129784 * gh-129785 * gh-129786 * gh-129787 * gh-129788 * gh-129789 * gh-129790 * gh-129791 * gh-129792 * gh-129793 * gh-129794 * gh-129795 * gh-129796 * gh-129797 * gh-129798 * gh-129799 * gh-129800 * gh-129801 * gh-129802 * gh-130446 * gh-130575 * gh-130589 * gh-130590 * gh-130591 * gh-130682 * gh-130683 * gh-130684 * gh-130719 * gh-131101 * gh-131102 * gh-131135 * gh-131157 * gh-131159 * gh-131160 * gh-131161 * gh-131162 * gh-131163 * gh-131180 * gh-131191 * gh-131192 * gh-131193 * gh-131227 * gh-131228 * gh-131455 * gh-131456 * gh-131463 * gh-131464 * gh-131496 * gh-131602 * gh-131603 * gh-131605 * gh-131606 * gh-131607 * gh-131608 * gh-131609 * gh-131610 * gh-131611 * gh-131612 * gh-131613 * gh-131614 * gh-131615 * gh-131616 * gh-131659 * gh-131660 * gh-131663 * gh-131664 * gh-131665 * gh-131667 * gh-131668 * gh-131669 * gh-131673 * gh-131674 * gh-131714 * gh-131977 * gh-131979 * gh-132020 * gh-132395 * gh-133072 * gh-135539 * gh-135547 <!-- /gh-linked-prs -->
4f07fd59cbd2656ae31e164098b8d10c5b7e51f0
f1b81c408fb83beeee519ae4fb9d3a36dd4522b3
python/cpython
python__cpython-111210
# `_io.BytesIO.getbuffer()`: unshare_buffer: Assertion `self->exports == 0' failed # Crash report ### What happened? ```python import io f = io.BytesIO() a = f.getbuffer() b = f.getbuffer() ``` Output: ``` python: ./Modules/_io/bytesio.c:112: unshare_buffer: Assertion `self->exports == 0' failed. Aborted (core dumped) ``` Reproduced on 3.8 and 3.11-3.13. ### CPython versions tested on: 3.8, 3.11, 3.12, CPython main branch ### Operating systems tested on: Linux ### Output from running 'python -VV' on the command line: Python 3.13.0a1+ (heads/main:11312eae6e, Oct 22 2023, 02:44:38) [GCC 10.2.1 20210110] <!-- gh-linked-prs --> ### Linked PRs * gh-111210 * gh-111314 * gh-111315 <!-- /gh-linked-prs -->
9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b
f6a45a03d0e0ef6b00c45a0de9a606b1d23cbd2f
python/cpython
python__cpython-111166
# Move test running code from test.support to libregrtest `test.support.run_unittest()` was used to run unit tests, but now all tests are collected using standard unittest mechanism. Currently it is only used in libregrtest, and its code can be moved there. `test.support.run_doctest()` was used to run doctests, but now they are integrated in unit tests using `DocTestSuite` and `DocFileSuite`. It is no longer used, and can be removed. <!-- gh-linked-prs --> ### Linked PRs * gh-111166 * gh-111316 * gh-111318 * gh-111327 * gh-111328 * gh-111329 * gh-111467 * gh-111471 * gh-111472 <!-- /gh-linked-prs -->
f6a45a03d0e0ef6b00c45a0de9a606b1d23cbd2f
a8a89fcd1ff03bb2f10126e0973faa74871874c3
python/cpython
python__cpython-111160
# `doctest` fails to compare tracebacks with notes # Bug report Minimal reproducer: ```python """ Module doctest >>> raise_with_note() Traceback (most recent call last): ... ValueError: Text Note """ def raise_with_note(): err = ValueError('Text') err.add_note('Note') raise err ``` Now, run it, you will get a very strange error: ``` » ./python.exe -m doctest ex.py ********************************************************************** File "/Users/sobolev/Desktop/cpython/ex.py", line 4, in ex Failed example: raise_with_note() Expected: Traceback (most recent call last): ... ValueError: Text Note Got: Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/doctest.py", line 1374, in __run exec(compile(example.source, filename, "single", File "<doctest ex[0]>", line 1, in <module> raise_with_note() File "/Users/sobolev/Desktop/cpython/ex.py", line 14, in raise_with_note raise err ValueError: Text Note ********************************************************************** 1 items had failures: 1 of 1 in ex ***Test Failed*** 1 failures. ``` Things that do not help: - `IGNORE_EXCEPTION_DETAIL` - `ELLIPSIS` - Coping the whole traceback Related to how exceptions with notes are represented in https://github.com/python/cpython/blob/7237fb578dc9db9dc557759a24d8083425107b91/Lib/doctest.py#L1396 I am working on this issue right now :) Refs https://github.com/python/cpython/issues/111157 <!-- gh-linked-prs --> ### Linked PRs * gh-111160 * gh-111169 * gh-111170 * gh-111541 * gh-111732 * gh-111733 <!-- /gh-linked-prs -->
fd60549c0ac6c81f05594a5141d24b4433ae39be
5e7727b05232b43589d177c15263d7f4f8c584a0
python/cpython
python__cpython-111158
# Docstring of `traceback.format_exception_only` misses the `__notes__` part # Bug report Compare the docs: https://github.com/python/cpython/blob/7237fb578dc9db9dc557759a24d8083425107b91/Doc/library/traceback.rst#L138-L146 With the docstring: https://github.com/python/cpython/blob/7237fb578dc9db9dc557759a24d8083425107b91/Lib/traceback.py#L151-L165 Docstring is missing ``` Following the message, the list contains the exception's :attr:`notes <BaseException.__notes__>`. ``` part. I think that it would be better to mention `__notes__` there as well. PR is incoming. <!-- gh-linked-prs --> ### Linked PRs * gh-111158 * gh-111163 * gh-111164 <!-- /gh-linked-prs -->
5e7727b05232b43589d177c15263d7f4f8c584a0
9a1fe09622cd0f1e24c2ba5335c94c5d70306fd0
python/cpython
python__cpython-111156
# Direct invocation of `test_pprint.py` fails # Bug report Before my fix: ``` » ./python.exe Lib/test/test_pprint.py ..........F...............x................. ====================================================================== FAIL: test_dataclass_no_repr (__main__.QueryTestCase.test_dataclass_no_repr) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/test/test_pprint.py", line 538, in test_dataclass_no_repr self.assertRegex(formatted, r"<test.test_pprint.dataclass3 object at \w+>") AssertionError: Regex didn't match: '<test.test_pprint.dataclass3 object at \\w+>' not found in '<__main__.dataclass3 object at 0x101847ad0>' ---------------------------------------------------------------------- Ran 44 tests in 0.058s FAILED (failures=1, expected failures=1) ``` After: ``` » ./python.exe Lib/test/test_pprint.py ..........................x................. ---------------------------------------------------------------------- Ran 44 tests in 0.058s OK (expected failures=1) ``` <!-- gh-linked-prs --> ### Linked PRs * gh-111156 <!-- /gh-linked-prs -->
e136e2d640f4686b63ea05088d481115185fc305
86276fe4f8e0801f1194b55fa8d8cb7dbf8ee658
python/cpython
python__cpython-111152
# Convert unsemantic monospaced directives to :ref: Directives like `:class:`, `:func:`, etc. auto-apply a monospaced font to the displayed text, which doesn't look very nice if used unsemantically. `:ref:` directives are the way to go when it comes to internal links with non-code text, and most of other internal links already follow this. For example, this line in _Doc/library/typing.rst_: https://github.com/python/cpython/blob/b07f23259d30e61fd7cc975b8b0e3b2e846fed8f/Doc/library/typing.rst#L307 ...should be changed to: ```rst variadic number of arguments, :ref:`overloaded functions <overload>` ``` And this line: https://github.com/python/cpython/blob/b07f23259d30e61fd7cc975b8b0e3b2e846fed8f/Doc/library/typing.rst#L2775 ...needs an _[explicit target](https://docs.readthedocs.io/en/stable/guides/cross-referencing-with-sphinx.html#explicit-targets)_: ```rst .. _overload: .. decorator:: overload ``` <!-- gh-linked-prs --> ### Linked PRs * gh-111152 * gh-111269 * gh-111270 <!-- /gh-linked-prs -->
1198076447f35b19a9173866ccb9839f3bcf3f17
9bb202a1a90ef0edce20c495c9426d9766df11bb
python/cpython
python__cpython-111148
# `test_set_of_sets_reprs` of `test_pprint` is silently ignored # Bug report Right now this test is marked as `expectedFailure` with a big comment about why: https://github.com/python/cpython/blob/b07f23259d30e61fd7cc975b8b0e3b2e846fed8f/Lib/test/test_pprint.py#L622-L646 With `self.maxDiff = None`: ``` » ./python.exe -m test test_pprint -m test_set_of_sets_reprs Using random seed 3151060862 0:00:00 load avg: 1.34 Run 1 test sequentially 0:00:00 load avg: 1.34 [1/1] test_pprint test test_pprint failed -- Traceback (most recent call last): File "/Users/sobolev/Desktop/cpython/Lib/test/test_pprint.py", line 672, in test_set_of_sets_reprs self.assertEqual(pprint.pformat(cube), cube_repr_tgt) AssertionError: '{fro[43 chars]set({1}), frozenset({0})}),\n frozenset({0}): [843 chars])})}' != '{fro[43 chars]set({0}), frozenset({1})}),\n frozenset({0}): [1017 chars])})}' - {frozenset(): frozenset({frozenset({2}), frozenset({1}), frozenset({0})}), - frozenset({0}): frozenset({frozenset(), frozenset({0, 1}), frozenset({0, 2})}), - frozenset({1}): frozenset({frozenset(), frozenset({0, 1}), frozenset({1, 2})}), ? ^ --- --- --- + {frozenset(): frozenset({frozenset({2}), frozenset({0}), frozenset({1})}), ? ^ +++ + frozenset({0}): frozenset({frozenset(), + frozenset({0, 2}), + frozenset({0, 1})}), + frozenset({1}): frozenset({frozenset(), + frozenset({1, 2}), + frozenset({0, 1})}), + frozenset({2}): frozenset({frozenset(), + frozenset({1, 2}), + frozenset({0, 2})}), - frozenset({0, 1}): frozenset({frozenset({1}), ? ^ ^ ^ + frozenset({1, 2}): frozenset({frozenset({2}), ? ^ ^ ^ - frozenset({0}), ? ^ + frozenset({1}), ? ^ frozenset({0, 1, 2})}), - frozenset({2}): frozenset({frozenset(), frozenset({0, 2}), frozenset({1, 2})}), frozenset({0, 2}): frozenset({frozenset({2}), frozenset({0}), frozenset({0, 1, 2})}), - frozenset({1, 2}): frozenset({frozenset({2}), ? --- ^ + frozenset({0, 1}): frozenset({frozenset({0}), ? +++ ^ frozenset({1}), frozenset({0, 1, 2})}), - frozenset({0, 1, 2}): frozenset({frozenset({0, 1}), ? ^ ^ + frozenset({0, 1, 2}): frozenset({frozenset({1, 2}), ? ^ ^ frozenset({0, 2}), - frozenset({1, 2})})} ? --- + frozenset({0, 1})})} ? +++ test_pprint failed (1 failure) == Tests result: FAILURE == 1 test failed: test_pprint Total duration: 38 ms Total tests: run=1 (filtered) failures=1 Total test files: run=1/1 (filtered) failed=1 Result: FAILURE ``` There are several problems with this test: 1. It creates an explicit relation with `test_set` because of an import: https://github.com/python/cpython/blob/b07f23259d30e61fd7cc975b8b0e3b2e846fed8f/Lib/test/test_pprint.py#L11 We try to revome such dependencies 2. It does not work :) 3. It is not very readable: <img width="1352" alt="Снимок экрана 2023-10-21 в 08 49 09" src="https://github.com/python/cpython/assets/4660275/bbf78fe6-f881-494c-b84e-2581aec4b199"> Why is this test unstable? Because `frozenset({0}) < frozenset({1}) is False` and `frozenset({1}) < frozenset({0}) is False`. However, we can refator this test to use `frozenset()`, it is always ordered: `frozenset() < frozenset({1, 2}) is True`, `frozenset() > frozenset({1, 2}) is False` So, my idea is to: - Refactor this test to still do pretty much the same - But reliably - With more readability - Without `test_set` dependency Refs: - https://github.com/python/cpython/commit/969fe57baa0eb80332990f9cda936a33e13fabef - https://bugs.python.org/issue13907 <!-- gh-linked-prs --> ### Linked PRs * gh-111148 <!-- /gh-linked-prs -->
7ac49e74c3db35365968cd2cbd395cf063d2050d
fb79e1ed4a985a487a02bb8585cc1bd2933dfa7c
python/cpython
python__cpython-114886
# C API: Consider adding public PyLong_AsByteArray() and PyLong_FromByteArray() functions # Feature or enhancement The private `_PyLong_AsByteArray()` and `_PyLong_FromByteArray()` functions were removed in Python 3.13: see PR #108429. @scoder [asked](https://github.com/python/cpython/pull/108429#issuecomment-1772777608) what is the intended replacement for `_PyLong_FromByteArray()`. The replacement for `_PyLong_FromByteArray()` is ``PyObject_CallMethod((PyObject*)&PyList_Type, "from_bytes", "s#s", str, len, "big")`` but I'm not sure what is the easy way to set the *signed* parameter to True (default: `signed=False`). The replacement for `_PyLong_AsByteArray()` is `PyObject_CallMethod(my_int, "to_bytes", "ns", length, "big")`. Same, I'm not sure how to easy set the *signed* parameter to True (default: `signed=False`). I propose to add public PyLong_AsByteArray() and PyLong_FromByteArray() functions to the C API. Python 3.12 modified PyLongObject: it's no longer a simple array of digits, but it's now a more less straightforward `_PyLongValue` structure which requires using unstable functions to access small "compact" values: * PyUnstable_Long_IsCompact() * PyUnstable_Long_CompactValue() So having a reliable and simple way to import/export a Python int object as bytes became even more important. --- A code search for ``_PyLong_AsByteArray `` in PyPI top 5,000 projects found 12 projects using it: * Cython (0.29.36) * blspy (2.0.2) * catboost (1.2) * fastobo (0.12.2) * gevent (22.10.2) * guppy3 (3.1.3) * line_profiler (4.0.3) * msgspec (0.16.0) * orjson (3.9.1) * pickle5 (0.0.12) * pyodbc (4.0.39) * rlp (3.0.0) <!-- gh-linked-prs --> ### Linked PRs * gh-114886 * gh-115375 * gh-115380 * gh-116053 * gh-118612 <!-- /gh-linked-prs -->
7861dfd26a41e40c2b4361eb0bb1356b9b4a064b
a82fbc13d0e352b9af7d7ffbef4bc04cf635f07f
python/cpython
python__cpython-113887
# C API: Consider adding a public PyLong_GCD() function # Feature or enhancement The private _PyLong_GCD() function was removed in Python 3.13: see PR #108429. @scoder [asked](https://github.com/python/cpython/pull/108429#issuecomment-1772786659) what is the intended replacement for _PyLong_GCD(). I suppose that the replacement is to call ``math.gcd()``. Is it worth it to add a public PyLong_GCD() function to the C API? Is it commonly used? A code search for ``_PyLong_GCD`` is PyPI top 5,000 projects found 0 projects using it. @scoder: What is your use case for _PyLong_GCD()? Using ``math.gcd()`` doesn't solve your use case? <!-- gh-linked-prs --> ### Linked PRs * gh-113887 <!-- /gh-linked-prs -->
93930eaf0acd64dc0d08d58321d2682cb019bc1a
66363b9a7b9fe7c99eba3a185b74c5fdbf842eba
python/cpython
python__cpython-111137
# Unnecessary `PyFrozenSet_Check` calls in `ast_opt.c`? This code looks strange: https://github.com/python/cpython/blob/37e4e20eaa8f27ada926d49e5971fecf0477ad26/Python/ast_opt.c#L177-L178 Function above intended as *safe mutiply*, but set (and frozenset) doesn't have `tp_as_number->nb_multiply` field, so it cannot be used with `*` operator. <!-- gh-linked-prs --> ### Linked PRs * gh-111137 <!-- /gh-linked-prs -->
7162c3a1e8707fdea2efcc70d2cec987eba9ea78
124259f9b30f6cbab4dd2bcfb0d32f1cddcc35db
python/cpython
python__cpython-111136
# Crash of interpreter due to assign before global declaration # Crash report ### What happened? ```python def bar(): x = 11 global x return x bar() ``` Traceback: ```python File "/Users/admin/Projects/cpython/example.py", line 3 global x ^^^^^^^^ SyntaxError: name 'x' is assigned to before global declaration Assertion failed: ((gc->_gc_next & NEXT_MASK_UNREACHABLE) == next_value), function validate_list, file gcmodule.c, line 403. zsh: abort ./python.exe example.py ``` ### CPython versions tested on: CPython main branch ### Operating systems tested on: macOS ### Output from running 'python -VV' on the command line: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111136 <!-- /gh-linked-prs -->
124259f9b30f6cbab4dd2bcfb0d32f1cddcc35db
37e4e20eaa8f27ada926d49e5971fecf0477ad26
python/cpython
python__cpython-111127
# `test_typing` has strange `assertIsInstance` calls # Bug report These line are problematic: https://github.com/python/cpython/blob/264f4af506bf5b587105eab37fcfb7dfa62d6587/Lib/test/test_typing.py#L2013-L2020 Why? 1. `self.assertIsInstance` gives the intention that this will return `True` 2. `self.assertNotIsInstance` gives the intention that this will return `False` 3. Technically `self.assert[Not]IsInstance` can raise `TypeError` on its own (but not in practice) However, this will always fail with `TypeError`. I propose to use just `isintance` instead. <!-- gh-linked-prs --> ### Linked PRs * gh-111127 * gh-111130 * gh-111131 <!-- /gh-linked-prs -->
ea7c26e4b89c71234c4a603567a93f0a44c9cc97
f1e751e933aa8c39c0e9cfa4cdc3f8f9f0538202
python/cpython
python__cpython-111142
# global declaration in except has incorrect prior use # Bug report ### Bug description: I think the `global a` has no prior use in this code (and pyright tells me the same). But I don't understand why cpython thinks it has a prior use. ```python a=5 def f(): try: pass except: global a else: print(a) ``` output (Python 3.12.0): ```python File "/home/frank/projects/pysource-playground/pysource-codegen/bug.py", line 8 global a ^^^^^^^^ SyntaxError: name 'a' is used prior to global declaration ``` the following code has no syntax error: ```python a=5 def f(): try: pass except: global a print(a) ``` I can also reproduce this issue in 3.7. I also don't know what the exact semantic of global/nonlocal inside statements like if/while/try/... is. I would like to know more about it because I'm currently writing [pysource-codegen](https://github.com/15r10nk/pysource-codegen) where I generate such cases. ### CPython versions tested on: 3.12 ### Operating systems tested on: Linux <!-- gh-linked-prs --> ### Linked PRs * gh-111142 <!-- /gh-linked-prs -->
b578e51f026a45576930816d6784697192ed472e
f71cd5394efe154ba92228b2b67be910cc1ede95
python/cpython
python__cpython-111124
# Flaky test: test.test_capi.test_misc.Test_PyLock.test_lock_two_threads # Bug report I noticed a spurious test failure in `test_lock_two_threads` when running the test suite. I'll put up a PR to fix this. ``` test_lock_two_threads (test.test_capi.test_misc.Test_PyLock.test_lock_two_threads) ... Assertion failed: (test_data.m.v == 3), function test_lock_two_threads, file test_lock.c, line 82. ``` <details> <summary>Stack trace</summary> ``` test_lock_two_threads (test.test_capi.test_misc.Test_PyLock.test_lock_two_threads) ... Assertion failed: (test_data.m.v == 3), function test_lock_two_threads, file test_lock.c, line 82. Fatal Python error: Aborted Current thread 0x00007ff8466c6e80 (most recent call first): File "/Users/sgross/Projects/cpython/Lib/unittest/case.py", line 589 in _callTestMethod File "/Users/sgross/Projects/cpython/Lib/unittest/case.py", line 636 in run File "/Users/sgross/Projects/cpython/Lib/unittest/case.py", line 692 in __call__ File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 122 in run File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 84 in __call__ File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 122 in run File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 84 in __call__ File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 122 in run File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 84 in __call__ File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 122 in run File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 84 in __call__ File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 122 in run File "/Users/sgross/Projects/cpython/Lib/unittest/suite.py", line 84 in __call__ File "/Users/sgross/Projects/cpython/Lib/unittest/runner.py", line 240 in run File "/Users/sgross/Projects/cpython/Lib/test/support/__init__.py", line 1166 in _run_suite File "/Users/sgross/Projects/cpython/Lib/test/support/__init__.py", line 1293 in run_unittest File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/single.py", line 36 in run_unittest File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/single.py", line 92 in test_func File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/single.py", line 48 in regrtest_runner File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/single.py", line 95 in _load_run_test File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/single.py", line 138 in _runtest_env_changed_exc File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/single.py", line 238 in _runtest File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/single.py", line 266 in run_single_test File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/worker.py", line 89 in worker_process File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/worker.py", line 112 in main File "/Users/sgross/Projects/cpython/Lib/test/libregrtest/worker.py", line 116 in <module> File "<frozen runpy>", line 88 in _run_code File "<frozen runpy>", line 198 in _run_module_as_main ``` </details> <!-- gh-linked-prs --> ### Linked PRs * gh-111124 <!-- /gh-linked-prs -->
264f4af506bf5b587105eab37fcfb7dfa62d6587
cb4f7462d122d7ec9dd9d909014c548a0b945028
python/cpython
python__cpython-111113
# Misleading socketserver.TCPServer example recv semantics # Documentation Issue (on https://docs.python.org/3/library/socketserver.html#socketserver-tcpserver-example): ``` self.data = self.request.recv(1024).strip() print("{} wrote:".format(self.client_address[0])) ``` socket.recv(), as documented by the Python reference documentation, returns at most `bufsize` bytes, and the underlying TCP protocol means there is no guaranteed correspondence between what is sent by the client and what is received by the server. This conflation could mislead readers into thinking that TCP is datagram-based or has similar semantics, which will likely appear to work for simple cases, but introduce difficult to reproduce bugs. <!-- gh-linked-prs --> ### Linked PRs * gh-111113 * gh-114831 * gh-114832 <!-- /gh-linked-prs -->
a79a27242f75fc33416d4d135a4a542898d140e5
80aa7b3688b8fdc85cd53d4113cb5f6ce5500027
python/cpython
python__cpython-111093
# turtledemo: add root arg to PanedWindow call ``` import tkinter as tk tk._support_default_root=False from turtledemo.__main__ import main main() ``` currently fails at line 165: `pane = PanedWindow(orient=HORIZONTAL, ...` with `RuntimeError: No master specified and tkinter is configured to not support default root`. Since all other widget calls include a master argument, adding 'root' here fixes the failure. <!-- gh-linked-prs --> ### Linked PRs * gh-111093 * gh-111095 * gh-111096 <!-- /gh-linked-prs -->
b802882fb2bff8b431df661322908c07491f3ce7
8d234cd315a4c98a87778cc15e7563c7fe74881f
python/cpython
python__cpython-111091
# [C API] Change PyUnicode_AsUTF8() to return NULL on embedded null characters I propose to change the `PyUnicode_AsUTF8()` API to raise an exception and return NULL if the string contains embedded null characters. If the string contains an embedded null character, the UTF-8 encoded string can be truncated if used with C functions using `char*` since a null byte is treated as the terminator: marker of the string end. Truncating a string **silently** is a bad practice and can lead to different bugs including security vulnerabilities. In practice, the minority of impacted C extensions and impacted users should **benefit** of such backward incompatible change, since truncating a string **silently** is a bad practice. Impacted users can use `PyUnicode_AsUTF8AndSize(obj, NULL)` and just ignore the size if they want to truncate **on purpose**. It would address the following "hidden" comment on PyUnicode_AsUTF8(): > Use of this API is **DEPRECATED** since no size information can be > extracted from the returned data. PyUnicode_AsUTF8String() is part of the limited C API, whereas PyUnicode_AsUTF8() is not. In the recently added PyUnicode_EqualToUTF8(obj, str), *str* is treated as not equal if *obj* contains embedded null characters. The folllowing functions already raise an exception if the string contains embedded null characters or bytes: * PyUnicode_AsWideCharString() * PyUnicode_EncodeLocale() * PyUnicode_EncodeFSDefault() * PyUnicode_DecodeLocale(), PyUnicode_DecodeLocaleAndSize() * PyUnicode_DecodeFSDefaultAndSize() * PyUnicode_FSConverter() * PyUnicode_FSDecoder() PyUnicode_AsUTF8String() returns a bytes object and so the length, so it doesn't raise the exception. PyUnicode_AsUTF8AndSize() also returns the size and so don't raise on embedded null characters. <!-- gh-linked-prs --> ### Linked PRs * gh-111091 * gh-111106 * gh-111121 * gh-111122 * gh-111585 * gh-111587 * gh-111620 * gh-111672 * gh-111688 * gh-111833 <!-- /gh-linked-prs -->
11e83488c5a4a6e75a4f363a2e1a45574fd53573
ea970fb116a114f2c47cc8f21df00166d43ab78b
python/cpython
python__cpython-111067
# Add more tests for the C API with the PySys_ prefix Currently there are only tests for `PySys_GetObject()` and `PySys_SetObject()` (added in #107735). But it seems that more than one new functions will be added in #108512. There will be more tests, and it is more convenient to have special files for the C API with the PySys_ prefix. It is also an opportunity to add more tests. <!-- gh-linked-prs --> ### Linked PRs * gh-111067 * gh-111305 <!-- /gh-linked-prs -->
b2ba2985275d1200e5c44c3f224d754141fc5292
0d1cbff833f761f80383f4ce5fe31f686f3f04eb
python/cpython
python__cpython-112428
# Python 3.12 inspecting a coroutine using `getcoroutinestate` returns the wrong state. # Bug report ### Bug description: Prior to Python 3.12, we can close a just created coroutine, thus, the following test passes: ```python from inspect import getcoroutinestate, CORO_CLOSED async def do_nothing(): pass def test_immediate_close(): coro = do_nothing() coro.close() assert getcoroutinestate(coro) == CORO_CLOSED ``` But in Python 3.12, the assertion fails and `getcoroutinestate(coro)` still is `CORO_CREATED` after the `coro.close()`. You can confirm it from https://github.com/gottadiveintopython/py312/actions/runs/6571303025/job/17850194150. I don't know if this is an intensional change or not, but I just wanted to tell you. ### CPython versions tested on: 3.12 ### Operating systems tested on: Linux <!-- gh-linked-prs --> ### Linked PRs * gh-112428 * gh-112589 <!-- /gh-linked-prs -->
bfb576ee23c133bec0ce7c26a8ecea76926b9d8e
a65a3d4806a4087f229b5ab6ab28d3e0b0a2d840
python/cpython
python__cpython-111052
# pdb should check if the executing file is modified and warn users # Feature or enhancement ### Proposal: It's possible that the file is modified during debugging, which would definitely confuse users - the source will not match the execution anymore. There's no perfect solution under such circunstances, but we should at least warn users that this is happening. ### Has this already been discussed elsewhere? This is a minor feature, which does not need previous discussion elsewhere ### Links to previous discussion of this feature: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-111052 * gh-121959 * gh-122114 <!-- /gh-linked-prs -->
8278fa2f5625b41be91191d18ee8eeab904a54ff
07ef63fb6a0fb996d5f56c79f4ccd7a1887a6b2b
python/cpython
python__cpython-111053
# IDLE: Simplify configdialog.HighPage.theme_elements dict This dict maps a selection-list display phrase, such as "Normal Code or Text", to the internal name for the theme, which is here "normal". In order to display the display phrase keys in a deterministic order, the internal name values were combined in a tuple with the the desired position of the display name in the selection list. This is used to sort the list. Hence, the first pair in the theme_elements definition is currently "'Normal Code or Text': ('normal', '00')". Now that dict keys iterate in insertion order, the position value is no longer needed. (The definition display already has items in their desired order.) Remove the position values and make the internal name the item value. Remove the redundant sorting of display phrases. Simplify internal name access by removing the '[0]' index to get the first element of a tuple. (As a side effect, we will be able to alter the order without changing the hard-coded positions.) <!-- gh-linked-prs --> ### Linked PRs * gh-111053 * gh-111055 * gh-111056 <!-- /gh-linked-prs -->
642eb8df951f2f1d4bf4d93ee568707c5bf40a96
19916941172844f9c52d7a6dce95efaa23035772
python/cpython
python__cpython-111221
# Segfault during garbage collection with GzipFile + failed urllib3 request on 3.12.0 # Crash report ### What happened? ```python import urllib3 import gzip import io import json import faulthandler faulthandler.enable() def test(): buffer = gzip.GzipFile(fileobj=io.BytesIO(), mode="w", compresslevel=5) fileobj = buffer.fileobj # get a reference to the fileobj before closing the gzip file buffer.close() data = fileobj.getbuffer() headers = {} try: urllib3.request("POST", "http://127.0.0.1:8200/intake/v2/events") except Exception as e: print(e) test() ``` The above example requires `urllib3`, so you'll need to install that first. When the above example is run on Python 3.12.0, it results in a segfault: ``` HTTPConnectionPool(host='127.0.0.1', port=8200): Max retries exceeded with url: /intake/v2/events (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x1053c5280>: Failed to establish a new connection: [Errno 61] Connection refused')) Fatal Python error: Segmentation fault Current thread 0x00000001e1499300 (most recent call first): Garbage-collecting <no Python frame> [1] 38085 segmentation fault python test.py ``` Some weird things: - If I remove the `urllib3.request`, it doesn't segfault. - If the `urllib3.request` *succeeds* (in this case, if I run the Elastic APM Server locally), it doesn't segfault. - If I pull the code out of the function and run it flat, it *doesn't segfault* 🤯: ```python import urllib3 import gzip import io import json import faulthandler faulthandler.enable() buffer = gzip.GzipFile(fileobj=io.BytesIO(), mode="w", compresslevel=5) fileobj = buffer.fileobj # get a reference to the fileobj before closing the gzip file buffer.close() data = fileobj.getbuffer() headers = {} try: urllib3.request("POST", "http://127.0.0.1:8200/intake/v2/events") except Exception as e: print(e) ``` This is an extremely simplified version of the code where I first saw the segfault. Note that you don't even have to send the `data` into the `urllib3.request` to cause the issue. You don't even have to write anything to the buffer! Note, writing to the buffer does not prevent the segfault. I can reproduce this issue on cpython 3.12.0 (built via `pyenv`) locally on macOS and on the `python:3.12.0` docker image. The segfault does not happen on 3.11 and below. ### CPython versions tested on: 3.12, 3.11 (only happens on 3.12) ### Operating systems tested on: Linux, macOS ### Output from running 'python -VV' on the command line: Python 3.12.0 (main, Oct 2 2023, 17:34:07) [Clang 15.0.0 (clang-1500.0.40.1)] <!-- gh-linked-prs --> ### Linked PRs * gh-111221 * gh-113096 <!-- /gh-linked-prs -->
bb36f72efcc6a656e0907ffa83620a1e44044895
4d5d9acb22ee8c6908ebd4fdc3d17472f8b286e3
python/cpython
python__cpython-111099
# Fix threaded build under WASI # Bug report ### Bug description: https://bytecodealliance.zulipchat.com/#narrow/stream/217126-wasmtime/topic/.60missing.20required.20memory.20export.60.20for.20threaded.20CPython/near/397361259 > I think you'll want -Wl,--export-memory (the --export-memory to wasm-ld) to get past that check; threaded modules for WASI need to both import and export their memory right now. ### CPython versions tested on: 3.12 ### Operating systems tested on: Other <!-- gh-linked-prs --> ### Linked PRs * gh-111099 * gh-111141 <!-- /gh-linked-prs -->
5dfa71769f547fffa893a89b0b04d963a41b2441
0937b11b89a26626c51e3975f8c52522e99def26
python/cpython
python__cpython-111032
# We can now untokenize PEP 701 syntax, `test_tokenize` needs an update # Bug report It states: https://github.com/python/cpython/blob/baefbb21d91db2d950706737a6ebee9b2eff5c2d/Lib/test/test_tokenize.py#L1911-L1912 But, it works now 🎉 So, I guess we need to test `f` strings now, since it is an important part of Python's syntax. Before: ``` » ./python.exe -m test test_tokenize Using random seed 465266543 0:00:00 load avg: 2.63 Run 1 test sequentially 0:00:00 load avg: 2.63 [1/1] test_tokenize == Tests result: SUCCESS == 1 test OK. Total duration: 857 ms Total tests: run=107 Total test files: run=1/1 Result: SUCCESS ``` After: ``` » ./python.exe -m test test_tokenize Using random seed 1341397923 0:00:00 load avg: 2.58 Run 1 test sequentially 0:00:00 load avg: 2.58 [1/1] test_tokenize == Tests result: SUCCESS == 1 test OK. Total duration: 1.2 sec Total tests: run=107 Total test files: run=1/1 Result: SUCCESS ``` <!-- gh-linked-prs --> ### Linked PRs * gh-111032 * gh-111061 <!-- /gh-linked-prs -->
e9b5399bee7106beeeb38a45cfef3f0ed3fdd703
642eb8df951f2f1d4bf4d93ee568707c5bf40a96
python/cpython
python__cpython-111020
# Align Expected and Actual titles in assert_has_calls/assert_called_with for greater readability # Feature or enhancement ### Proposal: The current output for `assert_called_with` and `assert_has_calls` has different spacing making visual identification of simple issues challenging. Example: ```pytb File "/usr/lib/python3.10/unittest/mock.py", line 929, in assert_called_with raise AssertionError(_error_message()) from cause AssertionError: expected call not found. Expected: mock('foo', 'bar') Actual: mock('foo', 'foo') <-- moving this two chars to the right would be easier to see foo != bar File "/usr/lib/python3.10/unittest/mock.py", line 966, in assert_has_calls raise AssertionError( AssertionError: Calls not found. Expected: [call('foo', 'bar')] Actual: [call('foo', 'foo')] <-- moving this two chars to the right would be easier to see foo != bar ``` I propose whitespace is added preceding `Actual:` to align as follows: ```pytb File "/usr/lib/python3.10/unittest/mock.py", line 929, in assert_called_with raise AssertionError(_error_message()) from cause AssertionError: expected call not found. Expected: mock('foo', 'bar') Actual: mock('foo', 'foo') File "/usr/lib/python3.10/unittest/mock.py", line 966, in assert_has_calls raise AssertionError( AssertionError: Calls not found. Expected: [call('foo', 'bar')] Actual: [call('foo', 'foo')] ``` I chose preceding to minimize any potential parsing (e.g `Actual :` would make two fields if split by whitespace) ### Has this already been discussed elsewhere? This is a minor feature, which does not need previous discussion elsewhere ### Links to previous discussion of this feature: I found similar, but not exact discussion here https://github.com/python/cpython/issues/79681 <!-- gh-linked-prs --> ### Linked PRs * gh-111020 * gh-111024 * gh-111025 <!-- /gh-linked-prs -->
77dbd956090aac66e264d9d640f6adb6b0930b87
738574fb21967a1f313f1542dd7b70ae0dcd9705
python/cpython
python__cpython-111016
# IDLE.app permissions are not set on installation # Bug report ### Bug description: The `install_IDLE` target in `Mac/Makefile.in` creates IDLE.app in the destination like this: ``` /bin/cp -PR "$(srcdir)/IDLE/IDLE.app" "$(DESTDIR)$(PYTHONAPPSDIR)" ``` It is thus created with whatever permissions were set in the source directory. If the source has no access for group or others set, as in the 3.12.0 release tarball, so will the installed IDLE.app. The Makefile target should ensure that good permissions are set. ### CPython versions tested on: 3.12 ### Operating systems tested on: macOS <!-- gh-linked-prs --> ### Linked PRs * gh-111016 * gh-111037 * gh-111038 <!-- /gh-linked-prs -->
cb1bf89c4066f30c80f7d1193b586a2ff8c40579
3156d193b81f7fefbafa1a5299bc9588a6768956
python/cpython
python__cpython-110998
# test_gdb are not skipped properly if gdb is not available (instead, an uncaught exception is raised) # Bug report ### Bug description: I'm bootstrapping Python 3.13a1 in Fedora Linux. In my environment I've got `gdb` built without Python. Now I want to build full Python and run its tests during the RPM build. **What happens** Tests from package test_gdb fail due to uncaught exception. **What should happen** Tests should be marked as skipped and not executed at all. <details><summary>Traceback</summary> <pre><code> 0:28:25 load avg: 2.73 Re-running 5 failed tests in verbose mode in subprocesses 0:28:25 load avg: 2.73 Run 5 tests in parallel using 2 worker processes (timeout: 45 min, worker timeout: 50 min) 0:28:26 load avg: 2.73 [1/5/1] test.test_gdb.test_cfunction failed (uncaught exception) Re-running test.test_gdb.test_cfunction in verbose mode test test.test_gdb.test_cfunction crashed -- Traceback (most recent call last): File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc _load_run_test(result, runtests) File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test test_mod = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1381, in _gcd_import File "<frozen importlib._bootstrap>", line 1354, in _find_and_load File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 929, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 1008, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_cfunction.py", line 5, in <module> from .util import setup_module, DebuggerTests File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in <module> check_usable_gdb() File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb stdout, stderr = run_gdb( ^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, " Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0: stdout='' stderr='Python scripting is not supported in this copy of GDB.\n' 0:28:26 load avg: 2.73 [2/5/2] test.test_gdb.test_backtrace failed (uncaught exception) Re-running test.test_gdb.test_backtrace in verbose mode test test.test_gdb.test_backtrace crashed -- Traceback (most recent call last): File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc _load_run_test(result, runtests) File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test test_mod = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1381, in _gcd_import File "<frozen importlib._bootstrap>", line 1354, in _find_and_load File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 929, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 1008, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_backtrace.py", line 6, in <module> from .util import setup_module, DebuggerTests, CET_PROTECTION, SAMPLE_SCRIPT File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in <module> check_usable_gdb() File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb stdout, stderr = run_gdb( ^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, " Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0: stdout='' stderr='Python scripting is not supported in this copy of GDB.\n' 0:28:27 load avg: 2.73 [3/5/3] test.test_gdb.test_cfunction_full failed (uncaught exception) Re-running test.test_gdb.test_cfunction_full in verbose mode test test.test_gdb.test_cfunction_full crashed -- Traceback (most recent call last): File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc _load_run_test(result, runtests) File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test test_mod = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1381, in _gcd_import File "<frozen importlib._bootstrap>", line 1354, in _find_and_load File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 929, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 1008, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_cfunction_full.py", line 7, in <module> from .util import setup_module File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in <module> check_usable_gdb() File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb stdout, stderr = run_gdb( ^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, " Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0: stdout='' stderr='Python scripting is not supported in this copy of GDB.\n' 0:28:27 load avg: 2.73 [4/5/4] test.test_gdb.test_misc failed (uncaught exception) Re-running test.test_gdb.test_misc in verbose mode test test.test_gdb.test_misc crashed -- Traceback (most recent call last): File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc _load_run_test(result, runtests) File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test test_mod = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1381, in _gcd_import File "<frozen importlib._bootstrap>", line 1354, in _find_and_load File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 929, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 1008, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_misc.py", line 5, in <module> from .util import run_gdb, setup_module, DebuggerTests, SAMPLE_SCRIPT File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in <module> check_usable_gdb() File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb stdout, stderr = run_gdb( ^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, " Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0: stdout='' stderr='Python scripting is not supported in this copy of GDB.\n' 0:28:27 load avg: 2.73 [5/5/5] test.test_gdb.test_pretty_print failed (uncaught exception) Re-running test.test_gdb.test_pretty_print in verbose mode test test.test_gdb.test_pretty_print crashed -- Traceback (most recent call last): File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 138, in _runtest_env_changed_exc _load_run_test(result, runtests) File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/libregrtest/single.py", line 85, in _load_run_test test_mod = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/importlib/__init__.py", line 88, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1381, in _gcd_import File "<frozen importlib._bootstrap>", line 1354, in _find_and_load File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 929, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 1008, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/test_pretty_print.py", line 5, in <module> from .util import ( File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 124, in <module> check_usable_gdb() File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 107, in check_usable_gdb stdout, stderr = run_gdb( ^^^^^^^^ File "/builddir/build/BUILD/Python-3.13.0a1/Lib/test/test_gdb/util.py", line 64, in run_gdb raise Exception(f"{cmd_text} failed with exit code {proc.returncode}, " Exception: gdb --batch -nx --init-eval-command 'add-auto-load-safe-path /builddir/build/BUILD/Python-3.13.0a1/build/debug/python-gdb.py' '--eval-command=python import sys; print(sys.version_info)' --args /builddir/build/BUILD/Python-3.13.0a1/build/debug/python failed with exit code 1, expected exit code 0: stdout='' stderr='Python scripting is not supported in this copy of GDB.\n' 5 tests failed again: test.test_gdb.test_backtrace test.test_gdb.test_cfunction test.test_gdb.test_cfunction_full test.test_gdb.test_misc test.test_gdb.test_pretty_print </code></pre> </details> I believe the refactoring done in #110026 has introduced a regression. `run_gdb()` used to always return a tuple `(stdout, stderr)`, but now it checks exitcode and raises an exception in case it's not what was expected. `check_usable_gdb()` consumes the values returned from `run_gdb()` and only then marks tests as skipped, but in this case the exception breaks the test run even before this can happen. cc: @vstinner ### CPython versions tested on: CPython main branch ### Operating systems tested on: Linux <!-- gh-linked-prs --> ### Linked PRs * gh-110998 * gh-111003 * gh-111004 <!-- /gh-linked-prs -->
920b3dfacad615c7bb9bd9a35774469f8809b453
2dcc57008be7012b8249208282837ed4d9c3c3e2
python/cpython
python__cpython-110975
# `test_zoneinfo` tests are silently skipped # Bug report This is how `test_zoneinfo` defines its package: https://github.com/python/cpython/blob/b75b1f389f083db8568bff573c33ab4ecf29655a/Lib/test/test_zoneinfo/__init__.py This is problematic, because there are clashin test-classes names in these files. For example: - https://github.com/python/cpython/blob/b75b1f389f083db8568bff573c33ab4ecf29655a/Lib/test/test_zoneinfo/test_zoneinfo.py#L119 - https://github.com/python/cpython/blob/b75b1f389f083db8568bff573c33ab4ecf29655a/Lib/test/test_zoneinfo/test_zoneinfo.py#L404 And: - https://github.com/python/cpython/blob/b75b1f389f083db8568bff573c33ab4ecf29655a/Lib/test/test_zoneinfo/test_zoneinfo_property.py#L94 - https://github.com/python/cpython/blob/b75b1f389f083db8568bff573c33ab4ecf29655a/Lib/test/test_zoneinfo/test_zoneinfo_property.py#L131 So, when running `./python.exe -m test test_zoneinfo`, some tests are not executed because of this clash. Proof: - Before: ``` Total duration: 677 ms Total tests: run=159 skipped=26 Total test files: run=1/1 Result: SUCCESS ``` - After: ``` Total duration: 567 ms Total tests: run=211 skipped=26 Total test files: run=1/1 Result: SUCCESS ``` I have a patch ready. <!-- gh-linked-prs --> ### Linked PRs * gh-110975 <!-- /gh-linked-prs -->
86276fe4f8e0801f1194b55fa8d8cb7dbf8ee658
7237fb578dc9db9dc557759a24d8083425107b91
python/cpython
python__cpython-110969
# [C API] Py_MOD_PER_INTERPRETER_GIL_SUPPORTED added to limited C API without versionning Three constants for PyModuleDef_Slot were added to the limited C API in Python 3.13: * Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED * Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED * Py_MOD_PER_INTERPRETER_GIL_SUPPORTED Problem: there are added without version, as if they are available on Python 3.12 and older, whereas it's not the case. cc @encukou @ericsnowcurrently <!-- gh-linked-prs --> ### Linked PRs * gh-110969 * gh-111584 * gh-111588 <!-- /gh-linked-prs -->
db15fc23c629fb7e0dfd4858c064fcd4c02582b3
9a9fba825f8aaee4ea9b3429875c6c6324d0dee0
python/cpython
python__cpython-110966
# [C API] Move undocumented private _PyArg C API to pycore_modsupport.h internal C API If a 3rd party C extension uses one of these functions, we should consider adding a clean, documented and tested public function to replace it. Private functions and structures: * _PyArg_BadArgument() * _PyArg_CheckPositional() * _PyArg_NoKeywords() * _PyArg_NoPositional() * _PyArg_ParseStack() * _PyArg_ParseStackAndKeywords() * _PyArg_Parser structure * _PyArg_UnpackKeywords() * _PyArg_UnpackKeywordsWithVararg() * _PyArg_UnpackStack() * _Py_ANY_VARARGS() <!-- gh-linked-prs --> ### Linked PRs * gh-110966 * gh-110982 * gh-110984 <!-- /gh-linked-prs -->
be5e8a010341c4d2d28ef53a1baed402ee06466e
054f496bd45cf94eac4158fd60ac95ab5f8e45c4
python/cpython
python__cpython-111017
# asyncio.wait function docstring misleading # Documentation According to [docstring](https://github.com/python/cpython/blob/99b7e1c1d7b02adaf98f24bfb843cc57b677f9d6/Lib/asyncio/tasks.py#L440) "Coroutines will be wrapped in Tasks.". This was [deprecated](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait) starting at 3.11. I can push out a fix sometime soon. <!-- gh-linked-prs --> ### Linked PRs * gh-111017 <!-- /gh-linked-prs -->
7025844f4c79eeb7d767009c7dad606f92079911
e7ae43ad7dde74e731a9d258e372d17f3b2eb893
python/cpython
python__cpython-111041
# Secure coding is not enabled for restorable state! WARNING on Mac OS Sonoma 14.0 # Bug report ### Bug description: With turtle_test.py containing ``` from turtle import home home() ``` running ``` python turtle_test.py ``` outputs: 2023-10-17 08:21:27.948 Python[19831:20908209] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES. ### CPython versions tested on: 3.12 ### Operating systems tested on: macOS <!-- gh-linked-prs --> ### Linked PRs * gh-111041 * gh-112293 * gh-112294 <!-- /gh-linked-prs -->
d67f947c72af8a215db2fd285e5de9b1e671fde1
de2715f086bc799b20e420a82b76180338352565
python/cpython
python__cpython-110945
# Make pdb completion work with alias, convenience variables etc. # Feature or enhancement ### Proposal: The current pdb completion could be improved for the following scenarios: 1. It should support alias if there is any 2. Convenience variables (starting with the `$`) should be supported as an expression 3. For the "command" completion, if there's no command matches, then the user is probably typing an expression to display and we should just complete as expression. ``` # The user probably wants $_frame (pdb) $<tab> ``` ### Has this already been discussed elsewhere? This is a minor feature, which does not need previous discussion elsewhere ### Links to previous discussion of this feature: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-110945 * gh-111826 * gh-112024 * gh-112025 <!-- /gh-linked-prs -->
f44d6ff6e0c9eeb0bb246a3dd8f99d40b7050054
324531df909721978446d504186738a33ab03fd5
python/cpython
python__cpython-110973
# invalid_def_raw and invalid_class_def_raw rules do not account for type parameters # Bug report ### Bug description: The rules which are affected are here: https://github.com/python/cpython/blob/6a4528d70c8435d4403e09937068a446f35a78ac/Grammar/python.gram#L1371 Typically I believe they should read ``` invalid_def_raw: | ['async'] a='def' NAME [type_params] '(' [params] ')' ['->' expression] ':' NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block after function definition on line %d", a->lineno) } invalid_class_def_raw: | 'class' NAME [type_params] ['(' [arguments] ')'] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") } | a='class' NAME [type_params] ['(' [arguments] ')'] ':' NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block after class definition on line %d", a->lineno) } ``` to allow proper error reporting if the definition uses type parameters. ### CPython versions tested on: 3.12 ### Operating systems tested on: _No response_ <!-- gh-linked-prs --> ### Linked PRs * gh-110973 * gh-110986 * gh-110990 * gh-111023 <!-- /gh-linked-prs -->
24e4ec7766fd471deb5b7e5087f0e7dba8576cfb
be5e8a010341c4d2d28ef53a1baed402ee06466e
python/cpython
python__cpython-111143
# SOURCE_DATE_EPOCH: AssertionError: 'Using random seed ([0-9]+)' not found in 'Using random seed None...' # Bug report ### Bug description: After https://github.com/python/cpython/pull/110168 when the test suite is run with `$SOURCE_DATE_EPOCH` set, `test_regrtest` fails. <details> <summary> Traceback: </summary> ```python $ SOURCE_DATE_EPOCH=1649999999 ./python -m test.regrtest -v test_regrtest == CPython 3.13.0a1+ (heads/main:a1ac5590e0f, Oct 16 2023, 16:57:59) [GCC 12.3.1 20230508 (Red Hat 12.3.1-1)] == Linux-6.3.5-100.fc37.x86_64-x86_64-with-glibc2.36 little-endian == Python build: release == cwd: .../cpython/build/test_python_worker_3521824æ == CPU count: 8 == encodings: locale=UTF-8 FS=utf-8 == resources: all test resources are disabled, use -u option to unskip tests Using random seed None 0:00:00 load avg: 6.56 Run 1 test sequentially 0:00:00 load avg: 6.56 [1/1] test_regrtest test_add_python_opts (test.test_regrtest.ArgsTestCase.test_add_python_opts) ... ok test_cleanup (test.test_regrtest.ArgsTestCase.test_cleanup) ... ok test_coverage (test.test_regrtest.ArgsTestCase.test_coverage) ... ok test_crashed (test.test_regrtest.ArgsTestCase.test_crashed) ... ok test_doctest (test.test_regrtest.ArgsTestCase.test_doctest) ... ok test_env_changed (test.test_regrtest.ArgsTestCase.test_env_changed) ... ok test_failing_test (test.test_regrtest.ArgsTestCase.test_failing_test) ... ok test_forever (test.test_regrtest.ArgsTestCase.test_forever) ... ok test_fromfile (test.test_regrtest.ArgsTestCase.test_fromfile) ... ok test_huntrleaks (test.test_regrtest.ArgsTestCase.test_huntrleaks) ... skipped 'need a debug build' test_huntrleaks_fd_leak (test.test_regrtest.ArgsTestCase.test_huntrleaks_fd_leak) ... skipped 'need a debug build' test_huntrleaks_mp (test.test_regrtest.ArgsTestCase.test_huntrleaks_mp) ... skipped 'need a debug build' test_ignorefile (test.test_regrtest.ArgsTestCase.test_ignorefile) ... ok test_interrupted (test.test_regrtest.ArgsTestCase.test_interrupted) ... ok test_leak_tmp_file (test.test_regrtest.ArgsTestCase.test_leak_tmp_file) ... ok test_list_cases (test.test_regrtest.ArgsTestCase.test_list_cases) ... ok test_list_tests (test.test_regrtest.ArgsTestCase.test_list_tests) ... ok test_matchfile (test.test_regrtest.ArgsTestCase.test_matchfile) ... ok test_multiprocessing_timeout (test.test_regrtest.ArgsTestCase.test_multiprocessing_timeout) ... ok test_no_test_ran_some_test_exist_some_not (test.test_regrtest.ArgsTestCase.test_no_test_ran_some_test_exist_some_not) ... ok test_no_tests_ran (test.test_regrtest.ArgsTestCase.test_no_tests_ran) ... ok test_no_tests_ran_multiple_tests_nonexistent (test.test_regrtest.ArgsTestCase.test_no_tests_ran_multiple_tests_nonexistent) ... ok test_no_tests_ran_skip (test.test_regrtest.ArgsTestCase.test_no_tests_ran_skip) ... ok test_print_warning (test.test_regrtest.ArgsTestCase.test_print_warning) ... ok test_python_command (test.test_regrtest.ArgsTestCase.test_python_command) ... ok test_random (test.test_regrtest.ArgsTestCase.test_random) ... FAIL test_random_seed (test.test_regrtest.ArgsTestCase.test_random_seed) ... FAIL test_random_seed_workers (test.test_regrtest.ArgsTestCase.test_random_seed_workers) ... FAIL test_rerun_async_setup_hook_failure (test.test_regrtest.ArgsTestCase.test_rerun_async_setup_hook_failure) ... ok test_rerun_async_teardown_hook_failure (test.test_regrtest.ArgsTestCase.test_rerun_async_teardown_hook_failure) ... ok test_rerun_fail (test.test_regrtest.ArgsTestCase.test_rerun_fail) ... ok test_rerun_setup_class_hook_failure (test.test_regrtest.ArgsTestCase.test_rerun_setup_class_hook_failure) ... ok test_rerun_setup_hook_failure (test.test_regrtest.ArgsTestCase.test_rerun_setup_hook_failure) ... ok test_rerun_setup_module_hook_failure (test.test_regrtest.ArgsTestCase.test_rerun_setup_module_hook_failure) ... ok test_rerun_success (test.test_regrtest.ArgsTestCase.test_rerun_success) ... ok test_rerun_teardown_class_hook_failure (test.test_regrtest.ArgsTestCase.test_rerun_teardown_class_hook_failure) ... ok test_rerun_teardown_hook_failure (test.test_regrtest.ArgsTestCase.test_rerun_teardown_hook_failure) ... ok test_rerun_teardown_module_hook_failure (test.test_regrtest.ArgsTestCase.test_rerun_teardown_module_hook_failure) ... ok test_resources (test.test_regrtest.ArgsTestCase.test_resources) ... ok test_skip (test.test_regrtest.ArgsTestCase.test_skip) ... ok test_slowest (test.test_regrtest.ArgsTestCase.test_slowest) ... ok test_slowest_interrupted (test.test_regrtest.ArgsTestCase.test_slowest_interrupted) ... ok test_success (test.test_regrtest.ArgsTestCase.test_success) ... ok test_threading_excepthook (test.test_regrtest.ArgsTestCase.test_threading_excepthook) ... ok test_uncollectable (test.test_regrtest.ArgsTestCase.test_uncollectable) ... ok test_unicode_guard_env (test.test_regrtest.ArgsTestCase.test_unicode_guard_env) ... ok test_unraisable_exc (test.test_regrtest.ArgsTestCase.test_unraisable_exc) ... ok test_wait (test.test_regrtest.ArgsTestCase.test_wait) ... ok test_worker_decode_error (test.test_regrtest.ArgsTestCase.test_worker_decode_error) ... ok test_worker_output_on_failure (test.test_regrtest.ArgsTestCase.test_worker_output_on_failure) ... ok test_finds_expected_number_of_tests (test.test_regrtest.CheckActualTests.test_finds_expected_number_of_tests) Check that regrtest appears to find the expected set of tests. ... ok test_arg (test.test_regrtest.ParseArgsTestCase.test_arg) ... ok test_arg_option_arg (test.test_regrtest.ParseArgsTestCase.test_arg_option_arg) ... ok test_coverage (test.test_regrtest.ParseArgsTestCase.test_coverage) ... ok test_coverdir (test.test_regrtest.ParseArgsTestCase.test_coverdir) ... ok test_dont_add_python_opts (test.test_regrtest.ParseArgsTestCase.test_dont_add_python_opts) ... ok test_exclude (test.test_regrtest.ParseArgsTestCase.test_exclude) ... ok test_failfast (test.test_regrtest.ParseArgsTestCase.test_failfast) ... ok test_fast_ci (test.test_regrtest.ParseArgsTestCase.test_fast_ci) ... FAIL test_fast_ci_python_cmd (test.test_regrtest.ParseArgsTestCase.test_fast_ci_python_cmd) ... FAIL test_fast_ci_resource (test.test_regrtest.ParseArgsTestCase.test_fast_ci_resource) ... FAIL test_forever (test.test_regrtest.ParseArgsTestCase.test_forever) ... ok test_fromfile (test.test_regrtest.ParseArgsTestCase.test_fromfile) ... ok test_header (test.test_regrtest.ParseArgsTestCase.test_header) ... ok test_help (test.test_regrtest.ParseArgsTestCase.test_help) ... ok test_huntrleaks (test.test_regrtest.ParseArgsTestCase.test_huntrleaks) ... ok test_ignore (test.test_regrtest.ParseArgsTestCase.test_ignore) ... ok test_long_option__partial (test.test_regrtest.ParseArgsTestCase.test_long_option__partial) ... ok test_match (test.test_regrtest.ParseArgsTestCase.test_match) ... ok test_memlimit (test.test_regrtest.ParseArgsTestCase.test_memlimit) ... ok test_multiprocess (test.test_regrtest.ParseArgsTestCase.test_multiprocess) ... ok test_nocoverdir (test.test_regrtest.ParseArgsTestCase.test_nocoverdir) ... ok test_nowindows (test.test_regrtest.ParseArgsTestCase.test_nowindows) ... ok test_option_and_arg (test.test_regrtest.ParseArgsTestCase.test_option_and_arg) ... ok test_option_with_empty_string_value (test.test_regrtest.ParseArgsTestCase.test_option_with_empty_string_value) ... ok test_quiet (test.test_regrtest.ParseArgsTestCase.test_quiet) ... ok test_randomize (test.test_regrtest.ParseArgsTestCase.test_randomize) ... ok test_randseed (test.test_regrtest.ParseArgsTestCase.test_randseed) ... ok test_rerun (test.test_regrtest.ParseArgsTestCase.test_rerun) ... ok test_runleaks (test.test_regrtest.ParseArgsTestCase.test_runleaks) ... ok test_single (test.test_regrtest.ParseArgsTestCase.test_single) ... ok test_slow_ci (test.test_regrtest.ParseArgsTestCase.test_slow_ci) ... FAIL test_slowest (test.test_regrtest.ParseArgsTestCase.test_slowest) ... ok test_start (test.test_regrtest.ParseArgsTestCase.test_start) ... ok test_testdir (test.test_regrtest.ParseArgsTestCase.test_testdir) ... ok test_threshold (test.test_regrtest.ParseArgsTestCase.test_threshold) ... ok test_timeout (test.test_regrtest.ParseArgsTestCase.test_timeout) ... ok test_two_options (test.test_regrtest.ParseArgsTestCase.test_two_options) ... ok test_unknown_option (test.test_regrtest.ParseArgsTestCase.test_unknown_option) ... ok test_unrecognized_argument (test.test_regrtest.ParseArgsTestCase.test_unrecognized_argument) ... ok test_use (test.test_regrtest.ParseArgsTestCase.test_use) ... ok test_verbose (test.test_regrtest.ParseArgsTestCase.test_verbose) ... ok test_verbose3 (test.test_regrtest.ParseArgsTestCase.test_verbose3) ... ok test_wait (test.test_regrtest.ParseArgsTestCase.test_wait) ... ok test_module_autotest (test.test_regrtest.ProgramsTestCase.test_module_autotest) ... FAIL test_module_from_test_autotest (test.test_regrtest.ProgramsTestCase.test_module_from_test_autotest) ... FAIL test_module_regrtest (test.test_regrtest.ProgramsTestCase.test_module_regrtest) ... FAIL test_module_test (test.test_regrtest.ProgramsTestCase.test_module_test) ... FAIL test_pcbuild_rt (test.test_regrtest.ProgramsTestCase.test_pcbuild_rt) ... skipped 'Windows only' test_script_autotest (test.test_regrtest.ProgramsTestCase.test_script_autotest) ... FAIL test_script_regrtest (test.test_regrtest.ProgramsTestCase.test_script_regrtest) ... FAIL test_tools_buildbot_test (test.test_regrtest.ProgramsTestCase.test_tools_buildbot_test) ... skipped 'Windows only' test_format_duration (test.test_regrtest.TestUtils.test_format_duration) ... ok test_format_resources (test.test_regrtest.TestUtils.test_format_resources) ... ok test_get_signal_name (test.test_regrtest.TestUtils.test_get_signal_name) ... ok test_normalize_test_name (test.test_regrtest.TestUtils.test_normalize_test_name) ... ok ====================================================================== FAIL: test_random (test.test_regrtest.ArgsTestCase.test_random) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 940, in test_random randseed = self.parse_random_seed(output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 665, in parse_random_seed match = self.regex_search(r'Using random seed ([0-9]+)', output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 488, in regex_search self.fail("%r not found in %r" % (regex, output)) AssertionError: 'Using random seed ([0-9]+)' not found in 'Using random seed None\n0:00:00 load avg: 7.05 Run 1 test sequentially\n0:00:00 load avg: 7.05 [1/1] test_regrtest_random\nTESTRANDOM: 794\ntest_regrtest_random ran no tests\n\n== Tests result: NO TESTS RAN ==\n\n1 test run no tests:\n test_regrtest_random\n\nTotal duration: 52 ms\nTotal tests: run=0\nTotal test files: run=1/1 run_no_tests=1\nResult: NO TESTS RAN\n' ====================================================================== FAIL: test_random_seed (test.test_regrtest.ArgsTestCase.test_random_seed) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 1954, in test_random_seed self._check_random_seed(run_workers=False) File ".../cpython/Lib/test/test_regrtest.py", line 1951, in _check_random_seed self.assertEqual(matches, [expected] * len(tests)) AssertionError: Lists differ: ['Random numbers: [503, 432, 8, 125, 683, 217, 539, 633, 376[141 chars]76]'] != ['Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 29[142 chars]36]'] First differing element 0: 'Random numbers: [503, 432, 8, 125, 683, 217, 539, 633, 376, 549]' 'Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 294, 136]' - ['Random numbers: [503, 432, 8, 125, 683, 217, 539, 633, 376, 549]', - 'Random numbers: [155, 758, 193, 409, 656, 829, 891, 649, 708, 353]', - 'Random numbers: [361, 569, 523, 955, 15, 366, 121, 82, 878, 876]'] + ['Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 294, 136]', + 'Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 294, 136]', + 'Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 294, 136]'] ====================================================================== FAIL: test_random_seed_workers (test.test_regrtest.ArgsTestCase.test_random_seed_workers) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 1957, in test_random_seed_workers self._check_random_seed(run_workers=True) File ".../cpython/Lib/test/test_regrtest.py", line 1951, in _check_random_seed self.assertEqual(matches, [expected] * len(tests)) AssertionError: Lists differ: ['Random numbers: [762, 220, 332, 666, 137, 398, 674, 781, 5[142 chars]78]'] != ['Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 29[142 chars]36]'] First differing element 0: 'Random numbers: [762, 220, 332, 666, 137, 398, 674, 781, 565, 877]' 'Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 294, 136]' - ['Random numbers: [762, 220, 332, 666, 137, 398, 674, 781, 565, 877]', - 'Random numbers: [575, 517, 485, 394, 742, 165, 158, 4, 970, 86]', - 'Random numbers: [143, 808, 956, 892, 987, 384, 744, 777, 658, 178]'] + ['Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 294, 136]', + 'Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 294, 136]', + 'Random numbers: [160, 631, 525, 973, 159, 624, 86, 148, 294, 136]'] ====================================================================== FAIL: test_fast_ci (test.test_regrtest.ParseArgsTestCase.test_fast_ci) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 406, in test_fast_ci regrtest = self.check_ci_mode(args, use_resources) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 394, in check_ci_mode self.assertTrue(regrtest.randomize) AssertionError: False is not true ====================================================================== FAIL: test_fast_ci_python_cmd (test.test_regrtest.ParseArgsTestCase.test_fast_ci_python_cmd) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 413, in test_fast_ci_python_cmd regrtest = self.check_ci_mode(args, use_resources, rerun=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 394, in check_ci_mode self.assertTrue(regrtest.randomize) AssertionError: False is not true ====================================================================== FAIL: test_fast_ci_resource (test.test_regrtest.ParseArgsTestCase.test_fast_ci_resource) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 423, in test_fast_ci_resource self.check_ci_mode(args, use_resources) File ".../cpython/Lib/test/test_regrtest.py", line 394, in check_ci_mode self.assertTrue(regrtest.randomize) AssertionError: False is not true ====================================================================== FAIL: test_slow_ci (test.test_regrtest.ParseArgsTestCase.test_slow_ci) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 428, in test_slow_ci regrtest = self.check_ci_mode(args, use_resources) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 394, in check_ci_mode self.assertTrue(regrtest.randomize) AssertionError: False is not true ====================================================================== FAIL: test_module_autotest (test.test_regrtest.ProgramsTestCase.test_module_autotest) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 785, in test_module_autotest self.run_tests(args) File ".../cpython/Lib/test/test_regrtest.py", line 760, in run_tests self.check_output(output) File ".../cpython/Lib/test/test_regrtest.py", line 754, in check_output self.parse_random_seed(output) File ".../cpython/Lib/test/test_regrtest.py", line 665, in parse_random_seed match = self.regex_search(r'Using random seed ([0-9]+)', output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 488, in regex_search self.fail("%r not found in %r" % (regex, output)) AssertionError: 'Using random seed ([0-9]+)' not found in 'Using random seed None\n0:00:00 load avg: 6.86 Run 4 tests in parallel using 4 worker processes (timeout: 1 hour, worker timeout: 1 hour 5 min)\n0:00:00 load avg: 6.86 [1/4] test_regrtest_noop52 passed\n0:00:00 load avg: 6.86 [2/4] test_regrtest_noop53 passed\n0:00:00 load avg: 6.86 [3/4] test_regrtest_noop51 passed\n0:00:00 load avg: 6.86 [4/4] test_regrtest_noop50 passed\n\n== Tests result: SUCCESS ==\n\nAll 4 tests OK.\n\nTotal duration: 177 ms\nTotal tests: run=4\nTotal test files: run=4/4\nResult: SUCCESS\n' ====================================================================== FAIL: test_module_from_test_autotest (test.test_regrtest.ProgramsTestCase.test_module_from_test_autotest) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 792, in test_module_from_test_autotest self.run_tests(args) File ".../cpython/Lib/test/test_regrtest.py", line 760, in run_tests self.check_output(output) File ".../cpython/Lib/test/test_regrtest.py", line 754, in check_output self.parse_random_seed(output) File ".../cpython/Lib/test/test_regrtest.py", line 665, in parse_random_seed match = self.regex_search(r'Using random seed ([0-9]+)', output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 488, in regex_search self.fail("%r not found in %r" % (regex, output)) AssertionError: 'Using random seed ([0-9]+)' not found in 'Using random seed None\n0:00:00 load avg: 6.86 Run 4 tests in parallel using 4 worker processes (timeout: 1 hour, worker timeout: 1 hour 5 min)\n0:00:00 load avg: 6.86 [1/4] test_regrtest_noop56 passed\n0:00:00 load avg: 6.86 [2/4] test_regrtest_noop55 passed\n0:00:00 load avg: 6.86 [3/4] test_regrtest_noop57 passed\n0:00:00 load avg: 6.86 [4/4] test_regrtest_noop54 passed\n\n== Tests result: SUCCESS ==\n\nAll 4 tests OK.\n\nTotal duration: 226 ms\nTotal tests: run=4\nTotal test files: run=4/4\nResult: SUCCESS\n' ====================================================================== FAIL: test_module_regrtest (test.test_regrtest.ProgramsTestCase.test_module_regrtest) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 779, in test_module_regrtest self.run_tests(args) File ".../cpython/Lib/test/test_regrtest.py", line 760, in run_tests self.check_output(output) File ".../cpython/Lib/test/test_regrtest.py", line 754, in check_output self.parse_random_seed(output) File ".../cpython/Lib/test/test_regrtest.py", line 665, in parse_random_seed match = self.regex_search(r'Using random seed ([0-9]+)', output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 488, in regex_search self.fail("%r not found in %r" % (regex, output)) AssertionError: 'Using random seed ([0-9]+)' not found in 'Using random seed None\n0:00:00 load avg: 6.86 Run 4 tests in parallel using 4 worker processes (timeout: 1 hour, worker timeout: 1 hour 5 min)\n0:00:00 load avg: 6.86 [1/4] test_regrtest_noop59 passed\n0:00:00 load avg: 6.86 [2/4] test_regrtest_noop58 passed\n0:00:00 load avg: 6.86 [3/4] test_regrtest_noop61 passed\n0:00:00 load avg: 6.86 [4/4] test_regrtest_noop60 passed\n\n== Tests result: SUCCESS ==\n\nAll 4 tests OK.\n\nTotal duration: 227 ms\nTotal tests: run=4\nTotal test files: run=4/4\nResult: SUCCESS\n' ====================================================================== FAIL: test_module_test (test.test_regrtest.ProgramsTestCase.test_module_test) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 773, in test_module_test self.run_tests(args) File ".../cpython/Lib/test/test_regrtest.py", line 760, in run_tests self.check_output(output) File ".../cpython/Lib/test/test_regrtest.py", line 754, in check_output self.parse_random_seed(output) File ".../cpython/Lib/test/test_regrtest.py", line 665, in parse_random_seed match = self.regex_search(r'Using random seed ([0-9]+)', output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 488, in regex_search self.fail("%r not found in %r" % (regex, output)) AssertionError: 'Using random seed ([0-9]+)' not found in 'Using random seed None\n0:00:00 load avg: 6.86 Run 4 tests in parallel using 4 worker processes (timeout: 1 hour, worker timeout: 1 hour 5 min)\n0:00:00 load avg: 6.86 [1/4] test_regrtest_noop62 passed\n0:00:00 load avg: 6.86 [2/4] test_regrtest_noop64 passed\n0:00:00 load avg: 6.86 [3/4] test_regrtest_noop65 passed\n0:00:00 load avg: 6.86 [4/4] test_regrtest_noop63 passed\n\n== Tests result: SUCCESS ==\n\nAll 4 tests OK.\n\nTotal duration: 175 ms\nTotal tests: run=4\nTotal test files: run=4/4\nResult: SUCCESS\n' ====================================================================== FAIL: test_script_autotest (test.test_regrtest.ProgramsTestCase.test_script_autotest) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 798, in test_script_autotest self.run_tests(args) File ".../cpython/Lib/test/test_regrtest.py", line 760, in run_tests self.check_output(output) File ".../cpython/Lib/test/test_regrtest.py", line 754, in check_output self.parse_random_seed(output) File ".../cpython/Lib/test/test_regrtest.py", line 665, in parse_random_seed match = self.regex_search(r'Using random seed ([0-9]+)', output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 488, in regex_search self.fail("%r not found in %r" % (regex, output)) AssertionError: 'Using random seed ([0-9]+)' not found in 'Using random seed None\n0:00:00 load avg: 6.86 Run 4 tests in parallel using 4 worker processes (timeout: 1 hour, worker timeout: 1 hour 5 min)\n0:00:00 load avg: 6.86 [1/4] test_regrtest_noop69 passed\n0:00:00 load avg: 6.86 [2/4] test_regrtest_noop68 passed\n0:00:00 load avg: 6.86 [3/4] test_regrtest_noop66 passed\n0:00:00 load avg: 6.86 [4/4] test_regrtest_noop67 passed\n\n== Tests result: SUCCESS ==\n\nAll 4 tests OK.\n\nTotal duration: 227 ms\nTotal tests: run=4\nTotal test files: run=4/4\nResult: SUCCESS\n' ====================================================================== FAIL: test_script_regrtest (test.test_regrtest.ProgramsTestCase.test_script_regrtest) ---------------------------------------------------------------------- Traceback (most recent call last): File ".../cpython/Lib/test/test_regrtest.py", line 767, in test_script_regrtest self.run_tests(args) File ".../cpython/Lib/test/test_regrtest.py", line 760, in run_tests self.check_output(output) File ".../cpython/Lib/test/test_regrtest.py", line 754, in check_output self.parse_random_seed(output) File ".../cpython/Lib/test/test_regrtest.py", line 665, in parse_random_seed match = self.regex_search(r'Using random seed ([0-9]+)', output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../cpython/Lib/test/test_regrtest.py", line 488, in regex_search self.fail("%r not found in %r" % (regex, output)) AssertionError: 'Using random seed ([0-9]+)' not found in 'Using random seed None\n0:00:00 load avg: 6.86 Run 4 tests in parallel using 4 worker processes (timeout: 1 hour, worker timeout: 1 hour 5 min)\n0:00:00 load avg: 6.86 [1/4] test_regrtest_noop72 passed\n0:00:00 load avg: 6.86 [2/4] test_regrtest_noop73 passed\n0:00:00 load avg: 6.86 [3/4] test_regrtest_noop70 passed\n0:00:00 load avg: 6.86 [4/4] test_regrtest_noop71 passed\n\n== Tests result: SUCCESS ==\n\nAll 4 tests OK.\n\nTotal duration: 184 ms\nTotal tests: run=4\nTotal test files: run=4/4\nResult: SUCCESS\n' ---------------------------------------------------------------------- Ran 103 tests in 27.042s FAILED (failures=13, skipped=5) test test_regrtest failed test_regrtest failed (13 failures) == Tests result: FAILURE == 1 test failed: test_regrtest Total duration: 27.1 sec Total tests: run=103 failures=13 skipped=5 Total test files: run=1/1 failed=1 Result: FAILURE ``` </details> ### CPython versions tested on: CPython main branch ### Operating systems tested on: Linux <!-- gh-linked-prs --> ### Linked PRs * gh-111143 * gh-111153 * gh-111154 <!-- /gh-linked-prs -->
7237fb578dc9db9dc557759a24d8083425107b91
b07f23259d30e61fd7cc975b8b0e3b2e846fed8f
python/cpython
python__cpython-112490
# Should reference to old books be retained? # Documentation A [question on the help channel](https://discuss.python.org/t/offical-documentation/36356) asked about a reference to a "twenty year old book," but didn't specify it. I assume the poster was referring to Mark Lutz's book. I realize that book has a place in Python history as perhaps the first widely read book on Python, but should it still be afforded more-or-less first class status as Python reference material? I don't know when it was last updated, so maybe it's up-to-date and the link just needs to be corrected, but if not, perhaps we should continue ourselves to more recent, online, sources which better match the current language. <!-- gh-linked-prs --> ### Linked PRs * gh-112490 * gh-112523 * gh-112524 <!-- /gh-linked-prs -->
3fdf7ae3d1a08894e53c263945fba67fe62ac05b
a194938f33a71e727e53490815bae874eece1460
python/cpython
python__cpython-110926
# 50% of tests in `test__opcode` are not run # Bug report ### Bug description: Following https://github.com/python/cpython/commit/40f3f11a773b854c6d94746aa3b1881c8ac71b0f, `test__opcode.py` has two subclasses of `unittest.TestCase` in the global namespace that are both called `OpListTests`. This means that all tests in the first class are silently skipped in CI, as the whole class definition is overridden by the second class at import time, before unittest even tries to load the tests inside the class. If the `TestCase` subclasses are given different names, the tests in the first class fail, as they rely on a helper method that was removed in https://github.com/python/cpython/commit/40f3f11a773b854c6d94746aa3b1881c8ac71b0f. Cc. @iritkatriel as author of https://github.com/python/cpython/commit/40f3f11a773b854c6d94746aa3b1881c8ac71b0f ### CPython versions tested on: CPython main branch ### Operating systems tested on: Windows <!-- gh-linked-prs --> ### Linked PRs * gh-110926 <!-- /gh-linked-prs -->
14d2d1576d9301032a6a1f62caa347ff1685c872
bfc1cd8145db00df23fbbd2ed95324bb96c0b25b