360 Commits

Author SHA1 Message Date
Jeong, YunWon
fddd7cb690 fix cron-ci (#7483)
* fix cron-ci

* fix custom_text_test_runner
2026-03-27 23:55:30 +09:00
Christian Legnitto
2180f535d8 Fix sub_table ordering for nested inlined comprehensions (PEP 709) (#7480)
When an inlined comprehension's first iterator expression contains
nested scopes (such as a lambda), those scopes' sub_tables appear at the
current position in the parent's sub_table list. The previous code
spliced the comprehension's own child sub_tables (e.g. inner inlined
comprehensions) into that same position before compiling the iterator,
which shifted the iterator's sub_tables to wrong indices.

Move the splice after the first iterator is compiled so its sub_tables
are consumed at their original positions.

Fixes nested list comprehensions like:
```python
    [[x for _, x in g] for _, g in itertools.groupby(..., lambda x: ...)]
```

Disclosure: I used AI to develop the patch though I was heavily
involved.
2026-03-22 17:23:03 +09:00
Copilot
2f181efed8 Preserve str subclasses in ascii() for ASCII-only __repr__ results (#7455) 2026-03-19 09:48:42 +09:00
Lee Dogeon
97790a88b2 Implement missing slots for NoneType (#7437)
* Define only wrapper_descriptor

* Implement missing slots for NoneType
2026-03-16 11:58:40 +09:00
Jeong, YunWon
0355885651 Fix parking lot hash table after fork (#6963)
* Use patched parking_lot_core with fork-safe HASHTABLE reset

parking_lot_core's global HASHTABLE retains stale ThreadData after
fork(), causing segfaults when contended locks enter park(). Use the
patched version from youknowone/parking_lot (rustpython branch) which
registers a pthread_atfork handler to reset the hash table.

Unskip test_asyncio TestFork. Add Manager+fork integration test.

* Unskip fork-related flaky tests after parking_lot fix

With parking_lot_core's HASHTABLE now properly reset via
pthread_atfork, fork-related segfaults and connection errors
in multiprocessing tests should be resolved.

Remove skip/expectedFailure markers from:
- test_concurrent_futures/test_wait.py (6 tests)
- test_concurrent_futures/test_process_pool.py (1 test)
- test_multiprocessing_fork/test_manager.py (all WithManagerTest*)
- test_multiprocessing_fork/test_misc.py (5 tests)
- test_multiprocessing_fork/test_threads.py (2 tests)
- _test_multiprocessing.py (2 shared_memory tests)

Keep test_repr_rlock skipped (flaky thread start latency,
not fork-related).
2026-03-10 12:57:29 +09:00
Jeong, YunWon
cbcc19751e fix format (#7385) 2026-03-08 22:53:26 +09:00
Jeong, YunWon
46abff6880 Harden CALL specialization guards and cache callables (#7360)
* vm: align CALL/CALL_KW specialization core guards with CPython

* vm: keep specialization hot on misses and add heaptype getitem parity

* vm: align call-alloc/getitem cache guards and call fastpath ordering

* vm: align BINARY_OP, STORE_SUBSCR, UNPACK_SEQUENCE specialization guards

* vm: finalize unicode/subscr specialization parity and regressions

* vm: finalize specialization GC safety, tests, and cleanup
2026-03-08 21:15:30 +09:00
Shahar Naveh
ca390dc5fb io.TextIoWrapper.reconfigure to always flush (#7281)
* Always flush on reconfigure (io.TextWrapper)

* Add test
2026-03-02 01:03:44 +09:00
Shahar Naveh
72570c521c Update CI ruff to 0.15.4 (#7250)
* Update CI ruff to 0.15.4

* Format
2026-02-28 10:34:38 +09:00
Shahar Naveh
e51d6f0df7 Disallow warnings patches (#7249)
* Apply patches

* Remove struct cfg_attr

* Auto-format: ruff format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-27 23:48:09 +09:00
Jiseok CHOI
221dfc2e02 Fix IOBase.isatty() to raise ValueError on closed files (#7233)
* Fix IOBase.isatty() to raise ValueError on closed files

* Add snippet test for IOBase.isatty() closed check
2026-02-27 21:04:47 +09:00
Jiseok CHOI
09cf49204b fix: add flush method to BytesIO (#7235) 2026-02-27 16:53:17 +09:00
Jeong, YunWon
7b866f66e9 Add missing _winapi functions (#7185)
* Add missing _winapi functions and fix WinHandle int conversion

Add 13 functions: ReadFile, SetNamedPipeHandleState, CreateFileMapping,
OpenFileMapping, MapViewOfFile, UnmapViewOfFile, VirtualQuerySize,
CopyFile2, ResetEvent, CreateMutex, OpenEventW, LoadLibrary,
_mimetypes_read_windows_registry.

Add constants: INVALID_HANDLE_VALUE, FILE_MAP_READ/WRITE/COPY/EXECUTE.

Change WinHandle integer type from usize to isize so negative values
like INVALID_HANDLE_VALUE (-1) can be passed from Python.

* Align _winapi module with CPython

- Rename winapi.rs to _winapi.rs with #[path] attribute
- Rename CreateMutex to CreateMutexW
- Add missing constants: ERROR_ACCESS_DENIED, ERROR_PRIVILEGE_NOT_HELD,
  PROCESS_ALL_ACCESS, 10 STARTF_ constants, LOCALE_NAME_SYSTEM_DEFAULT,
  LOCALE_NAME_USER_DEFAULT, COPY_FILE_DIRECTORY
- Fix OpenMutexW return type and ReleaseMutex param type to use WinHandle

* Fix ReadFile/WriteFile overlapped keyword argument

Use FromArgs structs so overlapped parameter can be passed as
a keyword argument (overlapped=True), matching the CPython API.

* Remove extra constants and LoadLibrary not in CPython _winapi

Remove 19 constants (WAIT_ABANDONED, CREATE_ALWAYS, CREATE_NEW,
OPEN_ALWAYS, TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, 8 FILE_FLAG_*,
3 FILE_SHARE_*, NMPWAIT_NOWAIT, NMPWAIT_USE_DEFAULT_WAIT) and
LoadLibrary function that are not present in CPython's _winapi module.

* Fix utf8_mode default to 0 and add PYTHONUTF8 env var support

Default utf8_mode was incorrectly set to 1, causing text-mode
subprocess to always decode as UTF-8 instead of locale encoding.
Changed default to 0 to match CPython 3.13 behavior on Windows.
Added PYTHONUTF8 environment variable handling with -X utf8 override.

* Fix CopyFile2 to raise proper OSError subclass

Use std::io::Error::from_raw_os_error instead of vm.new_os_error so
that winerror attribute is set and errno-to-exception mapping works
(e.g. ERROR_ACCESS_DENIED → PermissionError).

* Fix syntax_non_utf8 test to not depend on locale encoding

Use explicit encoding='latin-1' so the test works regardless of
the system locale (e.g. C/POSIX locale uses ASCII by default).
2026-02-22 19:54:27 +09:00
wvmscs
dfc5de701b Fix re.fullmatch POSSESSIVE_REPEAT (#7187) 2026-02-20 09:51:34 +09:00
Lee Dogeon
d07d52224e Optimize redundant bool check (#7176)
* Add compile_bool_op_inner and optimize nested opposite-operator BoolOps to avoid redundant __bool__ calls

When a nested BoolOp has the opposite operator (e.g., `And` inside `Or`),
the inner BoolOp's short-circuit exits are redirected to skip the outer
BoolOp's redundant truth test. This avoids calling `__bool__()` twice on
the same value (e.g., `Test() and False or False` previously called
`Test().__bool__()` twice instead of once).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add snapshot test for nested BoolOp bytecode

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add runtime test for redundant __bool__ check (issue #3567)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Apply clippy and rustfmt

* Apply ruff format

* Refactor compile_bool_op: extract emit_short_circuit_test and unify with compile_bool_op_inner

Reduce code duplication by:
- Extracting the repeated Copy + conditional jump pattern into emit_short_circuit_test
- Merging compile_bool_op and compile_bool_op_inner into a single
  compile_bool_op_with_target with an optional short_circuit_target parameter
- Keeping compile_bool_op as a thin wrapper for the public interface

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Relocate redundant __bool__ check test snippet

* Update extra_tests/snippets/syntax_short_circuit_bool.py

* Fix assertion in syntax_short_circuit_bool

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2026-02-18 00:45:17 +09:00
Jeong, YunWon
f777416870 initial sandbox (#7035)
* Add host_env feature for sandbox isolation

Introduce a `host_env` feature flag that gates all host environment
access (filesystem, network, signals, processes). When disabled,
the VM operates in sandbox mode:

- _io module always available; FileIO gated by host_env
- SandboxStdio provides lightweight stdin/stdout/stderr via Rust std::io
- BytesIO/StringIO/BufferedIO/TextIOWrapper work without host_env
- open() returns UnsupportedOperation in sandbox
- stdlib modules (os, socket, signal, etc.) gated by host_env
- CI checks both host_env ON and OFF builds

* Auto-format: ruff check --select I --fix

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-08 13:58:30 +00:00
Jeong, YunWon
684e880689 Implement more ast features (#6986) 2026-02-05 16:20:22 +09:00
Jeong, YunWon
95abec4c21 More Load instructions including LoadLocals, LoadFastBorrow (#6886)
* fix stdlib_io

* more scpell dict

* LoadLocals

* LoadFastBorrow

* more ops
2026-01-29 19:33:46 +09:00
Jeong, YunWon
e363b14e81 fix ssl MSG_PEEK (#6892) 2026-01-29 16:48:02 +09:00
Jeong, YunWon
d2166dd93a Fix sorted() to use __lt__ instead of __gt__ (#6887)
* test

* Fix sorted() to use __lt__ instead of __gt__

CPython's sort uses __lt__ for comparisons, but RustPython was using
__gt__. This caused issues when only __lt__ was overridden on a
subclass (e.g., NamedTuple with custom __lt__), as it would fall back
to the parent class's comparison instead of using the overridden method.
2026-01-28 16:55:51 +09:00
Jeong, YunWon
6df3753229 Py 3.14 changes fix (#6755)
* marshal v5

* conditional blclk

* fix jit don't use lossy string

* add varname

* symboltable takes responsibility of __debug__
2026-01-18 01:02:40 +09:00
github-actions[bot]
60fb4384e1 Auto-format: ruff check --select I --fix 2026-01-17 10:34:53 +00:00
Jeong, YunWon
566b6f438b PEP 649 annotation phase 4 2026-01-17 19:21:11 +09:00
Jeong, YunWon
a78b569d92 PEP 649 annotation phase 3 2026-01-17 19:21:11 +09:00
Jeong, YunWon
0793bd3d08 co_consts 2026-01-17 19:21:11 +09:00
Jeong, YunWon
f5b44f505a Fix Exception.__init__ 2026-01-17 19:21:11 +09:00
Jeong, YunWon
24bff8d5bf fix unsigned validation 2026-01-17 19:21:11 +09:00
Jeong, YunWon
eafa0c0149 Fix int rounding 2026-01-17 19:21:11 +09:00
Jeong, YunWon
db01a1d653 Remove pickle from itertools 2026-01-17 19:21:11 +09:00
Jeong, YunWon
2fe140fdb9 Fix bytes/bytearray fromhex 2026-01-17 19:21:11 +09:00
Jeong, YunWon
8d901a7300 Implement bool(NotImplemented) 2026-01-17 19:21:10 +09:00
Jeong, YunWon
e9a57d172b correct builtins type under function (#6745)
* correct buitins type

* Auto-format: ruff format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-17 00:00:16 +09:00
Lee Dogeon
6cb763a332 Fix some parts of cron-ci workflow (#6724)
* Use shared PYTHON_VERSION in cron-ci benchmark job

* Correct extra-tests/jsontests.py script

When the `extra_tests/jsontests.py` script was added, it was presumably during
the time when Python versions 3.5 to 3.8 were in use. At that time,
`test.libregrtest.runtest` was a valid path, but from CPython version 3.11
onwards, the path changed to `test.libregrtest.findtests`.

* Use ssl-rustls feature instead of ssl in cron-ci workflow

Replace the ssl feature with ssl-rustls in both the CARGO_ARGS
environment variable and the cargo-llvm-cov test command to fix
the cron-ci workflow.

Since 1a783fc9ec, it is disallowed
to use ssl manually.

* Replace inspect.getargspec with inspect.getfullargspec in custom_text_test_runner

inspect.getargspec() was removed in Python 3.11, causing jsontests.py to
fail with "TypeError: 'NoneType' object is not iterable" when running on
RustPython (which targets Python 3.13).

The get_function_args() function was silently catching the AttributeError
and returning None, which then caused the error in store_class_fields()
when trying to iterate over None.

> https://docs.python.org/3/whatsnew/3.11.html
> The getargspec() function, deprecated since Python 3.0; use
> inspect.signature() or inspect.getfullargspec() instead.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Exclude rustpython-venvlauncher in cron-ci workflow

Since rustpython-venvlauncher is Windows-only,
it disables the project in the cron-ci workflow.

* Apply suggestion from @fanninpm

Co-authored-by: fanninpm <luxverdans@sbcglobal.net>

* Trigger cron-ci workflow in pull_request

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
Co-authored-by: fanninpm <luxverdans@sbcglobal.net>
2026-01-14 13:28:25 +09:00
HueCodes
83a0deac25 Fix set in-place operators with self argument (#6661)
Co-authored-by: Hugh <HueCodes@users.noreply.github.com>
2026-01-09 21:31:21 +09:00
Copilot
03380dc4ec Ensure __new__ entries in class __dict__ are staticmethods (#6659)
* Initial plan

* Wrap __new__ methods as staticmethods in type dicts

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>

* Unmark passing enum test

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2026-01-06 12:16:51 +09:00
Copilot
7b36c9e8e0 Handle oversized __hash__ results without panicking (#6561)
* Initial plan

* Fix hash wrapper overflow handling

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>

* Auto-format: cargo fmt --all

* Adjust __hash__ wrapper conversion

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>

* Auto-format: cargo fmt --all

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-28 16:27:32 +09:00
Copilot
04a4d1e02f Prevent array.tofile re-entrant deadlock and add regression snippet (#6559)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2025-12-28 14:48:27 +09:00
Copilot
27ab62de48 Prevent __class__ reassignment across incompatible layouts (#6521)
---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2025-12-27 01:16:09 +09:00
Copilot
a7d7f81ca7 Handle unions with GenericAlias subclasses without TypeError (#6540)
---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2025-12-27 01:13:20 +09:00
Jeong, YunWon
4a6e8fb29e Add except* support (#6530) 2025-12-26 21:54:23 +09:00
Copilot
61ddd98b89 Handle missing type_params on AST Function/Class/TypeAlias nodes (#6512)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-25 19:08:23 +09:00
Copilot
a5a1173c3f Disallow rebinding __module__ on immutable builtins and add regression snippet (#6513)
* Initial plan

* Fix __module__ setter on immutable builtin types

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>

* Remove unused value parameter from immutability helper

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>

* Auto-format: cargo fmt --all

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-25 18:27:19 +09:00
Copilot
8443b2c97e Add POSIX shared memory module for multiprocessing on Unix (#6498)
---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-25 14:54:44 +09:00
Copilot
be9e44aafb Allow SyntaxError.msg to be writable and reflected in string formatting (#6493)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2025-12-25 09:08:18 +09:00
Jeong, YunWon
014622ac34 Fix os.access not to raise exception when path doesn't exist (#6477)
* Fix os.access not to raise exception when path doesn't exist

* add test
2025-12-24 14:23:33 +09:00
Shahar Naveh
9d2dd17455 Add regression test (#6452) 2025-12-17 19:02:44 +09:00
Jeong, YunWon
d36a2cffde New subclass payload layout (#6319)
* PySubclass

* Add base payload to exception

* PyStructSequecne base

* redefine PyOSError and subtypes

* heap exception new

* rework UNSUPPORTED_OPERATION
2025-12-14 19:17:14 +09:00
Shahar Naveh
9ccf4c1872 Ruff auto-format (#6422) 2025-12-12 22:46:39 +09:00
Shahar Naveh
a47b32816b Merge pull request #6417 from ShaharNaveh/regr-test-doc-leak
Add regression test for #4505
2025-12-12 21:12:02 +09:00
Jeong, YunWon
98fff96f1c __doc__ handing in the right way (#6390) 2025-12-10 20:04:09 +09:00