Compare commits

...

3061 Commits

Author SHA1 Message Date
dependabot[bot]
855c583bf7 Bump the random group across 1 directory with 3 updates
Bumps the random group with 3 updates in the / directory: [getrandom](https://github.com/rust-random/getrandom), [mt19937](https://github.com/RustPython/mt19937) and [rand](https://github.com/rust-random/rand).


Updates `getrandom` from 0.3.4 to 0.4.2
- [Changelog](https://github.com/rust-random/getrandom/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/getrandom/compare/v0.3.4...v0.4.2)

Updates `mt19937` from 3.2.0 to 3.3.0
- [Commits](https://github.com/RustPython/mt19937/commits)

Updates `rand` from 0.9.4 to 0.10.1
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/0.9.4...0.10.1)

---
updated-dependencies:
- dependency-name: getrandom
  dependency-version: 0.4.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: random
- dependency-name: mt19937
  dependency-version: 3.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: random
- dependency-name: rand
  dependency-version: 0.10.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: random
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-28 03:25:46 +00:00
Joshua Megnauth
7d54ba502e Fix ssl-vendor (OpenSSL) (#7985)
Closes: #7893

Fix 1:
`foreign-types-shared` needs to match `openssl`'s version. Bumping it is
a SemVer violation because the latest versions of the crate aren't
backwards compatible with older versions.
See: rust-openssl/rust-openssl#2461

Fix 2:
The second fix is to align the `openssl` module with the latest
`host_env` and `ssl` changes.
2026-05-28 12:16:08 +09:00
Shahar Naveh
e80a14ba12 Align more error messages with CPython 3.14.5 (#7988)
* Cannot assign to True/False/None

* cannot use assignment expressions with ...

* cannot assign to function call/expression
2026-05-28 11:19:03 +09:00
Joshua Megnauth
30ae48b24b Support custom rustls providers (#7657)
* Modularize rustls as work towards providers

`rustls`'s architecture is very clean and trait-driven. There are many
providers for `rustls` including the built-in `aws-lc-rs` and `ring` as
well as backends for `boringssl`, `graviola`, `openssl`, `mbedtls`, etc.

This commit removes the hard dependency on `aws-lc-rs` and adds support
for `ring`. It works towards #7059 as well.

* Clean up rustls features

* Remove ring as an explicit feature
* ssl-rustls is the default and implies aws-lc

* Support custom rustls crypto providers

The new feature, `ssl-rustls-no-provider`, enables custom rustls
providers. By default, `aws-lc-rs` is enabled which matches the old
behavior and keeps backward compatibility.

I wrote a new type that abstracts what we need from crypto providers.
CryptoExt encapsulates the ticketer as well as cipher suites and KX
groups. I wrote fallbacks to help select a reasonable default if a
provider is missing features (they all seem to support the same things
though).

I also wrote an example to show how to actually use custom providers.

* Fix duplicate VERIFY_X509 constants and unused imports in ssl module

Remove duplicate VERIFY_X509_STRICT/VERIFY_X509_PARTIAL_CHAIN definitions
from compat.rs (already defined in _ssl module with #[pyattr]).
Remove unused imports: ClientConnection, ServerConnection.

* no-provider as default

* Fix CI failures: openssl build, wasm target, cargo-shear

- Update openssl.rs to use renamed sock_wait/SockWaitKind and add vm parameter
- Add skip_ssl for wasm32-wasip2 target (aws-lc-sys cannot build for wasm)
- Remove unused workspace dependency aws-lc-rs
- Fix foreign-types-shared version to match openssl's dependency (0.1)
- Restore Cargo.lock from upstream/main

---------

Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
2026-05-28 11:07:09 +09:00
Jeong, YunWon
1a959cf7f3 Align codegen passes and opcode metadata with CPython (#7987)
* Share marshal ref table between code object and its internals

read_marshal_bytes, _str, _str_vec, _name_tuple, and _const_tuple now
take a shared ref table and resolve TYPE_REF / register FLAG_REF
entries. deserialize_code is split into a public wrapper and an inner
function that receives the ref table; deserialize_value_depth opens a
fresh inner ref space when it hits Type::Code, mirroring CPython's
behaviour of putting the code object itself at ref slot 0. Nested code
objects inside const tuples reuse the surrounding code's ref space via
the new read_const_value helper.

* Align PYC magic number, FORMAT_VERSION, and header check with CPython 3.14

PYC_MAGIC_NUMBER changes from 2994 to 3627, matching CPython 3.14's
pyc_magic_number_token (0x0a0d0e2b). marshal FORMAT_VERSION drops from
5 to 4 (the encoder/marshal.version value; the decoder already accepts
both). check_pyc_magic_number_bytes now compares all four magic bytes
instead of the first two.

* Accept CPython-tagged .pyc as read-only bytecode source

SourceFileLoader.get_code now also looks for .pyc files using
_RP_FALLBACK_CACHE_TAGS (currently ('cpython-314',)) in addition to
sys.implementation.cache_tag. The matched .pyc is only used for
reading; recompilation still writes to the RustPython-tagged path, so
CPython's .pyc is never overwritten. Source-stat / hash / timestamp
validation logic is unchanged.

* Apply rustfmt to marshal helpers

* Marshal PySlice from format version 4 instead of 5

CPython's marshal supports TYPE_SLICE from format version 4 onwards
and that is the default version. Rejecting slice dumps below version
5 made marshal.dumps(slice(...)) fail with the default version and
broke test.test_marshal.SliceTestCase.test_slice.

* Revert "Accept CPython-tagged .pyc as read-only bytecode source"

Lib/importlib/_bootstrap_external.py is CPython's own code copied
verbatim; local patches here defeat compatibility tracking. The
cpython-XX cache_tag fallback needs to live on the RustPython side
(Rust code or sys.implementation.cache_tag policy), not as edits to
the imported standard library.

This reverts commit 1fc426d0fb5fcdb50d35cad13bbb43e8f6ce1c7f.

* Set marshal FORMAT_VERSION to 5 to match CPython 3.14.5

Py_MARSHAL_VERSION is 5 in CPython 3.14.5 (Include/marshal.h:16) and
TYPE_SLICE serialization rejects version < 5 (Python/marshal.c:720).
Restore the same threshold and constant so marshal.version and the
slice-marshal gate match CPython.

* Thread marshal recursion depth through nested code objects

Code objects embedded in const-tuples reset the depth budget on each
recursion, so a hostile or pathological marshal stream of code-in-tuple-
in-code can blow the stack despite MAX_MARSHAL_STACK_DEPTH. Pass the
current depth through deserialize_code_inner and read_marshal_const_tuple
and decrement at each code-object/tuple boundary.

Also route dict keys through deserialize_value_after_header so TYPE_CODE
keys decode instead of failing with BadType.

* align compiler to CPython

* Align codegen with CPython compile.c

Rename CFG helpers and accessors to the names used in CPython's
compile.c (basicblock_next_instr, basicblock_last_instr,
basicblock_append_instructions, bb_has_fallthrough, is_jump,
make_cfg_traversal_stack, mark_warm/mark_cold, etc.). Drop the unused
boolop-folding gate, mark_cpython_cfg_label_block helper, and
ComprehensionLoopControl::iter_range field.

Track an is_coroutine flag on SymbolTable, set in async def, await, and
async comprehensions, and propagate it through non-generator
comprehensions per symtable_handle_comprehension().

Mark SetupCleanup/SetupFinally/SetupWith as has_arg pseudo-ops, mark
ForIter as a terminator, and add has_arg/has_const on AnyInstruction.
Fix Instruction::stack_effect_jump to delegate to the opcode's
stack_effect_jump rather than stack_effect.

* Align codegen IR with CPython CFG structures

* Match CPython CFG annotation offset arithmetic

* Propagate CPython CFG label translation errors

* Align CPython exception target labeling flow

* Propagate CPython CFG traversal stack allocation errors

* Match CPython optimize_load_fast allocation flow

* Propagate CPython basicblock allocation errors

* Propagate CPython redundant NOP cleanup errors

* Propagate CPython unused const cleanup errors

* Propagate CPython const folding errors

* Propagate CPython swaptimize allocation errors

* Match CPython list-to-tuple fold allocation

* Skip const folding on CPython allocation failures

* Skip subscript folding on CPython allocation failures

* Propagate CPython assembler allocation errors

* Propagate CPython localsplus allocation errors

* Propagate CPython localsplus setup allocation errors

* Propagate CPython jump label map allocation errors

* Propagate CPython instruction sequence allocation errors

* Propagate CPython instruction label allocation errors

* Guard CPython codegen block allocation

* Guard CPython label shadow allocation

* Propagate CPython label shadow allocation errors

* Align CPython c-array allocation updates

* Align CPython ref stack growth

* Match CPython CFG builder debug check

* Avoid Rust-only CFG append clone

* Reuse CPython cleared block slots

* Use CPython block append in copy_basicblock

* Match CPython cfg builder creation order

* Clear label map after CPython apply pass

* Match CPython cfg builder allocation check

* Propagate CPython c-array size errors

* Drop Rust-only label uniqueness check

* Drop Rust-only label shadow debug checks

* Propagate CFG block index overflow

* Propagate CFG label oparg overflow

* Model CPython basicblock instruction storage

* Drop Rust-only recorded CFG precheck

* Model CPython instruction sequence storage

* Propagate instruction sequence offset overflow

* Model CPython instruction sequence labels

* Match CPython jump offset arithmetic

* Match CPython exception table arithmetic

* Match CPython label index arithmetic

* Match CPython instruction offset casts

* Match CPython jump offset indexing

* Match CPython oparg locals casts

* Match CPython localsplus offset arithmetic

* Match CPython cell prefix indexing

* Match CPython C array growth arithmetic

* Match CPython label map allocation arithmetic

* Match CPython label map size tracking

* Use CPython label map size in sequence passes

* Assert CPython label map clearing invariants

* Match CPython label oparg assignment

* Match CPython compiler direct arithmetic

* Match CPython load fast local casts

* Match CPython load fast depth assert

* Match CPython resume depth flagging

* Match CPython stack depth arithmetic

* Drop Rust-only stack overflow error

* Return CPython stack depth directly

* Match CPython C array growth errors

* Match CPython instruction insert asserts

* Match CPython unreachable pseudo jump

* Match CPython CFG size guard

* Match CPython superinstruction assert

* Match CPython redundant jump assert

* Match CPython stackdepth errors

* Match CPython jump offset flow

* Match CPython assembler buffer defaults

* Match CPython bytecode emit growth

* Match CPython assembler entry growth

* Match CPython assembler growth overflow check

* Match CPython remove_unreachable structure

* Match CPython static swap flow

* Inline CPython code unit preprocessing

* Match CPython C array growth checks

* Match CPython label map size guard

* Match CPython load-fast flow

* Simplify CPython CFG condition flow

* Align exception fallthrough propagation

* Match CPython pseudo target table

* Match CPython annotations CFG assert

* Match CPython inverted op assert

* Match CPython many-locals guard

* Reject deopt opcodes in CFG stack effects

* Match CPython invalid stack effect error

* Test CPython deopt stack effect guard

* Match CPython load-fast extended-arg assert

* Match CPython instruction allocation asserts

* Match CPython basicblock last-instr asserts

* Match CPython opcode range asserts

* Assert CPython fallthrough line propagation invariant

* Assert CPython CFG target offset sign

* Assert CPython exception fallthrough invariant

* Assert CPython exception stack bounds

* Assert CPython traversal stack allocation

* Match CPython label-map allocation in shadow

* Mirror CPython label-map sentinel fill

* Match CPython CFG builder allocation asserts

* Match CPython exception stack structure

* Match CPython ref stack structure

* Match CPython CFG traversal stack structure

* Mirror CPython CFG traversal stack pointer

* Use CPython fixed exception handler stack

* Mirror CPython ref stack capacity field

* Match CPython swap optimizer scratch stack

* Align static swap helpers with CPython blocks

* Align swaptimize signature with CPython

* Match CPython redundant pair pass result

* Match CPython inline pass result

* Match CPython redundant NOP pass results

* Fix bytecode metadata after upstream rebase

* Match CPython opcode stack metadata

* Add CPython identifiers to cspell dictionary

Add CNOTAB, LNOTAB, ialloc, ioffset, iused, nblocks, ncellsused,
ncellvars, nextop, noffsets, nvars, swaptimize, untargeted to
.cspell.dict/cpython.txt for the new CFG/assembler code in
crates/codegen/src/ir.rs.

* Fix CI failures from bytecode-parity work

- clippy: drop redundant `test_` prefix on three test functions and
  remove an unnecessary `u32` cast in basicblock_clear_reuses_cpython_spare_slots_in_offset_order
- insta: regenerate nested_double_async_with snapshot to match the new
  CFG output that drops unreferenced labels after the redundant-NOP pass
- regrtest: drop `@expectedFailure` markers from test_func_args,
  test_meth_args (test_compile), test_disassemble_with,
  test_disassemble_try_finally (test_dis), and test_except_star
  (test_monitoring) which now pass

* Resync generated opcode metadata

Empty conf.toml since WithExceptStart and Setup{Cleanup,Finally,With}
stack effects already match CPython, so the TODO override entries are
stale and only cause CI hook diffs.

Regenerate opcode_metadata.rs and drop the matching SetupCleanup/
SetupFinally/SetupWith assertions on PseudoOpcode::has_arg(); their
`HAS_ARG` flag comes from pseudo definitions in bytecodes.c that the
upstream analyzer does not propagate through PseudoInstruction.properties,
so the generated has_arg() excludes them. has_target() still covers
these block-push pseudos via is_block_push().

* Drop is_block_push has_arg invariant

The CPython invariant `assert(OPCODE_HAS_ARG(op) || !IS_BLOCK_PUSH(op))`
relies on SETUP_{FINALLY,CLEANUP,WITH} carrying `HAS_ARG_FLAG` in
CPython's metadata. The autogen tool reads pseudo-opcode properties from
target instructions and does not propagate the pseudo's own
HAS_ARG flag, so PseudoOpcode::has_arg() omits these three opcodes.
Drop the debug_assert that fired inside py_freeze proc-macro expansion.

* Auto-generate has_eval_break and route AnyInstruction has_arg/has_const via macro

Add fn_has_eval_break to generate_rs_opcode_metadata.py using CPython's
Properties.eval_breaker, removing the hand-written matches! body for
Opcode::has_eval_break and PseudoOpcode::has_eval_break.

Forward has_arg/has_const from Instruction and PseudoInstruction to
their opcode, so AnyInstruction can use either_real_pseudo! like the
other has_* accessors instead of an open-coded match.
2026-05-28 09:19:11 +09:00
Bas Schoenmaeckers
ca412fce5d Add support for creating functions with the c-api (#7984) 2026-05-27 16:46:46 +09:00
Shahar Naveh
f95b7468f7 Autogen opcodes metadata (#7983) 2026-05-27 16:44:58 +09:00
Chanho Lee
1cb24c5ebb Reject non-ASCII digits in JSON numbers (#7982) 2026-05-27 16:40:52 +09:00
Jiseok CHOI
ce79cd4853 sqlite3: fix Blob.__setitem__ value range validation (#7981)
* sqlite3: fix Blob.__setitem__ value range validation

Previously, assigning an out-of-range integer (negative or > 255) or an
integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError
instead of ValueError.

Mirror CPython's ass_subscript_index logic:
- Convert the value via to_i64(), treating any overflow as -1
- Validate the result is in [0, 255], raising ValueError("byte must be in range(0, 256)") otherwise
- Separate deletion error messages: "item deletion" for index, "slice deletion" for slice

* sqlite3: fix Blob.__setitem__ negative-step slice write

In the step != 1 branch of Blob.ass_subscript, the loop used
  i_in_temp += step as usize
where step is isize. For negative steps (e.g. step = -2),
  (-2isize) as usize = 18446744073709551614
causing an out-of-bounds panic whenever slice_len >= 2.

Fix: use SaturatedSliceIter (already used by the read path) to iterate
over the correct absolute blob indices, then map each index back to a
temp buffer offset via abs_idx - range_start.

Also fix a Clippy lint: replace
  val < 0 || val > 255
with the idiomatic
  !(0..=255).contains(&val)

Add a regression test in extra_tests/snippets/stdlib_sqlite.py that
exercises blob[9:0:-2] (negative step, slice_len=5).

* fix: guard blob negative-step snippet from CPython 3.11 bug

* style: add blank line after import sys in stdlib_sqlite snippet (ruff)

* Update extra_tests/snippets/stdlib_sqlite.py

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2026-05-27 16:40:05 +09:00
Bas Schoenmaeckers
dcb273ba68 Add capsule support to c-api (#7940) 2026-05-26 23:12:54 +09:00
Bas Schoenmaeckers
dd8d250ba3 Add list support to c-api (#7944)
* Add list support to c-api

* Review

* Fix Insert clamping
2026-05-26 23:12:01 +09:00
Shahar Naveh
3db172c025 Update ensurepip to 3.14.5 (#7860) 2026-05-26 23:11:43 +09:00
dependabot[bot]
fb531ecce3 Bump cranelift in the wasmtime group across 1 directory (#7980)
Bumps the wasmtime group with 1 update in the / directory: [cranelift](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift` from 0.131.1 to 0.131.2
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.131.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-26 10:37:02 +09:00
Shahar Naveh
9701c46d86 Clippy rules (test related) (#7968) 2026-05-25 22:03:18 +09:00
James Clarke
021c78655e docs: expand AGENTS.md with test marker guidance and CI audit notes (#7963)
* docs: expand AGENTS.md with test marker guidance and CI audit notes

Document the four-way test marker decision (expectedFailure /
expectedFailureIf vs skip / skipIf, with skip reserved for tests that
crash the interpreter), add guidance on avoiding zizmor's
impostor-commit audit when pinning third-party actions, link the wiki
guide for syncing tests from upstream CPython, and note the grep recipe
for finding WIP TODO: RUSTPYTHON entries.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs: add pre-commit checks rule, trim CI section per review

Add a "CRITICAL: Pre-commit Checks" subsection requiring prek and the
full test suite to pass before any commit. Shrink the CI Workflows
section to a single sentence per @ShaharNaveh's review feedback:
contributors only need to know that workflow changes must pass a zizmor
scan in CI, not the full impostor-commit explainer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs: warn against doc comments on pyattr/pyclass/pyfunction items

- Note that rustpython-doc supplies CPython docstrings via the derive macros
- Flag that `///` comments override that source and are dropped on `#[pyattr]`

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 22:02:22 +09:00
dependabot[bot]
411230a46c Bump j178/prek-action from 2.0.3 to 2.0.4 (#7973)
Bumps [j178/prek-action](https://github.com/j178/prek-action) from 2.0.3 to 2.0.4.
- [Release notes](https://github.com/j178/prek-action/releases)
- [Commits](6ad8027733...bdca6f102f)

---
updated-dependencies:
- dependency-name: j178/prek-action
  dependency-version: 2.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-25 21:20:30 +09:00
Shahar Naveh
b69644196a Upgrade pkcs8 to 0.11 (#7977) 2026-05-25 21:20:13 +09:00
dependabot[bot]
a6fee92683 Bump the wasmtime group across 1 directory with 2 updates (#7975)
Bumps the wasmtime group with 1 update in the / directory: [cranelift-jit](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift-jit` from 0.131.1 to 0.131.2
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-module` from 0.131.1 to 0.131.2
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift-jit
  dependency-version: 0.131.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
- dependency-name: cranelift-module
  dependency-version: 0.131.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-25 18:40:48 +09:00
dependabot[bot]
f4696ea890 Bump peaceiris/actions-gh-pages from 4.0.0 to 4.1.0 (#7972)
Bumps [peaceiris/actions-gh-pages](https://github.com/peaceiris/actions-gh-pages) from 4.0.0 to 4.1.0.
- [Release notes](https://github.com/peaceiris/actions-gh-pages/releases)
- [Changelog](https://github.com/peaceiris/actions-gh-pages/blob/main/CHANGELOG.md)
- [Commits](4f9cc6602d...84c30a85c1)

---
updated-dependencies:
- dependency-name: peaceiris/actions-gh-pages
  dependency-version: 4.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-25 18:40:33 +09:00
dependabot[bot]
0237a1d520 Bump taiki-e/install-action from 2.77.6 to 2.79.1 (#7971)
Bumps [taiki-e/install-action](https://github.com/taiki-e/install-action) from 2.77.6 to 2.79.1.
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](c070f87102...b550161ef8)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.79.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-25 18:40:17 +09:00
dependabot[bot]
6bbe24a725 Bump zizmorcore/zizmor-action from 0.5.3 to 0.5.6 (#7970)
Bumps [zizmorcore/zizmor-action](https://github.com/zizmorcore/zizmor-action) from 0.5.3 to 0.5.6.
- [Release notes](https://github.com/zizmorcore/zizmor-action/releases)
- [Commits](b1d7e1fb5d...5f14fd08f7)

---
updated-dependencies:
- dependency-name: zizmorcore/zizmor-action
  dependency-version: 0.5.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-25 18:40:02 +09:00
dependabot[bot]
f9e4988cf5 Bump github/gh-aw from 0.73.0 to 0.74.4 (#7969)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.73.0 to 0.74.4.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](4d44d0e898...2c1a237d20)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.74.4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-25 18:39:43 +09:00
James Clarke
a5775e0c07 Fix thread teardown panic when weakref callback fires during cleanup (#7965) 2026-05-25 13:55:32 +09:00
fanninpm
bc3d00e879 Replace ahash with rapidhash (#7954)
* Add `rapidhash` to list of dependencies

* Use `rapidhash::quality::RandomState` in `codegen` crate

* Use `rapidhash::quality::RandomState` in `stdlib` crate

* Use `rapidhash::quality::RandomState` in `vm` crate

* Remove `ahash` from lists of dependencies
2026-05-25 13:53:54 +09:00
Shahar Naveh
52305c0c72 Skip flaky test (#7967) 2026-05-24 20:00:32 +09:00
Shahar Naveh
7011942e4e Add builtin.PythonFinalizationError (#7966)
* Add PythonFinalizationError to builtins

* Patch failing tests (unrelated)

* Unmark passing test

* Update `exception_hierarchy.txt` to 3.14.5
2026-05-24 19:58:16 +09:00
dependabot[bot]
438925401f Bump qs and express in /wasm/demo (#7959)
Bumps [qs](https://github.com/ljharb/qs) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.

Updates `qs` from 6.14.2 to 6.15.2
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.14.2...v6.15.2)

Updates `express` from 4.22.1 to 4.22.2
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/v4.22.2/History.md)
- [Commits](https://github.com/expressjs/express/compare/v4.22.1...v4.22.2)

---
updated-dependencies:
- dependency-name: express
  dependency-version: 4.22.2
  dependency-type: indirect
- dependency-name: qs
  dependency-version: 6.15.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-24 19:57:20 +09:00
Shahar Naveh
2fabf38d8f Impl sys.audithook (#7960)
* Update tests

* Add basic audit support

* Add audit for `time.sleep`

* Add some for `socket`

* Some syslog

* Some sys related audits

* some marshal

* monitoring callback

* Mark failing tests

* clippy

* Clippy

* clippy

* mark failing test

* mark more

* Update `test_sys_setprofile.py` to 3.14.5

* Mark failing tests
2026-05-24 19:56:35 +09:00
Shahar Naveh
d7d936575c General code nitpicks (#7955) 2026-05-24 19:55:22 +09:00
Jeong, YunWon
b5ff41c219 Align marshal and .pyc with CPython 3.14 (#7958)
* Share marshal ref table between code object and its internals

read_marshal_bytes, _str, _str_vec, _name_tuple, and _const_tuple now
take a shared ref table and resolve TYPE_REF / register FLAG_REF
entries. deserialize_code is split into a public wrapper and an inner
function that receives the ref table; deserialize_value_depth opens a
fresh inner ref space when it hits Type::Code, mirroring CPython's
behaviour of putting the code object itself at ref slot 0. Nested code
objects inside const tuples reuse the surrounding code's ref space via
the new read_const_value helper.

* Align PYC magic number, FORMAT_VERSION, and header check with CPython 3.14

PYC_MAGIC_NUMBER changes from 2994 to 3627, matching CPython 3.14's
pyc_magic_number_token (0x0a0d0e2b). marshal FORMAT_VERSION drops from
5 to 4 (the encoder/marshal.version value; the decoder already accepts
both). check_pyc_magic_number_bytes now compares all four magic bytes
instead of the first two.

* Add CPython 3.14 .pyc decoding regression tests

Two fixture-based tests pin the marshal decoder against actual CPython
3.14 marshal.dumps() output: a trivial module that exercises FLAG_REF
plus TYPE_REF for qualname, and a module with a nested function that
exercises ref sharing between a const tuple and its surrounding code
object.

* Accept CPython-tagged .pyc as read-only bytecode source

SourceFileLoader.get_code now also looks for .pyc files using
_RP_FALLBACK_CACHE_TAGS (currently ('cpython-314',)) in addition to
sys.implementation.cache_tag. The matched .pyc is only used for
reading; recompilation still writes to the RustPython-tagged path, so
CPython's .pyc is never overwritten. Source-stat / hash / timestamp
validation logic is unchanged.

* Apply rustfmt to marshal helpers

* Marshal PySlice from format version 4 instead of 5

CPython's marshal supports TYPE_SLICE from format version 4 onwards
and that is the default version. Rejecting slice dumps below version
5 made marshal.dumps(slice(...)) fail with the default version and
broke test.test_marshal.SliceTestCase.test_slice.

* Revert "Accept CPython-tagged .pyc as read-only bytecode source"

Lib/importlib/_bootstrap_external.py is CPython's own code copied
verbatim; local patches here defeat compatibility tracking. The
cpython-XX cache_tag fallback needs to live on the RustPython side
(Rust code or sys.implementation.cache_tag policy), not as edits to
the imported standard library.

This reverts commit 1fc426d0fb5fcdb50d35cad13bbb43e8f6ce1c7f.

* Format sys.implementation.cache_tag as cpython-{MAJOR}{MINOR}

Use the CPython compatibility version (e.g. cpython-314) instead of
the rustpython-{MAJOR_IMPL}_{MINOR_IMPL} interpreter version string.

* Set marshal FORMAT_VERSION to 5 to match CPython 3.14.5

Py_MARSHAL_VERSION is 5 in CPython 3.14.5 (Include/marshal.h:16) and
TYPE_SLICE serialization rejects version < 5 (Python/marshal.c:720).
Restore the same threshold and constant so marshal.version and the
slice-marshal gate match CPython.

* Thread marshal recursion depth through nested code objects

Code objects embedded in const-tuples reset the depth budget on each
recursion, so a hostile or pathological marshal stream of code-in-tuple-
in-code can blow the stack despite MAX_MARSHAL_STACK_DEPTH. Pass the
current depth through deserialize_code_inner and read_marshal_const_tuple
and decrement at each code-object/tuple boundary.

Also route dict keys through deserialize_value_after_header so TYPE_CODE
keys decode instead of failing with BadType.
2026-05-24 19:30:42 +09:00
Shahar Naveh
e1d9a1123e Skip flaky tests (#7961) 2026-05-24 13:48:00 +09:00
Ivan Mironov
b9efe10537 Add missing test for select.select() (#7953)
This is a follow up for https://github.com/RustPython/RustPython/pull/7948
2026-05-24 13:43:56 +09:00
Jeong, YunWon
d3272e752b Align codegen metadata with CPython (#7952) 2026-05-23 20:16:03 +09:00
Shahar Naveh
f3b83efcee Update test_structseq.py to 3.14.5 (#7951) 2026-05-22 20:11:57 +09:00
Shahar Naveh
1a013930a7 Update test_timeout.py to 3.14.5 (#7950) 2026-05-22 20:11:27 +09:00
Shahar Naveh
c513b923df Update test_socketserver.py to 3.14.5 (#7949) 2026-05-22 20:10:49 +09:00
Ivan Mironov
cf3b6397b2 Fix panic in select.select() when too many FDs specified (#7948)
Also:

* Add regression test into existing `extra_tests/snippets/stdlib_select.py`
* Stop calculating nfds on Windows as it is ignored there

Panic:

	thread 'main' (189598) panicked at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.186/src/unix/linux_like/mod.rs:1777:9:
	index out of bounds: the len is 16 but the index is 16
	note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

	thread 'main' (189598) panicked at library/core/src/panicking.rs:225:5:
	panic in a function that cannot unwind
	stack backtrace:
	   0:     0xaaab763a0b88 - <<std[1934960bf7f41d0a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[f1abae5f1257fe69]::fmt::Display>::fmt
	   1:     0xaaab75590ff0 - core[f1abae5f1257fe69]::fmt::write
	   2:     0xaaab763a94fc - <std[1934960bf7f41d0a]::sys::stdio::unix::Stderr as std[1934960bf7f41d0a]::io::Write>::write_fmt
	   3:     0xaaab7638b714 - std[1934960bf7f41d0a]::panicking::default_hook::{closure#0}
	   4:     0xaaab7639b288 - std[1934960bf7f41d0a]::panicking::default_hook
	   5:     0xaaab7639b478 - std[1934960bf7f41d0a]::panicking::panic_with_hook
	   6:     0xaaab7638b7ec - std[1934960bf7f41d0a]::panicking::panic_handler::{closure#0}
	   7:     0xaaab76382654 - std[1934960bf7f41d0a]::sys::backtrace::__rust_end_short_backtrace::<std[1934960bf7f41d0a]::panicking::panic_handler::{closure#0}, !>
	   8:     0xaaab7638c504 - __rustc[b7425922bef61dcf]::rust_begin_unwind
	   9:     0xaaab754f778c - core[f1abae5f1257fe69]::panicking::panic_nounwind_fmt
	  10:     0xaaab754f7714 - core[f1abae5f1257fe69]::panicking::panic_nounwind
	  11:     0xaaab754f786c - core[f1abae5f1257fe69]::panicking::panic_cannot_unwind
	  12:     0xaaab75a6283c - rustpython_vm::function::builtin::<impl rustpython_vm::function::builtin::sealed::PyNativeFnInternal<(rustpython_vm::function::builtin::OwnedParam<T1>,rustpython_vm::function::builtin::OwnedParam<T2>,rustpython_vm::function::builtin::OwnedParam<T3>,rustpython_vm::function::builtin::OwnedParam<T4>),R,rustpython_vm::vm::VirtualMachine> for F>::call_::h2471c8e242c9b51d
	  13:     0xaaab75db1e68 - rustpython_vm::types::slot::Callable::slot_call::hd1c1ad0ad14f306b
	  14:     0xaaab762c0a50 - rustpython_vm::protocol::callable::PyCallable::invoke::h9f6d571fca351ca6
	  15:     0xaaab75c550e8 - rustpython_vm::protocol::callable::<impl rustpython_vm::object::core::PyObject>::call_with_args::hed1f4a61aba2dced
	  16:     0xaaab762e7c24 - rustpython_vm::frame::ExecutingFrame::execute_call::h0ad3490dd74ed1e3
	  17:     0xaaab762fed40 - rustpython_vm::frame::ExecutingFrame::run::hcf90f0950fc26812
	  18:     0xaaab761e6768 - rustpython_vm::vm::VirtualMachine::with_frame::hd49ba6fcdf2422e2
	  19:     0xaaab75c45398 - rustpython_vm::builtins::function::<impl rustpython_vm::object::core::Py<rustpython_vm::builtins::function::PyFunction>>::invoke_with_locals::h42de3d2316941ce2
	  20:     0xaaab76132a80 - rustpython_vm::builtins::function::vectorcall_function::h7331cb67b334e867
	  21:     0xaaab763369d8 - rustpython_vm::protocol::callable::<impl rustpython_vm::object::core::PyObject>::vectorcall::h9019c5d16685c89a
	  22:     0xaaab762f4b54 - rustpython_vm::frame::ExecutingFrame::execute_call_vectorcall::h120134e11a58c946
	  23:     0xaaab76302a7c - rustpython_vm::frame::ExecutingFrame::run::hcf90f0950fc26812
	  24:     0xaaab761e6768 - rustpython_vm::vm::VirtualMachine::with_frame::hd49ba6fcdf2422e2
	  25:     0xaaab761e7f24 - rustpython_vm::vm::VirtualMachine::run_code_obj::h354618be6e5cc553
	  26:     0xaaab761e2d18 - rustpython_vm::vm::python_run::file_run::<impl rustpython_vm::vm::VirtualMachine>::run_any_file::h783d3127fbc0b523
	  27:     0xaaab757d700c - rustpython::run_rustpython::h354efb8d817cefbf
	  28:     0xaaab757c79e0 - std::thread::local::LocalKey<T>::with::hc9728e249843a926
	  29:     0xaaab757db860 - rustpython_vm::vm::interpreter::Interpreter::run::h42ac1fe9ed2287a2
	  30:     0xaaab757d7b30 - rustpython::run::hf14a209db5b4289c
	  31:     0xaaab757e2eb4 - rustpython::main::h1b59d8e13276ac48
	  32:     0xaaab757e2eec - std::sys::backtrace::__rust_begin_short_backtrace::h47e4b1f073f2155c
	  33:     0xaaab757e2ed4 - std::rt::lang_start::{{closure}}::h663a6c3dc7d80101
	  34:     0xaaab76399fd4 - std[1934960bf7f41d0a]::rt::lang_start_internal
	  35:     0xaaab757e2f44 - main
	  36:     0xfffed057655c - __libc_start_call_main
	  37:     0xfffed057663c - __libc_start_main@@GLIBC_2.34
	  38:     0xaaab755526f0 - _start
	  39:                0x0 - <unknown>
	thread caused non-unwinding panic. aborting.
	Aborted                    (core dumped) cargo run --release -- extra_tests/snippets/stdlib_select.py
2026-05-22 20:10:24 +09:00
Ivan Mironov
2a163609cd Rustls integration improvements (#7946)
* Do not call `import socket` on each send()/recv() when using rustls

Use method references cached during socket creation.

* Implement reading of at most one TLS record from socket

Previous algorithm didn't take into account that recv() may return less
data than requested even for blocking sockets.

* Remove special handling of rustls "buffer full" errors

First of all, existing code does not really work and this leads to an
infinite loop: https://github.com/RustPython/RustPython/issues/7891

Second, this should never happen when rustls used properly (wrt
wants_read() and wants_write()) and thus all such errors are
implementation bugs that must be properly fixed.

* Replace own TlsConnection with rustls::Connection

* Fix waiting on a socket

1) Ensure that socket_wait() called from TLS glue code allows threads
2) Ensure that socket_wait() called from TLS glue code properly handles
   EINTR on *nix
3) Ensure that select() or poll() error conditions are checked
4) Use poll() on *nix so socket descriptor values are not limited

* Remove dead code from rustls glue

* Do not present rustls errors as OSError(0, "Success")

* Remove infinite loop "detection" from rustls glue

TLS handshake cannot be infinite. Any infinite loop here is a serious
bug in implementation and should be fixed properly.

This code triggers in some cases (very short reads) with misleading
`ssl_error.SSLWantReadError: The operation did not complete (read)`.

* Add test for 1-byte max recv in TLS client

* Add regression test for https://github.com/RustPython/RustPython/issues/7891

* Fix constants in rustls glue code

* Deduplicate verify flags / record-size constants
* Larger "max encrypted TLS record length"
2026-05-22 20:04:15 +09:00
Bas Schoenmaeckers
4eb9534646 Add complex number support to c-api (#7945) 2026-05-22 20:00:46 +09:00
Bas Schoenmaeckers
ab5bc43359 Add float support to c-api (#7943) 2026-05-22 20:00:16 +09:00
Jeong, YunWon
06f73f2ae1 Align nested code object bytecode parity (#7942)
* Align nested code object bytecode parity

* Align CPython jump-back parity

* Align match guard block parity with CPython

* Align CPython block borrow parity

* Align CPython load-fast barrier parity

* Align CPython try-end label parity

* Align CPython try-except end label barriers

* Align more CPython bytecode edge cases

* Align bare except finally bytecode layout
2026-05-22 03:53:35 +09:00
Bas Schoenmaeckers
c845861c4f Add bool support to c-api (#7938) 2026-05-21 09:59:40 +09:00
Bas Schoenmaeckers
a136f9047b Add basic dict function to c-api (#7929)
* Add basic dict function to c-api

* Fix iter

* Do not use mapping protocol
2026-05-21 09:59:09 +09:00
Jeong, YunWon
948924a14b Align cleanup bytecode layout with CPython (#7935)
* Align cleanup bytecode layout with CPython

* Align bytecode anchors with CPython

* Fix bytecode CFG review regressions
2026-05-21 08:11:00 +09:00
Bas Schoenmaeckers
ae6c16093e Add call functions to c-api (#7937)
* Add call functions to c-api

* Review

* Move conversion impl to c-api
2026-05-21 00:22:55 +09:00
dependabot[bot]
a6f13b98fb Bump openssl from 0.10.79 to 0.10.80 (#7931)
Bumps [openssl](https://github.com/rust-openssl/rust-openssl) from 0.10.79 to 0.10.80.
- [Release notes](https://github.com/rust-openssl/rust-openssl/releases)
- [Commits](https://github.com/rust-openssl/rust-openssl/compare/openssl-v0.10.79...openssl-v0.10.80)

---
updated-dependencies:
- dependency-name: openssl
  dependency-version: 0.10.80
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-20 23:10:08 +09:00
Shahar Naveh
4daa526dc1 Update tzinfo to 3.14.5 (#7934)
* Update `tzinfo` to 3.14.5

* Mark failing tests
2026-05-20 23:09:50 +09:00
Shahar Naveh
d073964aaa Remove unused binaries (#7936) 2026-05-20 22:21:04 +09:00
Shahar Naveh
ee006af13e Align more error messages with CPython 3.14.5 (#7933)
* Align more error messages with CPython 3.14.5

* Align patches for `test_eof.py`

* Unmark passing test

* Fix more
2026-05-20 22:20:13 +09:00
Bas Schoenmaeckers
de06fc0923 Add eval function to c-api (#7927)
* Add eval function to c-api

* Extract `Py_CompileString` start values into constants
2026-05-20 22:18:06 +09:00
Jeong, YunWon
ae3804fb21 more hostenv isolation (#7886)
* Convert host_env Windows path/argv params from raw *const u16 to &WideCStr

* Migrate remaining winapi raw u16 pointer signatures to typed references

* Migrate winreg pub unsafe fn string parameters to typed references

* Add ToPyException impls for host_env error types (PyPy wrap_oserror analog)

* Add CheckLibcResult helper and apply to socket/fcntl/shm/posix_wasi

* Add Win32 BOOL/HANDLE check helpers; apply check helpers across host_env

* Apply Win32/libc check helpers to overlapped/testconsole/os.rs

* Apply Win32 check helpers to winapi.rs (partial)

* Apply Win32 check helpers across more winapi.rs functions

* Apply Win32 check helpers to nt.rs (partial)

* Add CheckWin32Sentinel helper; apply to nt.rs INVALID_HANDLE_VALUE/INVALID_FILE_ATTRIBUTES patterns

* Add OwnedHandle / HandleToOwned helper; apply to mmap create_named_mapping leak path

* Use OwnedHandle RAII in nt::pipe to eliminate manual cleanup on error path

* Use OwnedHandle in nt::chmod_follow; hoist HandleToOwned import

* Drop rustix dependency from vm crate

Remove unused IntoPyException impl for rustix::io::Errno and the
rustix entry in crates/vm/Cargo.toml. rustix is now only depended on
by host_env.

* Fix CI failures: cross-platform regressions

- winapi.rs: pass None to create_event_w; the recent Option<&WideCStr>
  migration left one call site still passing a raw null pointer.
- exceptions.rs: gate ToPyException for LockfError with
  cfg(any(unix, target_os = "wasi")), matching host_env::fcntl's own
  cfg. The previous cfg let it compile on wasm32-unknown-unknown where
  host_env::fcntl does not exist.
- io_unsupported.rs: derive Eq on FileMode alongside PartialEq to
  satisfy clippy::derive_partial_eq_without_eq.

* Fix CI failures: cfg gates and unused imports

- exceptions.rs: gate ToPyException for LockfError with
  cfg(all(unix, not(target_os = "redox"))) to match the type's own
  cfg in host_env/src/fcntl.rs (LockfError is not built on wasi).
- signal.rs: CheckLibcResult is only used in unix-gated functions;
  split import so it is not pulled in for windows.
- mmap.rs: remove CheckWin32Handle from imports; no longer used after
  switching to HandleToOwned-based RAII.
- overlapped.rs: remove INVALID_HANDLE_VALUE from connect_pipe import;
  the call now uses .check_valid().

* Fix CI failures: rustfmt and windows unused import

- signal.rs: reorder cfg-gated imports per rustfmt.
- socket.rs: gate ToPyException import to cfg(all(unix, not(target_os = "redox")));
  it is only used inside sendmsg which has the same gate, so it was unused
  on windows.

* Push remaining libc/extern callsites from vm into host_env

Add host_env wrappers and replace the corresponding vm call sites:
- host_env::errno::strerror_string for libc::strerror
- host_env::io::write_stderr_raw for libc::write(STDERR_FILENO,...)
- host_env::locale::localeconv_data reused from vm::format
- host_env::os::abort for the inline abort extern
- host_env::os::urandom wraps getrandom; getrandom moves from vm to host_env
- host_env::posix::lchmod for the macOS/BSD lchmod extern
- host_env::posix::fcopyfile for the macOS fcopyfile extern
- host_env::nt::wputenv for the Windows _wputenv extern

vm/format.rs's get_locale_info now uses host_env on both unix and windows
instead of the unix-only libc::localeconv path.

* Move time tz state and winsound FFI into host_env

- host_env::time::tz: wraps the libc tzset/timezone/daylight/tzname
  globals on non-msvc, non-wasm32 targets. vm::stdlib::time now reads
  these via the typed wrappers instead of declaring its own externs.
- host_env::winsound (windows): exposes PlaySoundW (via a typed
  PlaySoundSource enum), Beep, and MessageBeep. vm::stdlib::winsound
  drops its inline FFI block and routes through host_env.

* Migrate unsetenv to host_env::nt::wputenv; rustfmt

- vm::stdlib::os::unsetenv had a second _wputenv call site that still
  referenced the removed inline extern. Route it through
  host_env::nt::wputenv like putenv.
- rustfmt fixups in exceptions.rs (boolean chain layout) and the two
  winsound files.

* Address PR review comments

- host_env::winapi::create_process: assert that the command_line buffer
  is NUL-terminated and that the env block ends with a double-NUL,
  matching the Win32 CreateProcessW contract.
- stdlib::overlapped CreateEvent: replace WideCString::from_str_truncate
  with the fallible from_str(), so embedded NULs in the event name
  surface as ValueError instead of being silently truncated.
- vm::exceptions::ReadlinkError::NotSymbolicLink now maps to OSError
  (matches Win32 ERROR_NOT_A_REPARSE_POINT semantics) rather than
  ValueError.
- winreg::ConnectRegistry: route the non-zero return through the
  existing os_error_from_windows_code helper so the resulting exception
  carries the real winerror/message instead of a generic OSError.

* Fix CI failures and address review follow-ups

CI failures:
- rustfmt cleanup in exceptions.rs after the ReadlinkError change.
- vm/stdlib/os.rs: drop unused ToWideString import that the wputenv
  migration left behind.
- vm/stdlib/winsound.rs: replace explicit `&*buf` with `&buf` to
  satisfy clippy::explicit_auto_deref.
- Lib/test/test_format.py, Lib/test/test_types.py: drop the now-stale
  expectedFailureIfWindows decorators on the locale-format tests; the
  Windows path now reads real `localeconv` data via host_env so these
  tests pass.

Review follow-ups:
- host_env::winapi::create_process: switch the new buffer terminator
  checks from `assert!` to fallible validators returning
  `io::ErrorKind::InvalidInput`, so bad inputs stay recoverable at
  the API boundary.
- host_env::winsound::play_sound: reject `Memory(_)` together with
  `SND_ASYNC` (lifetime-unsafe) and `SND_MEMORY` without a
  `Memory(_)` source. Expand `PlaySoundError` into a variant enum.
- vm::stdlib::_winapi::CreateProcess: route the Win32 path/argv strings
  through `as_wtf8().to_wide_cstring()` like the rest of the Windows
  API surface; `expect_str()` could panic on Python strings containing
  lone surrogates.
2026-05-20 16:16:14 +09:00
Jeong, YunWon
d51069bc7f Align load-fast borrow barriers with CPython (#7930)
* Align load-fast borrow barriers with CPython

* Allow CPython ifexp compiler name in spellcheck

* Address load-fast passthrough review feedback

* Traverse empty load-fast passthrough predecessors

* Extract load-fast test helpers
2026-05-20 14:11:36 +09:00
Shahar Naveh
0063a6d18b Align more error messages with CPython 3.14.5 (#7928) 2026-05-20 08:59:59 +09:00
Bas Schoenmaeckers
cea21f953d Add more c-api error functions (#7915)
* Add more c-api error functions

* Return NULL when no cause is set
2026-05-20 08:58:45 +09:00
Jeong, YunWon
62b081b893 Resolve test_inspect bytecode parity gaps (#7926)
* Resolve test_inspect bytecode parity gaps

* Address code review feedback
2026-05-19 22:47:58 +09:00
Bas Schoenmaeckers
26f5bbf077 Add type name c-api functions (#7925) 2026-05-19 21:03:39 +09:00
dependabot[bot]
ccf1508a06 Bump webpack-dev-server from 5.2.1 to 5.2.4 in /wasm/demo (#7924)
Bumps [webpack-dev-server](https://github.com/webpack/webpack-dev-server) from 5.2.1 to 5.2.4.
- [Release notes](https://github.com/webpack/webpack-dev-server/releases)
- [Changelog](https://github.com/webpack/webpack-dev-server/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-dev-server/compare/v5.2.1...v5.2.4)

---
updated-dependencies:
- dependency-name: webpack-dev-server
  dependency-version: 5.2.4
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-19 21:03:14 +09:00
Joshua Megnauth
c5143aa82f Const eval all of version.rs (#7923)
`version.rs` essentially consists of constants that can be baked in at
compile time. I moved most of `version.rs` to `build.rs`. The constants
are passed via rustc's environment then stored in the binary.
2026-05-19 21:02:56 +09:00
Shahar Naveh
0a2461a704 Update test_grammar.py to 3.14.5 (#7913)
* Update `test_grammar.py` to 3.14.5

* Update `test_syntax.py` to 3.14.5
2026-05-19 20:59:00 +09:00
Bas Schoenmaeckers
276a0e6c42 Add tuple support to c-api (#7907) 2026-05-19 20:57:06 +09:00
Jeong, YunWon
d8dee81157 Bytecode parity (#7885)
* Align codegen CFG cleanup with CPython

* Align codegen bytecode with CPython 3.14

* Remove remove_jump_target_line_nops

The pass dropped a same-line NOP at the start of any jump-targeted block
whose body advanced to a later line, but CPython's basicblock_remove_redundant_nops
only consults the previous/next instruction inside the same block. The
extra pass deleted the else-body line trace anchor exercised by
test_nested_double_async_with.

Ignore test_conditional_break_finally_does_not_keep_break_cleanup_nop;
the break NOP lands in a separate block from the inlined finally body,
so same-line successor elision does not apply here.

* Keep except_handler blocks reachable in eliminate_unreachable_blocks

After convert_pseudo_ops lowers SETUP_FINALLY to a plain NOP, the only
remaining link from the try body to the except_handler block was the
per-instruction except_handler annotation. When earlier passes had
already removed every NOP that carried that annotation (e.g. an empty
try body with `pass`), the handler block became unreachable from the
entry block and its instructions were cleared, dropping the handler
entirely. Seed reachability with blocks already marked except_handler
so handler dispatch survives independent of the in-block annotation.

Also drop two expectedFailure markers in test_patma whose match-tracing
expectations now pass.

* Align bytecode CFG cleanup with CPython
2026-05-19 19:24:45 +09:00
Shahar Naveh
e8d7437d91 Update test_types.py to 3.14.5 (#7912) 2026-05-19 08:21:19 +00:00
dependabot[bot]
53941295a2 Bump taiki-e/install-action from 2.76.0 to 2.77.6 (#7919)
Bumps [taiki-e/install-action](https://github.com/taiki-e/install-action) from 2.76.0 to 2.77.6.
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](711e1c3275...c070f87102)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.77.6
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-19 13:36:00 +09:00
dependabot[bot]
1fe4485c10 Bump siphasher from 1.0.2 to 1.0.3 (#7922)
Bumps [siphasher](https://github.com/jedisct1/rust-siphash) from 1.0.2 to 1.0.3.
- [Commits](https://github.com/jedisct1/rust-siphash/compare/1.0.2...1.0.3)

---
updated-dependencies:
- dependency-name: siphasher
  dependency-version: 1.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-19 13:34:28 +09:00
dependabot[bot]
50f235aded Bump nix from 0.31.2 to 0.31.3 in the unix group across 1 directory (#7921)
Bumps the unix group with 1 update in the / directory: [nix](https://github.com/nix-rust/nix).


Updates `nix` from 0.31.2 to 0.31.3
- [Changelog](https://github.com/nix-rust/nix/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nix-rust/nix/compare/v0.31.2...v0.31.3)

---
updated-dependencies:
- dependency-name: nix
  dependency-version: 0.31.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: unix
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-19 13:34:16 +09:00
dependabot[bot]
b902ffdcf8 Bump github/gh-aw from 0.71.3 to 0.73.0 (#7918)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.71.3 to 0.73.0.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](2f2a6f572b...4d44d0e898)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.73.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-19 13:34:06 +09:00
dependabot[bot]
9c0557820b Bump cargo-bins/cargo-binstall from 1.19.0 to 1.19.1 (#7917)
Bumps [cargo-bins/cargo-binstall](https://github.com/cargo-bins/cargo-binstall) from 1.19.0 to 1.19.1.
- [Release notes](https://github.com/cargo-bins/cargo-binstall/releases)
- [Changelog](https://github.com/cargo-bins/cargo-binstall/blob/main/release-plz.toml)
- [Commits](4852a15cf0...aaa84a43ae)

---
updated-dependencies:
- dependency-name: cargo-bins/cargo-binstall
  dependency-version: 1.19.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-19 13:33:57 +09:00
Ivan Mironov
150b9103a8 Fix "tried to pop from empty stack" with BlockExpr and const (#7916)
* Add tests for Mode::BlockExpr and VirtualMachine::run_block_expr

test_block_expr_return_const() panics currently.

* Fix "tried to pop from empty stack" with BlockExpr and const

Constant expressions without side effects are optimized away unless in
an interactive mode[1]. This causes panic when last statement in a block
is a constant and Mode::BlockExpr is used as this constant value must be
returned to caller.

Example panic:

    ---- vm::python_run::tests::test_block_expr_return_const stdout ----
    [crates/vm/src/frame.rs:9653:9] self = ExecutingFrame {
        code: code: <code object <module> at ??? file "<embedded>", line 1>,
        stack_len: 0,
    }

    thread 'vm::python_run::tests::test_block_expr_return_const' (2640752) panicked at crates/vm/src/frame.rs:9410:18:
    tried to pop from empty stack
    stack backtrace:
       0: __rustc::rust_begin_unwind
                 at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/panicking.rs:689:5
       1: core::panicking::panic_fmt
                 at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/core/src/panicking.rs:80:14
       2: rustpython_vm::frame::ExecutingFrame::fatal
                 at ./src/frame.rs:9654:9
       3: rustpython_vm::frame::ExecutingFrame::pop_stackref_opt
                 at ./src/frame.rs:9410:18
       4: rustpython_vm::frame::ExecutingFrame::pop_stackref
                 at ./src/frame.rs:9420:18
       5: rustpython_vm::frame::ExecutingFrame::pop_value
                 at ./src/frame.rs:9435:14
       6: rustpython_vm::frame::ExecutingFrame::execute_instruction
                 at ./src/frame.rs:3391:34
       7: rustpython_vm::frame::ExecutingFrame::run
                 at ./src/frame.rs:1623:31
       8: rustpython_vm::frame::<impl rustpython_vm::object::core::Py<rustpython_vm::frame::Frame>>::run::{{closure}}
                 at ./src/frame.rs:1098:44
       9: rustpython_vm::frame::<impl rustpython_vm::object::core::Py<rustpython_vm::frame::Frame>>::with_exec
                 at ./src/frame.rs:1093:9
      10: rustpython_vm::frame::<impl rustpython_vm::object::core::Py<rustpython_vm::frame::Frame>>::run
                 at ./src/frame.rs:1098:14
      11: rustpython_vm::vm::VirtualMachine::run_frame::{{closure}}
                 at ./src/vm/mod.rs:1201:44
      12: rustpython_vm::vm::VirtualMachine::with_frame_impl::{{closure}}::{{closure}}
                 at ./src/vm/mod.rs:1610:60
      13: rustpython_vm::vm::VirtualMachine::dispatch_traced_frame
                 at ./src/vm/mod.rs:1689:22
      14: rustpython_vm::vm::VirtualMachine::with_frame_impl::{{closure}}
                 at ./src/vm/mod.rs:1610:22
      15: rustpython_vm::vm::VirtualMachine::with_recursion
                 at ./src/vm/mod.rs:1547:9
      16: rustpython_vm::vm::VirtualMachine::with_frame_impl
                 at ./src/vm/mod.rs:1572:14
      17: rustpython_vm::vm::VirtualMachine::with_frame
                 at ./src/vm/mod.rs:1555:14
      18: rustpython_vm::vm::VirtualMachine::run_frame
                 at ./src/vm/mod.rs:1201:20
      19: rustpython_vm::vm::VirtualMachine::run_code_obj
                 at ./src/vm/mod.rs:1120:14
      20: rustpython_vm::vm::python_run::<impl rustpython_vm::vm::VirtualMachine>::run_block_expr
                 at ./src/vm/python_run.rs:51:14
      21: rustpython_vm::vm::python_run::tests::test_block_expr_return_const::{{closure}}
                 at ./src/vm/python_run.rs:190:47
      22: rustpython_vm::vm::interpreter::Interpreter::enter::{{closure}}
                 at ./src/vm/interpreter.rs:366:39
      23: rustpython_vm::vm::thread::set_current_vm::{{closure}}
                 at ./src/vm/thread.rs:107:9
      24: std::thread::local::LocalKey<T>::try_with
                 at /home/im/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:513:12
      25: std::thread::local::LocalKey<T>::with
                 at /home/im/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:477:20
      26: rustpython_vm::vm::thread::set_current_vm
                 at ./src/vm/thread.rs:102:14
      27: rustpython_vm::vm::thread::enter_vm
                 at ./src/vm/thread.rs:132:5
      28: rustpython_vm::vm::interpreter::Interpreter::enter
                 at ./src/vm/interpreter.rs:366:9
      29: rustpython_vm::vm::python_run::tests::test_block_expr_return_const
                 at ./src/vm/python_run.rs:188:23
      30: rustpython_vm::vm::python_run::tests::test_block_expr_return_const::{{closure}}
                 at ./src/vm/python_run.rs:187:38
      31: core::ops::function::FnOnce::call_once
                 at /home/im/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
      32: <fn() -> core::result::Result<(), alloc::string::String> as core::ops::function::FnOnce<()>>::call_once
                 at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/core/src/ops/function.rs:250:5

[1] 883ce9d273/crates/codegen/src/compile.rs (L2990-L2997)
2026-05-19 13:33:46 +09:00
Shahar Naveh
48ad238349 Update some tests to 3.14.5 (#7909)
* Align patches for `test_class.py`

* Update more tests to 3.14.5

* Update `test_math`

* `test_hash.py`

* Update `test_grammar.py`

* Fix failing test

* Restore `test_grammar.py`
2026-05-19 13:31:33 +09:00
Shahar Naveh
67e66bdc75 code nits (#7908)
* Slight cleanup of super.rs

* frame.rs

* buffer.rs

* bool.rs
2026-05-19 13:31:21 +09:00
Joshua Megnauth
e16f1aa657 Use correct dirs crate; drop uname for rustix (#7906)
RustPython used an ancient, unmaintained version of the `dirs` crate.
This pulled in `winapi-rs` on Windows, which is an old crate that has
been deprecated in favor of `windows-rs`. `windows-rs` is maintained by
Microsoft. Bumping `dirs` to the latest version removes more `winapi-rs`
from Cargo.lock.

As for `uname`, `rustix` handles it safely so the additional crate isn't
needed.
2026-05-19 13:27:32 +09:00
Bas Schoenmaeckers
6e56d935cf Add integer c-api support (#7905)
* Add integer c-api support

* Fix `PyLong_AsUnsignedLongLong` return value

* Fix error message

* Add type check functions
2026-05-19 13:20:43 +09:00
Bas Schoenmaeckers
20cb8843e0 Add unicode & bytes c-api support (#7904)
* Add unicode & bytes c-api support

* Check for negative size
2026-05-19 13:20:19 +09:00
Shahar Naveh
a4579a98b2 Update NOP tests to 3.14.5 (#7902)
* Update `test_xxlimited.py` & `test_xxtestfuzz.py` to 3.14.5

* Add more NOP tests

* Remove `test_capi`

* Remove `test_cext`
2026-05-19 13:20:00 +09:00
Shahar Naveh
883ce9d273 Update test_xpickle.py to 3.14.5 (#7901) 2026-05-18 00:23:34 +09:00
Shahar Naveh
723766ef69 Don't skip passing ast tests (#7900) 2026-05-18 00:23:22 +09:00
Shahar Naveh
3ed8c91fef Update test/support to 3.14.5 (#7896)
* Update `test/support` to 3.14.5

* Adjuat test markers

* Add `test_set` to env polluting tests
2026-05-18 00:23:06 +09:00
Bas Schoenmaeckers
a1a87dc8ca Add macro for type check functions in c-api (#7871)
* Add macro for type check function in c-api

* Add `fn` to macro
2026-05-17 13:04:43 +00:00
Shahar Naveh
ea2a3d9d84 Build workspace cache (#7889) 2026-05-17 20:55:33 +09:00
Shahar Naveh
9c188b4da9 Update ctypes to 3.14.5 (#7899) 2026-05-17 20:54:56 +09:00
Joshua Megnauth
ab72b292bd rustix/windows-sys for page size; drop maplit (#7876)
The `page_size` crate is a simple libc wrapper for Unix and uses
`winapi-rs` for Windows. `windows-sys` and `windows-rs` are the modern
alternatives for the unmaintained `winapi-rs`. Both crates are
maintained by Microsoft - they're official. Getting the page size is a
simple call for both Unix and Windows.

Besides Unix and Windows, I also added the page size for wasm32 which
the `page_size` crate did not support. `wasm32`'s page size is a
constant that is defined by the spec, so I hard coded it without adding
additional dependencies.

Finally, I dropped `maplit` which is seven years old and only used in
one place. Calling `collect()` with a single item iterator is idiomatic
as well as better in this case because Rust can optimize it. `maplit`
called `HashMap::insert` which over allocates to amortize future allocs.
2026-05-17 20:47:13 +09:00
Shahar Naveh
f4f035013d Update test_rlcompleter.py to 3.14.5 (#7898) 2026-05-17 19:50:06 +09:00
Shahar Naveh
c77c56d99c Update venv to 3.14.5 (#7897) 2026-05-17 19:49:53 +09:00
Shahar Naveh
b432d4cbdc Update pickle.py to 3.14.5 (#7895)
* Update `pickle.py` to 3.14.5

* Update pickle deps with new file

* Mark failing tests
2026-05-17 19:49:42 +09:00
Shahar Naveh
5a5230a400 Update shutil.py & zipfile to 3.14.5 (#7894)
* Update `shutil.py` to 3.14.5

* Update `zipfile` to 3.14.5
2026-05-17 19:49:31 +09:00
Shahar Naveh
8c988711dd Update http to 3.14.5 (#7892)
* Update `http` to 3.14.5

* Restore cpu patch
2026-05-17 19:49:19 +09:00
Shahar Naveh
f2ef252724 Update random.py to 3.14.5 (#7890) 2026-05-17 19:49:09 +09:00
Bas Schoenmaeckers
3a56f37505 Add object protocol methods to c-api (#7882) 2026-05-17 19:38:31 +09:00
Shahar Naveh
4b9416a558 Update test_genexps.py & test_metaclass.py to 3.14.5 (#7884)
* Update `test_genexps.py` to 3.14.5

* Align `test_metaclass.py` with the new doctest checker
2026-05-17 01:59:03 +09:00
Shahar Naveh
2d8f8ab818 Move cargo doc to a seperate CI job (#7883) 2026-05-17 01:58:48 +09:00
Bas Schoenmaeckers
a364f86fd5 Add import support to c-api (#7881) 2026-05-17 01:57:47 +09:00
Shahar Naveh
7273d76cf2 Update email to 3.14.5 (#7880)
* Update `email` to 3.14.5

* Update `test_email`

* mark failing tests

* Remove ExtraAssertions
2026-05-17 01:57:05 +09:00
Shahar Naveh
54589bf255 Remove some #[allow(clippy::*)] (#7878)
* Remove some `#[allow(clippy::*)]`

* Fix after merge
2026-05-17 01:56:47 +09:00
dependabot[bot]
0871bc8a2d Bump taiki-e/install-action from 2.75.22 to 2.76.0 (#7838) 2026-05-16 20:00:39 +09:00
Shahar Naveh
f26016049d Update tarfile.py to 3.14.5 (#7879) 2026-05-16 19:41:22 +09:00
dependabot[bot]
451bdcc9da Bump qs and body-parser in /wasm/demo (#7877)
Bumps [qs](https://github.com/ljharb/qs) and [body-parser](https://github.com/expressjs/body-parser). These dependencies needed to be updated together.

Updates `qs` from 6.14.1 to 6.14.2
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.14.1...v6.14.2)

Updates `body-parser` from 1.20.3 to 1.20.5
- [Release notes](https://github.com/expressjs/body-parser/releases)
- [Changelog](https://github.com/expressjs/body-parser/blob/1.20.5/HISTORY.md)
- [Commits](https://github.com/expressjs/body-parser/compare/1.20.3...1.20.5)

---
updated-dependencies:
- dependency-name: qs
  dependency-version: 6.14.2
  dependency-type: indirect
- dependency-name: body-parser
  dependency-version: 1.20.5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-16 19:02:44 +09:00
Jeong, YunWon
8253253fc7 more hostenv impl (#7604) 2026-05-16 19:01:40 +09:00
Jeong, YunWon
56269f704a Bytecode parity - CFG reorders and LOAD_FAST_BORROW chain (#7870)
* Align LOAD_FAST_BORROW analysis with CPython chain shape

Three changes that bring optimize_load_fast_borrow closer to CPython's
optimize_load_fast in flowgraph.c:

* ir.rs: split mark_cold into the CPython-style two passes. Phase 1
  propagates "warm" from the entry block, phase 2 propagates "cold" from
  except_handler blocks. Blocks reached by neither phase keep cold=false
  and stay in their original b_next position, matching CPython's handling
  of empty placeholders left by remove_unreachable (e.g. the inner_end of
  a nested try/except whose incoming jumps were re-routed by optimize_cfg).

* ir.rs: in optimize_load_fast_borrow, push the fall-through successor
  only when the current block has a last instruction (is_some_and).
  Empty blocks now terminate fall-through propagation, matching the
  `term != NULL` check in optimize_load_fast.

* compile.rs: add switch_to_new_or_reuse_empty() helper and use it in
  compile_while. The helper reuses the current block when it is empty
  and unlinked, mirroring USE_LABEL absorption in
  cfg_builder_maybe_start_new_block. This stops a stray empty block
  from appearing between e.g. a try/except end_block and the following
  while loop header.

Four codegen tests that depended on the previous fall-through-through-
empty behavior are marked #[ignore] with TODO comments.

Also includes a handful of dictionary entries in .cspell.dict picked up
during the work.

* Interleave const fold passes per-block to match CPython

Mirror CPython's optimize_basic_block() (flowgraph.c) by walking each
block once in instruction order and trying tuple, list, set, unary, and
binop folding at each position before advancing. This replaces the
previous global-pass sequence where every fold_unary_constants pattern
in the whole CFG was registered before any tuple constant, leaving
negated literals like `-1` at co_consts positions earlier than CPython
produces (e.g. snippets.py: -1 at idx 280 vs CPython idx 726).

Changes:
- Extract `fold_unary_constant_at` and `fold_binop_constant_at` per-
  position helpers from the existing global passes; the global passes
  now call the helpers in a loop.
- Add `fold_constants_per_block` that walks each block to a fixed point,
  trying all five folds at each instruction position.
- Call the new walker before the legacy global passes in
  optimize_finalize so co_consts insertion order matches CPython's.

Measured on the full Lib tree: differing files 270 → 269; the only
newly matching file is `test/test_ast/snippets.py`, the case raised in
youknowone/RustPython#28.

* Inline small fast-return blocks only through unconditional jumps

`inline_small_fast_return_blocks` previously appended the target
`LOAD_FAST(_BORROW)/RETURN_VALUE` block's instructions onto any
predecessor whose fall-through eventually reached it, in addition to the
unconditional-jump case CPython handles in
`inline_small_or_no_lineno_blocks` (flowgraph.c:1210). CPython only
inlines through unconditional jumps, leaving fall-through predecessors
to reach the shared return block via the natural CFG layout. The extra
fall-through branch duplicated the return tail (e.g. `if/elif/return`
emitted two adjacent `LOAD_FAST_BORROW x; RETURN_VALUE` sequences).

Remove the fall-through inlining branch and keep only the
unconditional-jump path.

Measured on the full Lib tree: differing files 270 → 239 (-31), no new
regressions. Files newly matching include copy.py, argparse.py,
dataclasses.py, logging/__init__.py, pathlib/__init__.py, etc.

* Allow scope-exit/jump-back reorder within a shared except handler

`reorder_conditional_scope_exit_and_jump_back_blocks` previously skipped
any reorder where the conditional, scope-exit, or jump-back block had
an `except_handler` attached, even when all three shared the same
handler. CPython reorders these regardless of try/except context, as
long as the blocks stay within the same protected region. The over-
conservative guard left patterns like `try: for: if cond: return` with
the loop body's scope-exit ahead of the backedge, while CPython places
the backedge first and inverts the conditional.

Replace the `block_is_protected` triple-check with a single
`mismatched_protection` test: skip only when the three blocks do not
share the same `except_handler`. Same-handler reorders preserve the
protected range because every instruction's `except_handler` field
stays attached as `.next` pointers shift.

Measured on the full Lib tree: differing files 239 → 237; no new
regressions.

* Skip jump-over-cleanup reorder when target restarts an exception scope

reorder_jump_over_exception_cleanup_blocks was swapping a small
scope-exit target with a preceding cold cleanup chain even when the
target block began a fresh try (SETUP_FINALLY/SETUP_CLEANUP/SETUP_WITH).
The swap moved the next try's setup ahead of the prior handler's
cleanup_end/next_handler/cleanup_block, making the cleanup_body's
JUMP_FORWARD fall through directly to the cleanup_end and get elided as
redundant. The bytecode then lacked the JUMP_FORWARD that skips the
cleanup blocks and matched the prior handler's borrow tail incorrectly.

Skip the reorder when the target block contains any block-push pseudo
op so a new try's setup stays in source order. Re-enables the four
named/typed except-cleanup borrow tests that were marked #[ignore] in
commit 7481459ea.

* fix if block_idx == BlockIdx::NULL
2026-05-16 17:17:36 +09:00
Joshua Megnauth
078e23de27 Use icu4x for casefold() (#7780) 2026-05-16 12:59:49 +09:00
Shahar Naveh
ddfcb25957 Clippy nursery lints (#7875) 2026-05-15 10:38:36 +00:00
fanninpm
e467b67ef7 Move dependencies to workspace for compiler-core crate (#7874)
* Add dependency from `compiler-core` crate to workspace

* Declare dependency as workspace = true
2026-05-15 16:52:31 +09:00
Shahar Naveh
460b1d39ed Clippy warn uninlined_format_args & redundant_else (#7873) 2026-05-15 16:52:06 +09:00
Bas Schoenmaeckers
11e991fb95 Add basic pyobject c-api functions (#7872) 2026-05-14 13:13:41 +09:00
Joshua Megnauth
ef375bec26 Fix swapcase() (#7788)
The tests for swapcase() were failing for two reasons. The first is
'𐐧' casing which should be fixed with modern Unicode tables. The second
failure is due to CPython's sigma override, which I implemented in
PR #7717.
2026-05-13 23:21:45 +09:00
Bas Schoenmaeckers
4059a032a7 Add basic capi error support (#7787)
* Add basic capi error support

* Add missing symbols to make tests compile again

* Add `pyerrors` to dictionary

* Return exception in `Py_GetConstantBorrowed`

* Remove `allow(dead_code)`

* Fix windows

* Load stdlib when calling `Py_InitializeEx`

* Debug tests

* Revert "Load stdlib when calling `Py_InitializeEx`"

This reverts commit bccd38e981.

* Disable tests on windows for now

* Truncate `PyType_GetFlags` to be always 32 bits

* Add test for exception type checking

* Remove subclass type flags

* Use latest pyo3 to make test work on windows

* Revert "Use latest pyo3 to make test work on windows"

This reverts commit b2c2f6913f.

* `set_main_interpreter` -> `init_main_interpreter`
2026-05-13 23:19:58 +09:00
Shahar Naveh
e8711edd2d Clippy warn on unnecessary wraps (#7869) 2026-05-13 23:14:33 +09:00
Shahar Naveh
f8e0eeb579 Update webbrowser.py to 3.14.5 (#7868) 2026-05-13 19:53:31 +09:00
Shahar Naveh
32e6f8dd81 Update annotationlib.py to 3.14.5 (#7867) 2026-05-13 19:53:18 +09:00
Shahar Naveh
e36cd994e8 Update socket.py to 3.14.5 (#7866)
* Update `socket.py` to 3.14.5

* Don't have socket.sethostname on android

* Mark failing test
2026-05-13 19:52:56 +09:00
fanninpm
7ebffd063b Move dependencies to workspace for wasm crate (#7794)
* Add dependencies from `wasm` crate to workspace

* Declare dependencies as workspace = true
2026-05-13 03:12:22 +00:00
Shahar Naveh
5ef91c22de Unchecked code fixes (#7786)
* Clippy lints fixes

* Update crates/stdlib/src/tkinter.rs

Co-authored-by: fanninpm <27117322+fanninpm@users.noreply.github.com>

* Update crates/stdlib/src/openssl.rs

Co-authored-by: fanninpm <27117322+fanninpm@users.noreply.github.com>

* Update crates/stdlib/src/ssl/compat.rs

Co-authored-by: fanninpm <27117322+fanninpm@users.noreply.github.com>

* Update crates/stdlib/src/ssl/compat.rs

Co-authored-by: fanninpm <27117322+fanninpm@users.noreply.github.com>

* Revert "Update crates/stdlib/src/ssl/compat.rs"

This reverts commit b34228ff37.

---------

Co-authored-by: fanninpm <27117322+fanninpm@users.noreply.github.com>
2026-05-13 09:45:15 +09:00
Shahar Naveh
79395de9f3 Update test_xml_etree.py to 3.14.5 (#7855) 2026-05-12 22:19:57 +09:00
Jeong, YunWon
2b19ba79a8 Align bytecode CFG cleanup with CPython (#7781) 2026-05-12 22:14:24 +09:00
Shahar Naveh
9d77b25858 Add more pedantic clippy rules (#7830) 2026-05-12 20:57:37 +09:00
Shahar Naveh
d09179a7ee Code nits in contextvars.rs (#7835) 2026-05-12 20:57:07 +09:00
Shahar Naveh
8fe23b8a15 Update test_peepholer.py to 3.14.5 (#7864) 2026-05-12 20:56:36 +09:00
Shahar Naveh
ff05dae11c Update pydoc_data to 3.14.5 (#7863) 2026-05-12 20:54:51 +09:00
Shahar Naveh
1da29ff003 Update typing.py to 3.14.5 (#7862) 2026-05-12 20:54:36 +09:00
Shahar Naveh
a702e9ccc7 Update test_functools.py to 3.14.5 (#7861) 2026-05-12 20:54:18 +09:00
Shahar Naveh
9ee27526bc Update encodings to 3.14.5 (#7859) 2026-05-12 20:54:11 +09:00
Shahar Naveh
fb37b5ecc6 Update test_marshal.py to 3.14.5 (#7865)
* Update `test_marshal.py` to 3.14.5

* mark failing tests
2026-05-12 20:53:54 +09:00
Shahar Naveh
3bfa5ab8c0 Update dataclasses.py to 3.14.5 (#7857) 2026-05-12 20:53:35 +09:00
Shahar Naveh
a0632ae2c5 Update inspect.py to 3.14.5 (#7854) 2026-05-12 20:53:24 +09:00
Shahar Naveh
f3c2198ff0 Update timeit.py to 3.14.5 (#7852) 2026-05-12 20:53:11 +09:00
Shahar Naveh
2bcbe96e6d Update test_calendar.py to 3.14.5 (#7848) 2026-05-12 20:53:03 +09:00
Shahar Naveh
f5357692e8 Update test_type_comments.py to 3.14.5 (#7858) 2026-05-12 20:52:52 +09:00
Shahar Naveh
e0689bad7c Update urllib to 3.14.5 (#7856) 2026-05-12 20:52:36 +09:00
Shahar Naveh
1ac55db966 Update test_warnings to 3.14.5 (#7853) 2026-05-12 20:52:20 +09:00
Shahar Naveh
a7c9b98b5a Update test_fileinput.py to 3.14.5 (#7851) 2026-05-12 20:52:08 +09:00
Shahar Naveh
2bb7dd8cf9 Update smtplib.py to 3.14.5 (#7850) 2026-05-12 20:51:57 +09:00
Shahar Naveh
f6c382c595 Update runpy.py to 3.14.5 (#7849) 2026-05-12 20:51:46 +09:00
Shahar Naveh
72679af4b2 Update re related tests (#7847) 2026-05-12 20:51:33 +09:00
Shahar Naveh
27db8e5847 Update test_os.py to 3.14.5 (#7846)
* Update `test_os.py` to 3.14.5

* Mark failing test

* fix typo
2026-05-12 20:51:19 +09:00
Shahar Naveh
68be554684 Update pty.py to 3.14.5 (#7845) 2026-05-12 20:51:02 +09:00
Shahar Naveh
2e5077fe12 Update plistlib.py to 3.14.5 (#7844) 2026-05-12 20:49:48 +09:00
dependabot[bot]
673db1d71a Bump cargo-bins/cargo-binstall from 1.18.1 to 1.19.0 (#7837)
Bumps [cargo-bins/cargo-binstall](https://github.com/cargo-bins/cargo-binstall) from 1.18.1 to 1.19.0.
- [Release notes](https://github.com/cargo-bins/cargo-binstall/releases)
- [Changelog](https://github.com/cargo-bins/cargo-binstall/blob/main/release-plz.toml)
- [Commits](dc19f1e484...4852a15cf0)

---
updated-dependencies:
- dependency-name: cargo-bins/cargo-binstall
  dependency-version: 1.19.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-12 20:49:32 +09:00
dependabot[bot]
3cfb0fe7bc Bump j178/prek-action from 2.0.2 to 2.0.3 (#7839)
Bumps [j178/prek-action](https://github.com/j178/prek-action) from 2.0.2 to 2.0.3.
- [Release notes](https://github.com/j178/prek-action/releases)
- [Commits](cbc2f23eb5...6ad8027733)

---
updated-dependencies:
- dependency-name: j178/prek-action
  dependency-version: 2.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-12 20:49:09 +09:00
dependabot[bot]
9e066c4f50 Bump cranelift in the wasmtime group across 1 directory (#7842)
Bumps the wasmtime group with 1 update in the / directory: [cranelift](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift` from 0.131.0 to 0.131.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.131.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-12 20:48:57 +09:00
dependabot[bot]
3bce5566fa Bump github/gh-aw from 0.71.1 to 0.71.3 (#7841)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.71.1 to 0.71.3.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](f01a9d118a...2f2a6f572b)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.71.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-12 20:48:42 +09:00
dependabot[bot]
3b67d0f5d2 Bump libz-rs-sys from 0.5.5 to 0.6.0 (#7843)
Bumps [libz-rs-sys](https://github.com/trifectatechfoundation/zlib-rs) from 0.5.5 to 0.6.0.
- [Release notes](https://github.com/trifectatechfoundation/zlib-rs/releases)
- [Changelog](https://github.com/trifectatechfoundation/zlib-rs/blob/main/docs/release.md)
- [Commits](https://github.com/trifectatechfoundation/zlib-rs/compare/v0.5.5...v0.6.0)

---
updated-dependencies:
- dependency-name: libz-rs-sys
  dependency-version: 0.6.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-12 20:48:28 +09:00
Bas Schoenmaeckers
77070eb6ca Fix ctypes.py_object handling (#7836)
* Fix `ctypes.py_object` handling

* Assume owned pointer
2026-05-12 03:20:01 +09:00
Shahar Naveh
d6abdc4b79 Fixed: unused manifest key: dependencies.libz-sys.package (#7792)
* Fixed: `unused manifest key: dependencies.libz-sys.package`

* Use `libz-rs-sys` instead

* Adjust rust code
2026-05-12 00:54:44 +09:00
Shahar Naveh
fc00fc22d2 Code nits in csv.rs (#7834)
* Code nits in `csv.rs`

* clippy
2026-05-12 00:53:58 +09:00
Shahar Naveh
865e75dd99 Update configparser.py to 3.14.5 (#7833) 2026-05-12 00:53:36 +09:00
Shahar Naveh
9f019a5b86 Update argparse.py to 3.14.5 (#7832) 2026-05-12 00:53:22 +09:00
Shahar Naveh
ad6cc8f0a2 Update test_csv.py to 3.14.5 (#7831)
* Update `test_csv.py` to 3.14.5

* Mark failing test
2026-05-12 00:53:10 +09:00
Shahar Naveh
4a46e84eb9 Add map_unwrap_or clippy rule (#7829) 2026-05-12 00:51:23 +09:00
github-actions[bot]
949a620811 Update doc DB for CPython 3.14.5 (#7828)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-05-12 00:44:34 +09:00
Shahar Naveh
315865a6f7 Bump targeted CPython version to 3.14.5 (#7826) 2026-05-12 00:44:17 +09:00
Shahar Naveh
c79aefecee Update wsgiref.py to 3.14.4 (#7825) 2026-05-12 00:44:05 +09:00
Shahar Naveh
3fbfbf53c2 Update platform.py to 3.14.4 (#7824) 2026-05-12 00:43:49 +09:00
Shahar Naveh
3bd79e6b5b Update test_site.py to 3.14.4 (#7822) 2026-05-12 00:43:34 +09:00
Shahar Naveh
8e8b70fb33 Update sysconfig to 3.14.4 (#7821)
* Update `test_sysconfig.py` to 3.14.4

* Update `sysconfig` to 3.14.4
2026-05-12 00:43:18 +09:00
Shahar Naveh
29530049fe Update logging to 3.14.4 (#7820)
* Update `test_logging.py` to 3.14.4

* Update `logging` to 3.14.4  /
2026-05-12 00:42:54 +09:00
Shahar Naveh
5b0177d20a Update test_zipimport_support.py to 3.14.4 (#7819)
* Update `test_zipimport_support.py` to 3.14.4

* Add custom doctest checker
2026-05-12 00:42:39 +09:00
Shahar Naveh
479b2dc997 Update datetime related test files to 3.14.4 (#7817)
* Update datetime tests

* Add `test_strptime.py` from 3.14.4
2026-05-12 00:42:10 +09:00
Shahar Naveh
cb0cffbd7c Update test_contextlib_async.py to 3.14.4 (#7816) 2026-05-12 00:41:05 +09:00
Shahar Naveh
cc829b2756 Update test_contextlib.py to 3.14.4 (#7815) 2026-05-12 00:40:32 +09:00
Shahar Naveh
dfe99f647d Reapply patches to test_io.py (#7814) 2026-05-12 00:40:14 +09:00
Shahar Naveh
b3098c3058 Update ensurepip to 3.14.4 (#7811) 2026-05-12 00:39:37 +09:00
Shahar Naveh
8f19dff19d Update test_resource.py to 3.14.4 (#7808)
* Update `test_resource.py` to 3.14.4

* Mark failing tests

* Skip crashing macos test
2026-05-12 00:38:16 +09:00
Shahar Naveh
320355f633 Autogen instructions & opcodes (#7797) 2026-05-10 22:13:38 +09:00
Joshua Megnauth
108461f637 Fix title() and capitalize() (#7717)
* PyBytes.title should be ASCII-only.

* Use icu_casemap over unicode-casing for titles

`icu_casemap` is consistently maintained, official, and tracks the
latest Unicode versions. RustPython is also using other `icu4x` crates,
so using `icu_casemap` is more consistent.

As with islower and isupper, tracking the latest Unicode version is
important because character definitions shift over time which causes
discrepancies between RustPython and CPython.

This commit fixes title().

* Use icu_casemap for capitalize()

I dropped unicode-casing because it's cleaner to use icu4x for
everything. `icu4x` will also stay up to date whereas unicode-casing
will need to be periodically updated with new Unicode tables. Dropping
unicode-casing also removes some binary bloat due to the tables.

`capitalize()` mimics CPython behavior more closely now as well.
Notably, I implemented CPython's sigma edge case handler.

* Match CPython's title() exactly
2026-05-09 18:03:21 +00:00
fanninpm
bf7bb1bf3b Move dependencies to workspace for capi crate (#7795)
* Add dependency from `capi` crate to workspace

* Declare dependency as workspace = true

* Update Cargo.toml

Co-authored-by: Bas Schoenmaeckers <7943856+bschoenmaeckers@users.noreply.github.com>

---------

Co-authored-by: Shahar Naveh <50263213+ShaharNaveh@users.noreply.github.com>
Co-authored-by: Bas Schoenmaeckers <7943856+bschoenmaeckers@users.noreply.github.com>
2026-05-10 00:31:37 +09:00
Shahar Naveh
09c27bb440 Workaround for random windows cache failure (#7812) 2026-05-10 00:30:54 +09:00
Shahar Naveh
6dfc68b225 Update test_charmapcodec.py to 3.14.4 (#7810) 2026-05-10 00:30:26 +09:00
Shahar Naveh
17376ace28 Update test_global.py to 3.14.4 (#7809) 2026-05-10 00:29:46 +09:00
Shahar Naveh
9eacdfca48 Update test_userlist.py to 3.14.4 (#7807) 2026-05-10 00:29:27 +09:00
Shahar Naveh
68a0bc030b Update test_isinstance.py to 3.14.4 (#7806) 2026-05-10 00:29:05 +09:00
Shahar Naveh
edcf3002de Add test_finalization.py from 3.14.4 (#7805) 2026-05-10 00:28:50 +09:00
Shahar Naveh
67630ffbfe Update test_context.py to 3.14.4 (#7804)
* Update `test_context.py` to 3.14.4

* Mark & fix some tests

* clippy
2026-05-10 00:28:30 +09:00
Shahar Naveh
6ed17c3cb5 Update test_complex.py to 3.14.4 (#7803) 2026-05-10 00:28:13 +09:00
Shahar Naveh
002fc1122e Fix comment confusion bug in update_lib (#7802)
* Use `unittest.expectedSuccess` to mark failing tests

* Fix comment find logic

* Add test for it
2026-05-10 00:27:51 +09:00
dependabot[bot]
ae5c9119c9 Bump fast-uri from 3.0.6 to 3.1.2 in /wasm/demo (#7801)
Bumps [fast-uri](https://github.com/fastify/fast-uri) from 3.0.6 to 3.1.2.
- [Release notes](https://github.com/fastify/fast-uri/releases)
- [Commits](https://github.com/fastify/fast-uri/compare/v3.0.6...v3.1.2)

---
updated-dependencies:
- dependency-name: fast-uri
  dependency-version: 3.1.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-10 00:26:55 +09:00
Joshua Megnauth
4aa73ddab2 Use rustix for uname; drop uname crate (#7799) 2026-05-10 00:26:26 +09:00
Shahar Naveh
7576d68060 Update test_venv.py to 3.14.4 (#7798) 2026-05-10 00:26:05 +09:00
Joshua Megnauth
3bab7a9086 Fix sys.implementation (#7793)
`sys.version_info` and `sys.implementation` are two different versioning
schemes. `version_info` refers to the target Python version while
`implementation` refers to the implementation version.

For RustPython, `version_info` should be 3.14 because it currently
targets Python 3.14. This was correct and remains unchanged.

`implementation`, however, should be set to RustPython's version. I
updated the code to correctly get RustPython's version from the
environment. I also ensured values are hard coded at build time which
reduces the overall code that needs to be run at runtime as well as
removes some unneeded allocations.

Closes: #7770
2026-05-10 00:25:14 +09:00
dependabot[bot]
e10a27b1ae Bump openssl from 0.10.78 to 0.10.79 (#7791)
Bumps [openssl](https://github.com/rust-openssl/rust-openssl) from 0.10.78 to 0.10.79.
- [Release notes](https://github.com/rust-openssl/rust-openssl/releases)
- [Commits](https://github.com/rust-openssl/rust-openssl/compare/openssl-v0.10.78...openssl-v0.10.79)

---
updated-dependencies:
- dependency-name: openssl
  dependency-version: 0.10.79
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-06 20:44:10 +09:00
fanninpm
3b364608d9 Make determine_changes step run on ubuntu-slim (#7790) 2026-05-06 20:43:55 +09:00
fanninpm
1c4361803d Move dependencies to workspace for vm crate (#7789)
* Add dependencies from `vm` crate to workspace

* Declare dependencies as workspace = true
2026-05-06 14:03:05 +09:00
Bas Schoenmaeckers
22d4f43ad4 Add minimal capi lifecycle support (#7648)
* Add minimal capi lifecycle support

* Force enable `threading` on `stdlib`

---------

Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
2026-05-06 02:02:26 +09:00
Shahar Naveh
02a2b19839 Remove unused rust impl for formatting dis output (#7660)
* Remove unused rust impl for formatting dis output

* remove `examples/dis.rs`

* Added tests

* Update lock

* Try to set snapshot dir

* Remove verbose flag

* Regenerate snapshots after #7711

* Revert "Bump insta from 1.46.3 to 1.47.2 (#7706)"

This reverts commit e6d9ea6bfe.

* Debug info

* Show diff as well

* Show debug faster

* CI: true env

* Recert CI

* Add `CI: true` in ci emv

* Reapply "Bump insta from 1.46.3 to 1.47.2 (#7706)"

This reverts commit 693ca8cbe4d7885a81162a9be31e8bb567db885a.

* simplify macro

* trim on function side

* Force insta workspace root

* fix merge
2026-05-05 08:09:35 +00:00
Jeong, YunWon
ae7ff9c481 codegen: module seed CodeInfo emits empty flags (#7782)
CPython convention: top-level module / interactive / expression code
does not carry CO_NEWLOCALS or CO_OPTIMIZED. The per-scope mapping at
enter_scope::CompilerScope::Module already returns empty flags, but
Compiler::new seeded the root CodeInfo with CodeFlags::NEWLOCALS,
forcing module code into the NEWLOCALS arm of frame.rs:725-731 so
locals were allocated as a fresh empty dict instead of being bound to
globals (the correct semantics for exec(code, globals)).

Restore the seed to empty() so it matches the per-scope mapping and
CPython's compiler_enter_scope for module scope.
2026-05-05 16:22:55 +09:00
dependabot[bot]
d877c30417 Bump https://github.com/astral-sh/ruff-pre-commit (#7779)
Bumps [https://github.com/astral-sh/ruff-pre-commit](https://github.com/astral-sh/ruff-pre-commit) from v0.15.11 to 0.15.12.
- [Release notes](https://github.com/astral-sh/ruff-pre-commit/releases)
- [Commits](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.11...v0.15.12)

---
updated-dependencies:
- dependency-name: https://github.com/astral-sh/ruff-pre-commit
  dependency-version: 0.15.12
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-05 14:25:08 +09:00
dependabot[bot]
8bd4c5137e Bump mwilliamson/setup-wabt-action from 3.2.0 to 4.0.0 (#7778)
Bumps [mwilliamson/setup-wabt-action](https://github.com/mwilliamson/setup-wabt-action) from 3.2.0 to 4.0.0.
- [Release notes](https://github.com/mwilliamson/setup-wabt-action/releases)
- [Commits](https://github.com/mwilliamson/setup-wabt-action/compare/v3.2.0...427f2fdd70bc4dbc2e53c2eb4f19f66162d71bd2)

---
updated-dependencies:
- dependency-name: mwilliamson/setup-wabt-action
  dependency-version: 4.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-05 14:24:34 +09:00
Shahar Naveh
dc12bff0f4 Move clippy and cargo-shear to a dedicated job (#7741) 2026-05-05 14:24:21 +09:00
dependabot[bot]
e1dd3d43d5 Bump github/gh-aw from 0.68.3 to 0.71.1 (#7776)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.68.3 to 0.71.1.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](ce1794953e...f01a9d118a)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.71.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-05 14:22:14 +09:00
dependabot[bot]
a5cebc3242 Bump the wasmtime group across 1 directory with 2 updates (#7775)
Bumps the wasmtime group with 1 update in the / directory: [cranelift-jit](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift-jit` from 0.131.0 to 0.131.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-module` from 0.131.0 to 0.131.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift-jit
  dependency-version: 0.131.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
- dependency-name: cranelift-module
  dependency-version: 0.131.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-05 14:22:02 +09:00
Jeong, YunWon
ad5a55c1e3 Bytecode parity: align borrow optimization with CFG traversal (#7773)
* Align CFG cleanup bytecode with CPython

* Bytecode parity: fblock unwind, fstring join, folding, scope

- compile.rs: unwind_fblock_stack returns whether a finally ran so
  return-statement emission can adjust location handling; restructure
  try/except/finally cleanup to preserve or drop boundary NOPs based on
  whether the body falls through; rework f-string lowering with
  count/join helpers; remove the per-collection-type heuristic for
  AST-level folding and defer to flowgraph passes; add several folding
  helpers and a ComprehensionLoopControl enum.
- ir.rs: re-run unary/binop folding around tuple folding, add
  reorder_conditional_scope_exit_and_jump_back_blocks and several block
  classification helpers, add MAX_STR_SIZE, change is_exit_without_lineno
  to take the block list.
- symboltable.rs: in analyze_cells, remove names owned as cells in
  function-like scopes from the parent's free set; mark lambda scope
  type explicitly.

* Refine CFG scope-exit backedge ordering
2026-05-05 14:04:12 +09:00
fanninpm
e4d35b08ea Move dependencies to workspace for common crate (#7771)
* Add dependencies from `common` crate to workspace

* Declare dependencies as workspace = true
2026-05-05 14:02:57 +09:00
Noa
02932384d6 Use cfg_select in a bunch more places (#7740) 2026-05-04 20:26:16 +00:00
Shahar Naveh
0325fd429e Opcode name (#7433) 2026-05-04 20:49:47 +09:00
Shahar Naveh
4db0aca471 fix ci (#7774)
* fix ci

* more
2026-05-04 20:41:08 +09:00
Changjoon
83002d7369 Tighten CPython parity for str format spec, %-format, and str() constructor (#7769)
Five related CPython parity gaps in `str` formatting and construction:

1. **`str(bytes, errors=...)` triggers decode mode.** Previously, only
   `encoding=` triggered decode; passing only `errors=` fell back to
   `repr()`. CPython's behavior: presence of `encoding` OR `errors`
   triggers decode mode (default UTF-8 when only `errors` is given).

2. **`'{...}'.format() IndexError wording.** Generic Rust "tuple index
   out of range" replaced with CPython's "Replacement index N out of
   range for positional args tuple".

3. **`{0:3.2s}.format('abc')` → 'ab '.** String format spec applied
   precision after width padding; CPython truncates BEFORE padding.
   Reorder the operations.

4. **`%x` / `%o` / `%X` / `%c` accept `__index__` objects.** Previously
   only `PyInt` downcast was attempted. Mirror CPython's
   PyNumber_Index dispatch via `try_index_opt`.

5. **`%d` / `%u` / `%i` error wording.** "a number is required" →
   "a real number is required" (matches CPython).

Also adds `not <type>` suffix to `%c` error messages so the type is
visible in TypeError text (matches CPython structure even without
fully-qualified names).

Verified byte-identical with CPython 3.14.4 across 25+ probes covering
the format/spec/constructor combinations. Unmasks
`test_str.test_constructor_keyword_args` and
`test_str.test_constructor_defaults`. test_str/test_bytes/test_format/
test_codecs/test_io/test_unicode_identifiers — 1,429 tests pass, 0
regressions. All 188 `extra_tests/snippets/*.py` pass under the CI
feature set.

`test_str.test_format` and `test_str.test_formatting` markers retained:
`test_format` still trips on `'{0:08s}'.format('result')` (numeric
zero-pad treated as fill+left-align by CPython for str type — separate
format-spec parser concern). `test_formatting` still trips on
`%c` error message expecting fully qualified `module.qualname` (RP
returns bare class name — separate broader concern).
2026-05-04 10:28:43 +09:00
Changjoon
90cc888f4b Validate compile() filename type and dont_inherit __bool__ protocol (#7768)
Two CPython parity gaps in `compile()` argument handling:

1. **filename rejects only non-buffer-protocol types.** CPython's
   `PyUnicode_FSDecoder` accepts `str`, `bytes`, and objects with
   `__fspath__` only — `bytearray` / `memoryview` / `array.array` raise
   TypeError. RustPython's `FsPath::TryFromObject` impl falls back to
   any buffer-protocol object and silently converts to bytes, accepting
   them.

   ```python
   >>> compile('pass', bytearray(b'file.py'), 'exec')
   # CPython 3.14.4: TypeError
   # RustPython main: <code object>  
   ```

   Change `CompileArgs::filename` from `FsPath` (which uses the
   permissive `TryFromObject` impl) to `PyObjectRef`, then call the
   strict `FsPath::try_from_path_like` at the top of `compile()`. Other
   `FsPath` consumers are unchanged.

2. **dont_inherit strict-checks the `bool` type.** CPython routes
   `dont_inherit` through `PyObject_IsTrue`, calling `__bool__` on
   arbitrary objects and propagating exceptions raised there. RustPython
   typed it `OptionalArg<bool>`, which rejects subclass-less objects at
   binding time before `__bool__` runs.

   ```python
   >>> class EvilBool:
   ...     def __bool__(self): raise ValueError('hi')
   >>> compile('pass', 'f', 'exec', dont_inherit=EvilBool())
   # CPython 3.14.4: ValueError('hi')
   # RustPython main: TypeError('Expected type bool, not EvilBool')  
   ```

   Switch to `OptionalArg<ArgIntoBool>` — already used elsewhere in
   `builtins` (`all`, `any`, `print(..., flush=...)`).

Verified byte-identical with CPython 3.14.4 across:
- 6 filename types (str, bytes, bytearray, memoryview, list, int)
- 7 dont_inherit values (True/False/1/0/""/"yes"/None) plus the
  `__bool__`-raises-ValueError case

Unmasks `Lib/test/test_compile.py`:
- `test_compile_filename`
- `test_compile_filename_refleak`

`cargo run --release -- -m test test_compile test_builtin test_compileall
test_codeop test_ast` — 703 tests pass, 0 regressions. All 188
`extra_tests/snippets/*.py` pass under the CI feature set.
2026-05-04 10:27:53 +09:00
Jiseok CHOI
cf23884656 test(str): add regression test for isprintable() unicode 15 chars, (#7766)
Fixes #7525
2026-05-04 10:27:19 +09:00
Changjoon
c3c9292c8b Match CPython wording for compile() optimize and flags validation (#7765)
CPython's `builtin_compile_impl` (Python/bltinmodule.c) accepts only
optimize ∈ {-1, 0, 1, 2}; anything else raises
`ValueError("compile(): invalid optimize value")`. The previous logic
only validated via `i32::try_into::<u8>()`, which silently accepts every
value in [0, 255], so `compile(..., optimize=3)`, `optimize=99`, etc.
were silently truncated to a u8. The error wording also had the wrong
word order.

Replace the cast-based check with a `match` against the spec range.

Adjacent: the unrecognised-flags message used American spelling
("unrecognized") and missed the colon separator. CPython uses British
"unrecognised" with a colon — match it.

Verified byte-identical with CPython 3.14.4 across 12 boundary values
for optimize and 4 cases for flags. Preserves the existing OverflowError
path for `optimize=1 << 1000` (raised at the ArgPrimitiveIndex<i32>
conversion layer, before this check).
2026-05-04 10:26:16 +09:00
Shahar Naveh
ee5e9d0001 Enable some pedantic clippy lints (#7764) 2026-05-04 10:25:37 +09:00
Changjoon
181e4e7124 Drop redundant exception type prefix from float-to-int error messages (#7763)
CPython raises `OverflowError("cannot convert float infinity to integer")`
and `ValueError("cannot convert float NaN to integer")` from
`Objects/floatobject.c::float___trunc___impl` and friends. The exception
type name is added by Python's traceback display layer; the message
itself should not duplicate it.

`try_to_bigint` was producing
`OverflowError("OverflowError: cannot convert ...")` etc., which made
`repr(e)` and any code path that inspects `str(e)` diverge from CPython.

Affects all 5 callers of `try_to_bigint`: `__int__`, `__floor__`,
`__ceil__`, `__round__` (no-arg), `__trunc__` — i.e. `int(x)`,
`math.floor/ceil/trunc(x)`, `round(x)` for non-finite floats.

Verified byte-identical with CPython 3.14.4 across 14 affected sites.
2026-05-04 10:24:08 +09:00
Shahar Naveh
eb99a8ecf1 Warn on unreachable_pub (#7762) 2026-05-04 10:18:24 +09:00
fanninpm
acc167fc44 Move dependencies to workspace for stdlib crate (#7747)
* Add dependencies from `stdlib` crate to workspace

* Declare dependencies as workspace = true
2026-05-04 09:50:21 +09:00
Changjoon
c2910c06f3 Round float at the decimal level to match CPython's _Py_dg_dtoa (#7761)
* Round float at the decimal level to match CPython's _Py_dg_dtoa

CPython's `float.__round__` (Objects/floatobject.c) routes through
`_Py_dg_dtoa` and rounds at the decimal level. The previous
`round_float_digits` multiplied by 10**ndigits and rounded at the
IEEE 754 binary level, which diverges for values that aren't exactly
representable. For example, 2.675 stores as 2.67499...; dtoa correctly
rounds it down to 2.67, but `(2.675 * 100.0).round() / 100.0` lands on
2.68 because the multiplication produces a phantom 267.5 tie that
round-half-to-even snaps up.

Rust's `{:.*}` float formatting uses dtoa-style algorithms (Grisu3 +
Dragon4 fallback) and matches CPython's `_Py_dg_dtoa` byte-for-byte.
Replace the multiply-then-round step with `format!` + `parse` for
ndigits >= 0. The ndigits < 0 path is unchanged because dividing
typical inputs by 10**|ndigits| produces genuine ties rather than
synthesizing them.

Verified byte-identical with CPython 3.14.4 over a 108-case random
fuzz plus targeted half-tie probes. Unmasks
`test_float.RoundTestCase.test_matches_float_format` and
`test_previous_round_bugs`.

* Use #[expect] with reason for float_cmp suppression

Co-authored-by: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com>

---------

Co-authored-by: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com>
2026-05-03 00:16:27 +09:00
Shahar Naveh
ac3e067230 Only run cargo check when rust code is changed (#7760)
* Only run `cargo check` when rust code is changed

* Test

* Another test

* Revert "Test"

This reverts commit 1f23cc33f5.

* Revert "Another test"

This reverts commit 50a51d5e56.

* Add extra rust related files
2026-05-03 00:15:46 +09:00
Shahar Naveh
be7841f9c1 Update test_py_compile.py to 3.14.4 (#7759) 2026-05-03 00:15:22 +09:00
Shahar Naveh
3e66fb508a Update str related tests (#7758)
* Update `string_tests.py` to 3.14.4

* Update `test_bytes.py` to 3.14.4

* Update `test_userstring.py` to 3.14.4

* Mark failing tests
2026-05-03 00:15:03 +09:00
Shahar Naveh
f2ad84a489 AnyInstruction helpers + doc imrovments (#7757) 2026-05-03 00:13:31 +09:00
Shahar Naveh
926d69b50a Add some clippy lints (#7755) 2026-05-02 11:14:23 +09:00
dependabot[bot]
8d1c68c9a0 Bump actions/setup-node from 6.3.0 to 6.4.0 (#7689)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 6.3.0 to 6.4.0.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](53b83947a5...48b55a011b)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: 6.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-02 08:16:15 +09:00
Shahar Naveh
d9fff99718 Pin actions to hash (cron-ci.yaml) (#7686) 2026-05-02 08:15:43 +09:00
Shahar Naveh
0f25d145fd Make updating actions cache synchronous (#7712) 2026-05-02 08:15:14 +09:00
Shahar Naveh
7fd0da92d3 Fix libs deps check (#7732)
* Convert parsing logic to python

* Trigger job. (DROP ME BEFORE MERGE!)

* Missing EOF

* Add found modules to set

* Suggestion by @fanninpm

* Fix missing trailing slash

* Ensure no `.py` at module name

* Strip any file auffix

* Revert "Trigger job. (DROP ME BEFORE MERGE!)"

This reverts commit 8cf9651a24.

* Handle quoted args
2026-05-02 08:14:55 +09:00
Shahar Naveh
c027ffc2ba Pin marocchino/sticky-pull-request-comment action to a hash (#7751) 2026-05-01 22:58:35 +09:00
Jiseok CHOI
192ba371e4 Fix function attribute tests: __defaults__ del, __code__ free vars ch… (#7749)
* Fix function attribute tests: __defaults__ del, __code__ free vars check, bound method dir()

- Support `del func.__defaults__` and `del func.__kwdefaults__` by changing
  setter signatures to `PySetterValue<Option<...>>` so Delete is treated as
  setting the value to None (matching CPython behaviour)
- Validate free-variable count when assigning to `func.__code__`: raise
  ValueError when the new code object's freevars count doesn't match the
  existing closure size
- Add `__dir__` to `PyBoundMethod` that delegates to the underlying
  function's dir(), so attributes set on the function show up in
  `dir(bound_method)`
- Remove `@unittest.expectedFailure` from the four tests that now pass:
  test_blank_func_defaults, test_func_default_args, test___code__,
  test_dir_includes_correct_attrs

* Remove expectedFailure markers for now-passing tests
2026-05-01 22:58:16 +09:00
Shahar Naveh
d25195ed0e Update test_binascii.py to 3.14.4 (#7753)
* Update `test_binascii.py` to 3.14.4

* Mark failing test
2026-05-01 12:18:19 +00:00
Shahar Naveh
9004089fd1 Update unittest to 3.14.4 (#7752)
* Update `unittest` from 3.14.4

* Update `test_unittest` to 3.14.4

* Unmark passing test
2026-05-01 11:06:24 +00:00
dependabot[bot]
f6e2fcffe7 Bump liblzma-sys from 0.4.5 to 0.4.6 (#7744)
Bumps [liblzma-sys](https://github.com/portable-network-archive/liblzma-rs) from 0.4.5 to 0.4.6.
- [Release notes](https://github.com/portable-network-archive/liblzma-rs/releases)
- [Commits](https://github.com/portable-network-archive/liblzma-rs/compare/liblzma-sys-0.4.5...liblzma-sys-0.4.6)

---
updated-dependencies:
- dependency-name: liblzma-sys
  dependency-version: 0.4.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-01 19:49:10 +09:00
Shahar Naveh
bb77ac6284 Update test_unicodedata.py to 3.14.4 (#7750)
* Update `test_unicodedata.py` to 3.14.4

* Add test asset

* Mark failing tests

* Add `expectedSuccess` docorator

* Add support for nee decorator in patch_spec

* Reapply patches
2026-05-01 19:48:41 +09:00
Changjoon
c2141a765f Apply titlecase mapping in str.title() for uppercase digraphs (#7748)
The uppercase/titlecase branch of PyStr::title() pushed characters
unchanged when starting a new word, which left Latin Extended-B
digraphs (U+01F1 'DZ', U+01C4 'DŽ', etc.) in their uppercase form
instead of mapping them to their distinct titlecase counterparts
(U+01F2 'Dz', U+01C5 'Dž'). For ASCII letters and characters where
to_titlecase is identity this had no effect, hiding the bug for the
common case.

Mirror the lowercase branch — which already calls to_titlecase()
when starting a new word — so both branches symmetrically apply
the titlecase mapping. char::to_titlecase is identity for already-
titlecase and ASCII-uppercase characters, so existing cases stay
correct.

Also unmasks test_unicodedata.UnicodeMiscTest.test_bug_4971, which
asserts exactly this behavior (`'DŽ'.title() == 'Dž'` etc.)
and was marked expectedFailure with reason `+ Dž`.

Closes #7527 (the only example from that issue still failing on
3.14.4; the other four examples already pass on current main).
2026-05-01 19:45:55 +09:00
Changjoon
dd1cbac692 Match CPython's _float_div_mod, fixing divmod and % zero-handling (#7745)
float_ops::divmod, mod_, and floordiv each carried their own conversion
from Rust's dividend-sign `%` to CPython's divisor-sign convention. Both
divmod and mod_ mishandled the zero-remainder case where the dividend
is a non-zero exact multiple of the divisor (e.g. divmod(6.0, -3.0),
6.0 % -3.0): the sign-correction branch fired on a zero remainder and
produced (-3.0, -3.0) and -3.0 respectively, violating the magnitude
invariant 0 <= abs(r) < abs(b). divmod also leaked the wrong signed-
zero quotient when the true quotient was zero (divmod(-1.0, -2.0)
returned (-0.0, -1.0) instead of (+0.0, -1.0)).

These are independent bugs in two functions, but both come from the
same root cause: zero-remainder needs a separate path from the sign-
correction branch.

Mirror CPython's `_float_div_mod` (Objects/floatobject.c) by making
divmod the canonical implementation and turning mod_ and floordiv into
thin wrappers. divmod(a, b) == (a // b, a % b) now holds by
construction.

Closes #7722
2026-05-01 19:45:28 +09:00
Changjoon
c98d26e508 Raise OverflowError in float pow when finite-base result overflows (#7746)
PR #7727 added an overflow guard in float_pow's negative-base
non-integer-exponent branch (which delegates to complex_pow). The
remaining else branch — covering positive base or negative-base
integer exponent — directly returned v1.powf(v2) without inspecting
the result, so finite inputs that produced an out-of-range value
silently leaked f64::INFINITY (or -INFINITY) instead of raising.

Examples that now raise OverflowError as in CPython:
    pow(2.0, 2000)
    pow(10.0, 400)
    pow(-2.0, 2001)
    pow(0.5, -2000)
    pow(1e150, 3)

Mirror the inline overflow guard already used in complex.rs::complex_pow:
when the result is infinite but neither input is, raise OverflowError.
The both-finite check preserves intentional infinities like
pow(inf, 2.0).

Closes #7729
2026-05-01 19:44:42 +09:00
Changjoon
5e408d65f4 Resolve PathLike via os.fspath in io.open (#7743)
CPython splits PathLike resolution across two layers: _io.FileIO
preserves the raw argument on .name (low-level contract), while
the high-level open() wrapper resolves it via os.fspath before
delegating. RustPython's io_open skipped that step, so
builtins.open(PathLike).name returned the PathLike object instead
of the resolved str/bytes.

Match Lib/_pyio.py:193-194 by resolving non-int inputs at the
io_open boundary, leaving _io.FileIO unchanged.
2026-05-01 19:44:10 +09:00
Shahar Naveh
73b5b69bd8 Cargo check features on all os (#7733)
* Cargo check features on all os

* Adjust cargo conf

* Skip unsupported ssl platforms

* zizmor

* Remove duplicated check
2026-05-01 19:43:43 +09:00
Jeong, YunWon
e79df4a6fb Bytecode parity CFG normalization and jump cleanup (#7721)
* typealias reviews

* Bytecode parity - try/except block order, CFG reorder

Reorder try/except/else/finally to emit else+finally before
except handlers matching CPython layout. Add set_no_location
for cleanup blocks. Extend CFG reorder pass to handle true-path
jump-back for generators, break/continue, and assert in loops.
Add stop-iteration error handler awareness to block protection.

* Align CFG cleanup bytecode with CPython

* Unmark test_dis.test_findlabels expected failure

* Compute target predecessor flags in single pass

remove_nops and remove_redundant_nops_in_blocks repeated
has_jump_predecessor / has_plain_jump_predecessor / target lookups
per block, scanning all blocks each time. With ~200,000 if blocks
this became O(B^2 * I) and timed out test_compile.test_stack_overflow.
Fold the three flags into one O(B * I) pass via
compute_target_predecessor_flags.

* Address review feedback on slice folding, fallthrough, attr-chain

- try_fold_constant_slice now delegates to try_fold_constant_expr so
  slice bounds accept the same constants other folding paths do
  (unary-folded values, __debug__, etc.).
- remove_nops resolves fallthrough predecessors through empty blocks
  via next_nonempty_block before checking ends_with_for_cleanup.
- should_deopt_borrowed_attr_chain ReturnIter matcher now accepts
  Instruction::CallKw alongside Instruction::Call, matching the
  Call/CallKw treatment in the surrounding deopt trigger check.

* remove test
2026-04-30 23:30:27 +09:00
Shahar Naveh
32e16fe7da Fix possible npm cache poisoning (#7742)
* Fix possible npm cache poisoning

* fix typo

* fix logic errors

* Use correct output
2026-04-30 23:21:06 +09:00
fanninpm
88be7bb16a Move dependencies to workspace for literal crate (#7739)
* Add dependencies from `literal` crate to main workspace

* Declare dependencies as workspace = true
2026-04-30 10:24:50 +03:00
Alok Pandey
f90a5cf650 Fix del obj.__dict__ to match CPython behavior (fixes #5355) (#7568)
* Fix del obj.__dict__ to match CPython behavior (issue #5355)

* Address CodeRabbit concerns: fix GC clearing and improve thread safety of lazy __dict__ recreation

* Fix del obj.__dict__: improve GC safety, implement lazy re-creation in setattr, and enable passing CPython tests

* Restore expectedFailure for test_has_inline_values

* Fix ObjExt::new call site to include has_dict parameter

* Remove stray test.py to avoid CI syntax errors

* Remove debug txt files and clean test_class.py comments

* Delete Lib/test/test_class.py

* Restore test_class.py with correct changes (remove expectedFailure, no deletion)

* Fix clippy warnings: remove unused into_inner, collapse nested if-let

* Fix rustfmt formatting and ruff PEP 8 E302 blank line

* Align __dict__ error messages and ensure safety for function/partial objects

* Fix compilation errors: change &self to &Py<Self> in __dict__ methods

* Fix compilation errors: resolve borrow-after-move and replace transpose on PySetterValue

- type.rs: Replace invalid .transpose() on PySetterValue with explicit
  match on Assign/Delete variants in subtype_set_dict
- function.rs: Fix borrow-after-move in set___dict__ by capturing class
  name before downcast; use as_object() for instance_dict/set_dict calls
- _functools.rs: Same borrow-after-move fix and as_object() calls for
  PyPartial's __dict__ getter/setter

* Fix compilation errors: resolve borrow-after-move and replace transpose on PySetterValue

* Fix snippet formatting and mark test_remote as expected failure

* Fix test_remote by removing HAS_DICT flag from function type

* Fix lint formatting error

* Remove unnecessary print statement in test_del_dict

* Fix trailing newlines in snippet test

* Trigger CI

* Align __dict__ generic setter behavior

* Move __dict__ deletion tests to relevant snippets

---------

Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
2026-04-30 02:09:16 +00:00
dependabot[bot]
6c2c8421d7 Bump actions/upload-artifact from 7.0.0 to 7.0.1 (#7640)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 7.0.0 to 7.0.1.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](bbbca2ddaa...043fb46d1a)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-30 11:01:47 +09:00
dependabot[bot]
6e895fbac4 Bump psm from 0.1.30 to 0.1.31 (#7738)
Bumps [psm](https://github.com/rust-lang/stacker) from 0.1.30 to 0.1.31.
- [Commits](https://github.com/rust-lang/stacker/commits)

---
updated-dependencies:
- dependency-name: psm
  dependency-version: 0.1.31
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-30 04:45:57 +09:00
Shahar Naveh
543fcc841c Update test_weakset.py to 3.14.4 (#7735) 2026-04-30 04:45:43 +09:00
Changjoon
6c91c5bb2a Short-circuit identity in rich_compare_bool for Eq/Ne (PyObject_RichCompareBool parity) (#7734)
* Short-circuit identity in rich_compare_bool for Eq/Ne (PyObject_RichCompareBool parity)

CPython distinguishes two comparison entry points (Objects/object.c):
- PyObject_RichCompare returns the raw __eq__ / __ne__ result; no
  identity short-circuit
- PyObject_RichCompareBool returns bool; identity implies equality
  (and inequality is false on identity), short-circuiting before
  dispatch

Collection membership / equality (x in [x], [nan] == [nan], set/dict
comparisons) go through the bool variant and rely on the short-circuit.
RustPython's rich_compare_bool skipped the identity check, so a buggy
or raising __eq__ propagated even when the operand was the same object.

Add an identity short-circuit at the top of rich_compare_bool for Eq
(returns true) and Ne (returns false). Ordering ops fall through to
_cmp because Python does not guarantee reflexivity for </<=/>/>=.
_cmp itself is untouched, so == / != operators continue to invoke
__eq__ / __ne__ exactly as before.

Unmasks test_dictviews.TestDictViews.test_compare_error.

Verified byte-identical with CPython 3.14.4 across 53 scenarios in 10
categories (collection membership / equality / ordering ops / NaN /
hash collision / dict views / list-set-dict ops). 14-module regression
sweep ~2,402 tests passes with no regressions.

* Route proxy comparisons through PyObject_RichCompare

The identity short-circuit added to rich_compare_bool exposed a latent
bug in three proxy types (weakref, weakproxy, mappingproxy): they were
delegating their __eq__ to the bool variant on referents, while CPython
uses PyObject_RichCompare so the referent's __eq__ runs even when the
referents share identity.

Fixes test_weak_keyed_cascading_deletes which depends on key __eq__
firing during dict deletion to trigger a side-effect that mutates the
key list.
2026-04-30 04:45:23 +09:00
Shahar Naveh
3c297d478a Update test_call.py to 3.14.4 (#7730) 2026-04-30 04:40:44 +09:00
Jeongseop Lim
6ed2f15b67 Raise OverflowError in float pow when complex result overflows (#7727)
* fix: Align error messages with CPython

* fix: Raise overflow error on complex exponentiation overflow

* refactor: Delegate complex pow handling from float pow

* test: Add regression tests for complex pow overflow

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2026-04-30 04:40:31 +09:00
Changjoon
6b67067e9a Chain __context__ alongside __cause__ when wrapping StopIteration (PEP 479) (#7731)
PEP 479 wraps a StopIteration raised from a generator/coroutine into a
RuntimeError. CPython sets both __cause__ and __context__ of the new
RuntimeError to the original StopIteration (the same object). RustPython's
wrapping sites set __cause__ only, leaving __context__ as None.

set___cause__ already toggles __suppress_context__ to true, so the
user-facing traceback is unchanged — only assertions that inspect
__context__ directly observe the gap.

Three sites all wrap StopIteration / StopAsyncIteration into RuntimeError
for PEP 479. Set __context__ to the same exception instance before
setting __cause__ at each:

- frame.rs::StopIterationError intrinsic (generator yield-expression path)
- coroutine.rs generator __next__ StopIteration branch
- coroutine.rs async-generator __anext__ StopAsyncIteration branch

PyBaseExceptionRef is Arc-backed, so e.clone() is a refcount bump;
'cause is context' holds, matching CPython.

Unmasks:
- test_generator_stop.TestPEP479.test_stopiteration_wrapping_context
- test_yield_from.TestInterestingEdgeCases.test_close_and_throw_work
- test_yield_from.TestInterestingEdgeCases.test_close_and_throw_raise_stop_iteration
- test_yield_from.TestInterestingEdgeCases.test_close_and_throw_yield
2026-04-29 18:52:22 +09:00
Changjoon
04ffa3891c Match CPython's "argument of type ... is not a container or iterable" wording (#7714)
CPython's PySequence_Contains (Objects/abstract.c::_PySequence_IterSearch)
catches the TypeError from PyObject_GetIter when neither __contains__ nor
__iter__ is available, and re-raises with membership-test wording.

RustPython's PySequence::contains propagated the get_iter error verbatim,
so '1 in obj' produced 'X' object is not iterable — a literal but less
specific message.

Wrap the get_iter call in map_err: when the failure is a TypeError,
re-raise with byte-identical CPython wording. Other exception types pass
through unchanged.

Unmasks test_contains.TestContains.test_common_tests.
2026-04-29 18:29:31 +09:00
Changjoon
ba2b619c0c Accept __index__-conforming objects for compile() flags / optimize (#7728)
CPython's compile() (Python/Python-ast.c) accepts any object with
__index__ for the flags and optimize arguments. RustPython's CompileArgs
typed both fields as OptionalArg<PyIntRef>, so a class with only
__index__ raised 'TypeError: Expected type int but X found' during arg
binding.

bpo-36907's regression test (test_call.test_fastcall_clearing_dict)
exercises exactly this: an IntWithDict.__index__ that mutates
self.kwargs mid-call. CPython parses both args via __index__ and doesn't
crash even when the kwargs dict is cleared between binding and use.

Switch flags and optimize to OptionalArg<ArgPrimitiveIndex<i32>>, the
same helper already used by range, slice, bytes.__mul__, hex, oct, etc.
ArgPrimitiveIndex calls try_index (= __index__ protocol) and converts
to the requested primitive in one step, so the three call sites in
compile() simplify from .map_or(Ok(d), |v| v.try_to_primitive(vm))? to
.map_or(d, |v| v.value).

Unmasks test_call.FastCallTests.test_fastcall_clearing_dict.
2026-04-29 18:26:49 +09:00
Jeongseop Lim
c8ddbd2326 Fix pow() raising ValueError instead of TypeError for non-int exponent (#7725)
* Validate pow() exponent type before zero-modulus check

* Add tests for pow() exponent type check
2026-04-29 18:18:11 +09:00
Changjoon
3ebcab70c0 Make mappingproxy's nb_or slot symmetric for dict | mp (#7723)
* Make mappingproxy's nb_or slot symmetric for dict | mp

CPython's mappingproxy_or (Objects/descrobject.c) unwraps a mappingproxy
on either side of '|' to its underlying mapping and delegates back to
PyNumber_Or. This makes 'dict | mp', 'mp | dict', and 'mp | mp' all
produce a plain dict result without dict's own nb_or having to know
about mappingproxy.

RustPython's 'or' slot in 'AsNumber for PyMappingProxy' only handled
the case where the left operand is a mappingproxy. When the slot fired
with a=dict, b=mp (because dict.nb_or returned NotImplemented), it
returned NotImplemented again — so 'dict | mp' raised TypeError. This
propagated to 'UserDict | mappingproxy' (which calls self.data | other).

Rewrite the slot to unwrap a mappingproxy on either side (or both)
before delegating to vm._or on the underlying mappings. The
inplace_or slot is unchanged — '|=' is still rejected.

Unmasks test_userdict.UserDictTest.test_mixed_or.

* Unmask test_types.MappingProxyTests.test_union

The slot fix in this PR also enables this test, which was marked
expectedFailure for the same dict|mappingproxy TypeError. Caught as
UNEXPECTED SUCCESS in CI.
2026-04-29 18:16:27 +09:00
fanninpm
51e7200d11 Move dependencies to workspace for jit crate (#7720)
* Add dependencies from `jit` crate to main workspace

* Declare dependencies as workspace = true
2026-04-29 18:15:01 +09:00
fanninpm
d7a319d967 Move dependency to workspace for host_env crate (#7719)
* Add dependency from `host_env` crate to main workspace

* Declare dependency as workspace = true
2026-04-29 18:14:51 +09:00
Changjoon
330b18f2fe Preserve recursively-set value in defaultdict.__missing__ (#7718)
CPython's defaultdict.__missing__ (Modules/_collectionsmodule.c::defdict_missing)
calls default_factory() first; if the factory's recursion already populated
self[key] while running, the existing value is preserved instead of being
overwritten.

RustPython ships a Python fallback at Lib/collections/_defaultdict.py
(the C _collections.defaultdict is not available). That fallback
unconditionally executed self[key] = val after the factory returned,
overwriting any value the recursive call had already stored.

Add a 'if key in self: return self[key]' guard before the assignment.
dict.__contains__ does not invoke __missing__, so there's no recursion
risk; in the common non-reentrant case the check is False and behavior
is unchanged.

Unmasks test_defaultdict.TestDefaultDict.test_factory_conflict_with_set_value.
2026-04-29 18:14:32 +09:00
dependabot[bot]
82e8b200db Bump the unix group across 1 directory with 2 updates (#7713)
Bumps the unix group with 2 updates in the / directory: [nix](https://github.com/nix-rust/nix) and [rustyline](https://github.com/kkawakam/rustyline).


Updates `nix` from 0.30.1 to 0.31.2
- [Changelog](https://github.com/nix-rust/nix/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nix-rust/nix/compare/v0.30.1...v0.31.2)

Updates `rustyline` from 17.0.2 to 18.0.0
- [Release notes](https://github.com/kkawakam/rustyline/releases)
- [Changelog](https://github.com/kkawakam/rustyline/blob/master/History.md)
- [Commits](https://github.com/kkawakam/rustyline/compare/v17.0.2...v18.0.0)

---
updated-dependencies:
- dependency-name: nix
  dependency-version: 0.31.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: unix
- dependency-name: rustyline
  dependency-version: 18.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: unix
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-29 18:14:09 +09:00
Shahar Naveh
3f718f9942 Align _opcode.has_* functions with 3.14.4 (#7711)
* Align `_opcode.has*` with 3.14.4

* Unmark passing tests

* Unmark more passing tests
2026-04-28 12:15:23 +00:00
fanninpm
363d19839f Move dependencies to workspace for derive-impl crate (#7710)
* Add dependencies from `derive-impl` crate to main workspace

* Declare dependencies as workspace = true
2026-04-28 21:12:31 +09:00
Changjoon
68aece59c9 Reject format-string field index above Py_ssize_t::MAX (#7708)
CPython rejects digit-only format-string field names that overflow
Py_ssize_t at parse time with ValueError: Too many decimal digits in
format string (Python/string_parser.c::get_integer). RustPython's
FieldName::parse accepted any digit string usize::from_str could parse,
producing IndexError or KeyError at lookup instead.

Cap the parsed index at isize::MAX (Py_ssize_t::MAX on every platform)
inside FieldName::parse. Also reject digits-only strings whose value
overflows usize itself (caught when parse_usize returns None on an
all-digit input). A new FormatParseError::TooManyDecimalDigits maps to
the byte-identical CPython wording.

Unmasks test_str.StrTest.test_format_huge_item_number.
2026-04-28 21:12:09 +09:00
Changjoon
b3d6d2f247 Reject format spec with width above i32::MAX (#7707)
CPython rejects format-spec widths that exceed Py_ssize_t::MAX with
ValueError: Too many decimal digits in format string. RustPython's
FormatSpec::_parse only capped precision (via parse_precision); width
was accepted up to usize::MAX, so values like sys.maxsize + 1 silently
produced an effectively-ignored width.

Reject any width above i32::MAX with FormatSpecError::DecimalDigitsTooMany,
matching the existing precision cap and producing the byte-identical
ValueError wording.

Unmasks test_str.StrTest.test_format_huge_width.
2026-04-28 21:11:33 +09:00
dependabot[bot]
e6d9ea6bfe Bump insta from 1.46.3 to 1.47.2 (#7706)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.46.3 to 1.47.2.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.46.3...1.47.2)

---
updated-dependencies:
- dependency-name: insta
  dependency-version: 1.47.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-28 21:11:08 +09:00
dependabot[bot]
59382f385a Bump rustls from 0.23.38 to 0.23.39 (#7705)
Bumps [rustls](https://github.com/rustls/rustls) from 0.23.38 to 0.23.39.
- [Release notes](https://github.com/rustls/rustls/releases)
- [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rustls/rustls/compare/v/0.23.38...v/0.23.39)

---
updated-dependencies:
- dependency-name: rustls
  dependency-version: 0.23.39
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-28 21:11:00 +09:00
dependabot[bot]
9db00f741c Bump the wasmtime group across 1 directory with 3 updates (#7704)
Bumps the wasmtime group with 3 updates in the / directory: [cranelift](https://github.com/bytecodealliance/wasmtime), [cranelift-jit](https://github.com/bytecodealliance/wasmtime) and [cranelift-module](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift` from 0.130.1 to 0.131.0
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-jit` from 0.130.1 to 0.131.0
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-module` from 0.130.1 to 0.131.0
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.131.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: wasmtime
- dependency-name: cranelift-jit
  dependency-version: 0.131.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: wasmtime
- dependency-name: cranelift-module
  dependency-version: 0.131.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-28 21:10:52 +09:00
Changjoon
e5f2d2d3b9 Drop int() delegation to __trunc__ (#7703)
CPython 3.14 fully removed the long-deprecated fallback from int() to
__trunc__. Classes that want int(x) support must implement __int__ or
__index__; math.trunc(x) continues to use __trunc__.

Delete the __trunc__ branch in PyObject::try_int so a class with only
__trunc__ now reaches the existing TypeError arm, matching CPython.

Unmasks test_int.IntTestCases.test_intconversion.
2026-04-28 21:10:42 +09:00
Shahar Naveh
7fb743b1be Update traceback.py from 3.14.4 (#7702) 2026-04-28 21:10:33 +09:00
Changjoon
6c498fc4a7 Preserve str subclass type returned by __str__ / __repr__ (#7701)
Closes #7450.

CPython's unicode_new_impl returns the PyObject_Str result as-is when
type == &PyUnicode_Type, only invoking unicode_subtype_new for actual
str subclasses. RustPython's PyStr::Constructor stripped the result via
Self::from(s.as_wtf8().to_owned()) and re-materialized through
into_ref_with_type, dropping the subclass type even when cls is exactly
str.

Add a slot_new branch that returns input.str(vm)? directly when cls is
str_type with no encoding. Subtype construction and the bytes-decoding
path are unchanged.

Unmasks test_str.StrTest.test_conversion (11 assertTypedEqual cases).
2026-04-28 21:09:49 +09:00
Changjoon
b8f7ae4265 Reject __abc_tpflags__ with both SEQUENCE and MAPPING bits (#7700)
CPython's _abc._abc_init validates that __abc_tpflags__ doesn't combine
Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING (Modules/_abc.c::_abc_init).
RustPython's check_abc_tpflags copied the bits onto slots.flags without
that validation, so a class declaring both produced an inconsistent
type silently.

Validate the masked __abc_tpflags__ value against COLLECTION_FLAGS and
return a String error (which the existing new_heap_inner caller turns
into a TypeError) when both bits are present. Move the inheritance-skip
check after the self-attrs branch so a child overriding __abc_tpflags__
is still validated even when the parent already set one of the bits.
2026-04-28 21:09:16 +09:00
Changjoon
1d42ee565f Preserve __dict__ and __slots__ state in deque.__reduce__ (#7699)
deque.__reduce__ passed None as the unpickle state, so a deque
subclass's __dict__ and __slots__ values were dropped across a pickle
round-trip. CPython's deque___reduce___impl
(Modules/_collectionsmodule.c::deque___reduce___impl) calls
_PyObject_GetState, which returns the dict (or a (dict, slots) tuple)
so subclass attributes survive.

Replace the placeholder with the result of __getstate__() on the
instance. object.__getstate__ already implements the dict / dict+slots
protocol, matching _PyObject_GetState.
2026-04-27 12:50:23 +00:00
Changjoon
9794ab7fdf Enforce int_max_str_digits on int-to-str conversions (#7688)
* Enforce int_max_str_digits on int-to-str conversions

The str-to-int direction already enforced sys.get_int_max_str_digits()
via bytes_to_int; the int-to-str direction did not. CPython 3.14 enforces
both per PEP 644.

Adds check_int_to_str_digits helper in builtins::int (bit-count fast path
+ digit upper-bound from log10(2)), wired into the four Python-level
entry points: repr, the str fast path in protocol::object, int.__format__
(decimal/n/empty spec only — binary bases x/o/b are exempt per CPython),
and the DecimalD/I/U branches of vm::cformat for both str % and bytes %.

Unmasks 8 expectedFailure tests across test_int (max_str_digits, DoS
prevention, int_from_other_bases — each mirrored in IntSubclass),
test_ast (test_repr_large_input_crash) and test_reprlib (test_numbers).
Boundary cases (4299/4300/4301 digits at limit=4300) match CPython 3.14.4.

* Skip int-to-str DoS test on platforms without time.get_clock_info

The test_denial_of_service_prevented_int_to_str regression test uses
support.Stopwatch, which calls time.get_clock_info('monotonic'). In
RustPython that function is gated to unix/windows targets only, so on
wasm32-wasip1 it surfaces as AttributeError and breaks the wasm-wasi CI.
Guard the test with skipUnless(hasattr(time, 'get_clock_info'), ...) so
it runs everywhere it can and is skipped on wasm.

Also narrow is_decimal_int_format to Number(Case::Lower): 'N' is rejected
by format_int as UnknownFormatCode, so excluding it preserves that error
path instead of intercepting it with the digit-limit check.

* Add TODO: RUSTPYTHON marker to skipUnless reason

scripts/update_lib uses TODO: RUSTPYTHON markers inside unittest
decorator reason strings to identify and migrate custom RustPython
patches across CPython library updates.

* Use expectedFailureIf for wasm get_clock_info gap

skipUnless silently hides the test forever; expectedFailureIf surfaces
unexpected success once RustPython implements time.get_clock_info on
wasm, prompting marker removal.
2026-04-27 21:41:40 +09:00
Changjoon
dc81c740cf Match CPython wording for __slots__ conflict and __doc__ delete errors (#7698)
The behavior already matched CPython (the slot conflict is detected,
the __doc__ delete is rejected); only the message text drifted.

- "__slots__ conflicts with a class variable" -> drop the stray "a"
  to match CPython's "conflicts with class variable".
- "cannot delete '__doc__' attribute of type 'X'" -> insert "immutable"
  before "type" to match CPython's wording (CPython surfaces the same
  phrase even for user-defined classes since the descriptor refuses
  the delete unconditionally).
2026-04-27 21:39:21 +09:00
Changjoon
f10f441854 Defer staticmethod/classmethod callable storage to __init__ (#7697)
CPython's staticmethod and classmethod set __func__ and copy wrapper
attributes (__doc__, __name__, etc.) only inside __init__
(Objects/funcobject.c::sm_init / cm_init). RustPython did this work in
slot_new and again in __init__, so subclasses that override __init__
without calling super().__init__() saw __func__ pointing at the
original callable instead of None.

Move the callable assignment and the wrapper-attribute copy into
Initializer::init; slot_new now just validates the signature and stores
None for the callable, matching the CPython contract.
2026-04-27 21:38:44 +09:00
Shahar Naveh
1fa676fd07 Upgrade cspell to v10.0.0 (#7696)
* Update cspell to `v10.0.0`

* Force node version to be 24

* Ensure node24

* Disable cache
2026-04-27 21:37:55 +09:00
Shahar Naveh
5648a3346f Upgrade der to 0.8 (#7695)
* Update `der` to 0.8, move to workspace dependencies

* Add `pem` feature
2026-04-27 21:37:42 +09:00
dependabot[bot]
02c454bdb4 Bump libc from 0.2.185 to 0.2.186 (#7694)
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.185 to 0.2.186.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Changelog](https://github.com/rust-lang/libc/blob/0.2.186/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.185...0.2.186)

---
updated-dependencies:
- dependency-name: libc
  dependency-version: 0.2.186
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-27 12:38:06 +09:00
dependabot[bot]
049d44b1e0 Bump uuid from 1.23.0 to 1.23.1 (#7692)
Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.23.0 to 1.23.1.
- [Release notes](https://github.com/uuid-rs/uuid/releases)
- [Commits](https://github.com/uuid-rs/uuid/compare/v1.23.0...v1.23.1)

---
updated-dependencies:
- dependency-name: uuid
  dependency-version: 1.23.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-27 12:37:57 +09:00
dependabot[bot]
f6b6b18b62 Bump foreign-types-shared from 0.1.1 to 0.3.1 (#7691)
Bumps [foreign-types-shared](https://github.com/sfackler/foreign-types) from 0.1.1 to 0.3.1.
- [Release notes](https://github.com/sfackler/foreign-types/releases)
- [Commits](https://github.com/sfackler/foreign-types/commits/foreign-types-shared-v0.3.1)

---
updated-dependencies:
- dependency-name: foreign-types-shared
  dependency-version: 0.3.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-27 12:37:48 +09:00
fanninpm
7f8cdddbbf Add crates/* directories to Dependabot config (#7687) 2026-04-27 10:15:14 +09:00
Changjoon
625e5bf012 Report invalid \uXXXX escape position at the u character (#7676)
* Report invalid \uXXXX escape position at the u character

CPython's json decoder reports the position of the `u` specifier
when a \uXXXX escape fails to parse, but RustPython was reporting
the preceding `\`. For surrogate-pair cases (\uXXXX\uYYYY) the
second call was passing char_offset + next_char_i + 1, which
lands on the first hex digit of the first escape -- unrelated to
the actual failure site.

Pass next_char_i (position of the primary `u`) to the primary
decode_unicode call, and capture the second `u`'s char index from
the next_tuple peek to pass to the surrogate-pair decode_unicode
call.

Verified: 13 targeted probes across invalid-hex, short, and pair
cases now all match CPython positions. test.test_json 214 tests
pass with no regressions.

* Add regression test for invalid \uXXXX escape position

* Use raise AssertionError instead of assert False (B011)
2026-04-26 12:33:34 +09:00
Shahar Naveh
a2afaf0f13 Pin actions version to commit; force runner to use node 24 (#7685)
* Pin actions version to commit; force runner to use node 24

* Pin more
2026-04-26 12:32:37 +09:00
dependabot[bot]
956267c49e Bump aws-lc-rs from 1.16.2 to 1.16.3 (#7684)
Bumps [aws-lc-rs](https://github.com/aws/aws-lc-rs) from 1.16.2 to 1.16.3.
- [Release notes](https://github.com/aws/aws-lc-rs/releases)
- [Commits](https://github.com/aws/aws-lc-rs/compare/v1.16.2...v1.16.3)

---
updated-dependencies:
- dependency-name: aws-lc-rs
  dependency-version: 1.16.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-26 12:32:10 +09:00
Changjoon
be43bb6dbf Match CPython error type for non-ASCII struct format arguments (#7681)
* Match CPython error type for non-ASCII struct format arguments

Struct() raised the wrong exception type when the format argument
contained non-ASCII characters:
- str input with non-ASCII char: RustPython raised UnicodeDecodeError
  with an empty message; CPython raises UnicodeEncodeError as if
  format.encode('ascii') had been called directly.
- bytes input with non-ASCII byte: same wrong UnicodeDecodeError;
  CPython passes the bytes through to the format parser, which then
  errors with struct.error("bad char in struct format").

Restructure IntoStructFormatBytes::try_from_object to:
- raise UnicodeEncodeError("ascii", s, start, start+1, "ordinal not
  in range(128)") for non-ASCII str, with start computed as the
  first non-ASCII code point position (matching CPython's natural
  encoding-error format);
- raise struct.error("bad char in struct format") for non-ASCII bytes,
  produced via the existing new_struct_error helper.

Probed byte-identical with CPython 3.14.4 for both cases. Full
test.test_struct (43 tests) passes with no regressions. Sanity-tested
all standard format/pack/unpack/calcsize call shapes remain unchanged.

* Add regression test for non-ASCII format string error types

* Use raise AssertionError instead of assert False (B011)
2026-04-26 12:31:54 +09:00
dependabot[bot]
6ab1f806ba Bump actions/cache from 5.0.4 to 5.0.5 (#7649)
Bumps [actions/cache](https://github.com/actions/cache) from 5.0.4 to 5.0.5.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](668228422a...27d5ce7f10)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: 5.0.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-25 21:57:22 +09:00
Shahar Naveh
f0e23aacc2 Opcode descs not hardcoded (#7682)
* Add `::iterator()` for oparg enums

* adjust `get_special_method_names`

* Adjust intristic function 2 oparg

* Adjust intristic function 1 oparg

* Adjust binary operator oparg
2026-04-25 21:57:02 +09:00
fanninpm
a5f48eaaa1 Add sha1 to crypto dependency group (#7679) 2026-04-25 21:54:01 +09:00
Changjoon
b427f31164 Raise ValueError for None in required AST scalar fields (#7680)
Match CPython's "field 'X' is required for Y" error format when
required scalar AST fields receive None during ast_from_object
conversion. Previously these produced TypeError or a generic
"None disallowed in expression list" ValueError.

Fields covered (Alias.name, Arg.arg, Comprehension.target/iter,
Keyword.value, MatchCase.pattern, WithItem.context_expr,
YieldFrom.value): all now raise the CPython-compatible message
verbatim.

Add a get_node_field_required helper alongside the existing
get_node_field / get_node_field_opt and switch the eight call
sites that read these required scalar fields. The helper rejects
None with the proper ValueError before the value flows into the
type converter where Rust's strong typing would otherwise force a
generic catch-all error. Optional fields (read via
get_node_field_opt) and fields where None is valid (e.g.
Constant.value) are unaffected.

This complements the existing AST validator pass at
crates/vm/src/stdlib/_ast/validate.rs (hooked at _ast.rs:763):
the validator handles post-conversion semantic invariants
(ExprContext, empty body, cross-field rules) but cannot handle
required-scalar-field None because Rust's non-Option types reject
None at conversion time, before validation runs.

Verified byte-identical with CPython 3.14.4 for all seven probe
cases. test.test_ast.test_ast: 227 tests, expected failures
38 -> 36 (test_empty_yield_from and test_none_checks unmasked,
no regressions). test.test_compile: 0 regressions.
2026-04-25 21:53:37 +09:00
dependabot[bot]
7df0801db3 Bump rustls from 0.23.37 to 0.23.38 (#7678)
Bumps [rustls](https://github.com/rustls/rustls) from 0.23.37 to 0.23.38.
- [Release notes](https://github.com/rustls/rustls/releases)
- [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rustls/rustls/compare/v/0.23.37...v/0.23.38)

---
updated-dependencies:
- dependency-name: rustls
  dependency-version: 0.23.38
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-25 21:53:11 +09:00
dependabot[bot]
3a793ce716 Bump postcss from 8.5.3 to 8.5.10 in /wasm/demo (#7677)
Bumps [postcss](https://github.com/postcss/postcss) from 8.5.3 to 8.5.10.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.5.3...8.5.10)

---
updated-dependencies:
- dependency-name: postcss
  dependency-version: 8.5.10
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-25 21:52:59 +09:00
dependabot[bot]
adafaf222b Bump github/gh-aw from 0.62.5 to 0.68.3 (#7650)
* Bump github/gh-aw from 0.62.5 to 0.68.3

Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.62.5 to 0.68.3.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](48d8fdfddc...ce1794953e)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.68.3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix actionlint SC2129: use single group redirect block in upgrade-pylib.lock.yml

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/73a3a050-ff0b-45ad-b5fd-fcadec36239a

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

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@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-04-25 05:17:05 +09:00
dependabot[bot]
f6371de4a1 Bump rustls-webpki from 0.103.10 to 0.103.13 (#7674)
Bumps [rustls-webpki](https://github.com/rustls/webpki) from 0.103.10 to 0.103.13.
- [Release notes](https://github.com/rustls/webpki/releases)
- [Commits](https://github.com/rustls/webpki/compare/v/0.103.10...v/0.103.13)

---
updated-dependencies:
- dependency-name: rustls-webpki
  dependency-version: 0.103.13
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-25 05:16:34 +09:00
Changjoon
fb1218d6ba Accept surrogates in _json.JsonScanner decode path (#7675)
The _json decoder had two failure modes when a Python str value would
contain a lone surrogate (legal per the Python 3 str model):

1. Boundary UnicodeEncodeError: JsonScanner::Callable::call rejected
   any input str with surrogates via try_into_utf8 before scanning
   began.
2. Silent U+FFFD corruption: call_scan_once and parse_object's key
   path called .to_string() on scanstring's Wtf8Buf output, which
   routes through Wtf8::Display (lossy). Array values and dict keys
   decoded from JSON \uXXXX escapes silently became U+FFFD.

Switch JsonScanner's five PyUtf8StrRef signatures to PyStrRef, drop
the entry-point try_into_utf8 call, and feed Wtf8Buf directly to
new_str instead of going through .to_string(). Key memoization now
uses HashMap<Wtf8Buf, PyStrRef> so surrogate-bearing keys survive
interning. parse_number takes &[u8] since JSON numbers are ASCII.

Extends the WTF-8 refactor pattern established in #7673 to the
decoder. machinery::scanstring already returns Wtf8Buf and is
unchanged.

Unmasks test_single_surrogate_decode. 214 tests in test.test_json
pass with no regressions. Decoder output verified byte-identical to
CPython 3.13.4 over 10,000 random fuzz cases (JSON docs containing
random surrogate escapes at root/list/dict positions, compared via
json.dumps(..., ensure_ascii=True, sort_keys=True)).
2026-04-25 05:16:12 +09:00
dependabot[bot]
3f8a0b12eb Bump actions/github-script from 8.0.0 to 9.0.0 (#7661)
* Bump actions/github-script from 8.0.0 to 9.0.0

Bumps [actions/github-script](https://github.com/actions/github-script) from 8.0.0 to 9.0.0.
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](ed597411d8...3a2844b7e9)

---
updated-dependencies:
- dependency-name: actions/github-script
  dependency-version: 9.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix SC2129 shellcheck warning: group consecutive >> redirects into single block

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/dab79065-db94-41af-abb3-332d35557b29

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

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@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-04-25 05:15:31 +09:00
Changjoon
2e5c2be7fa Accept surrogates in _json.encode_basestring{,_ascii} (#7673)
encode_basestring/encode_basestring_ascii took PyUtf8StrRef, so
json.dumps(str_with_lone_surrogate) raised UnicodeEncodeError at the
Python/Rust boundary before write_json_string ran. CPython's encoder
emits \uXXXX under ensure_ascii=True and passes raw WTF-8 otherwise.

Switch to PyStrRef + s.as_wtf8(), matching scanstring in the same file.
Rewrite write_json_string to accept &Wtf8 and iterate
code_point_indices, emitting \uXXXX for surrogates in ascii mode and
passing their bytes through otherwise. Stop escaping 0x7F in the
ensure_ascii=False path (matches py_encode_basestring). Return Wtf8Buf
via the checked from_bytes so invariant breaks panic instead of UB.

Fuzzing also exposed two pre-existing ESCAPE_CHARS typos: 0x0B was
"\u000" and 0x1B was "\u001" (both missing trailing 'b'). Fixed here.

Verified byte-identical with CPython 3.13.4 over 16 manual + 10,000
random fuzz cases. Full test.test_json: 214 tests, 0 failures, 0
unexpected successes. Unmasks test_ascii_non_printable_encode and
test_single_surrogate_encode. Decoder path is a follow-up.
2026-04-25 00:08:14 +09:00
Shahar Naveh
0d67fd69e2 Relax rustyline version constraint (#7672) 2026-04-25 00:07:17 +09:00
Changjoon
952be48944 Unmask test_strftime_special and test_zones in datetimetester (#7671)
All three @unittest.skip("TODO: RUSTPYTHON") markers in
datetimetester.py are stale — the tests pass as written on current
main. Probed every assertion in each test body against both CPython
3.13.4 and RustPython: outputs are byte-identical for all unicode
passthrough cases (emoji, lone surrogates, surrogate pairs, null
bytes) in test_strftime_special and for all 11 FixedOffset
comparisons (utcoffset, tzname, dst, hash equality) in test_zones.

Full test.test_datetime run after unmasking: 1803 tests, 0 failures,
0 unexpected successes, 463 skipped (was 469 — 6 test-class inherited
runs now execute successfully).

Part of the skip-test inventory in #7611.
2026-04-25 00:07:06 +09:00
Changjoon
0913563bbe Raise ValueError for None in Stmt lists to match CPython validator (#7670)
Sibling fix to #7656 (which handled Vec<Expr>). The same catch-all
TypeError ("expected some sort of stmt, but got {}") in
Stmt::ast_from_object silently swallowed None, so compile() on an
AST with None in a statement-list field (ClassDef.body, Try.body,
For.body, etc.) raised TypeError where CPython raises
ValueError("None disallowed in statement list").

Add an is_none check before the catch-all, matching the Expr-side
shape introduced in #7656. Option<Stmt> positions are unaffected —
they short-circuit None earlier in node.rs.

Unmasks test_classdef (body=[None] sub-case). Full
test.test_ast.test_ast run: 227 tests, 0 unexpected successes, 38
expected failures (was 39).
2026-04-25 00:06:53 +09:00
Changjoon
1ab76d012b Fix ShellCheck findings in lib-deps-check and update-doc-db workflows (#7669)
Clear four of the five ShellCheck findings reported in #7653. The
fifth finding is in upgrade-pylib.lock.yml — a gh-aw-generated file
marked "DO NOT EDIT" whose source .md does not contain the flagged
pattern — and is out of scope here; it will resolve via the in-flight
gh-aw version bump (#7650).

lib-deps-check.yaml:
  * SC2076: replace `=~ " $module "` (quoted regex interpreted
    literally) with `== *" $module "*` glob match. Same intent
    (literal substring), same semantics across regex metachars.
  * SC2086: quote `$GITHUB_OUTPUT` in the output redirect.

update-doc-db.yml:
  * SC2129: collapse the eight sequential `echo ... >> $OUTPUT_FILE`
    lines (plus one `cat ... >> $OUTPUT_FILE`) into a single grouped
    redirect `{ ...; } > "$OUTPUT_FILE"`. Drops the now-redundant
    `echo -n '' > $OUTPUT_FILE` truncate.
  * SC2016: add `# shellcheck disable=SC2016` above the block; the
    backticks in the auto-generated-header comment are literal
    Markdown, not command substitution.

Verified locally with shellcheck 0.11.0: both modified blocks
produce no ShellCheck output. Semantic equivalence of the
lib-deps-check change confirmed across six test inputs including
regex metachars and glob-meaningful characters.
2026-04-25 00:06:23 +09:00
dependabot[bot]
f0acc67855 Bump https://github.com/astral-sh/ruff-pre-commit (#7668)
Bumps [https://github.com/astral-sh/ruff-pre-commit](https://github.com/astral-sh/ruff-pre-commit) from v0.15.7 to 0.15.11.
- [Release notes](https://github.com/astral-sh/ruff-pre-commit/releases)
- [Commits](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.7...v0.15.11)

---
updated-dependencies:
- dependency-name: https://github.com/astral-sh/ruff-pre-commit
  dependency-version: 0.15.11
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-25 00:05:24 +09:00
dependabot[bot]
9ebdf10c11 Bump https://github.com/rbubley/mirrors-prettier from v3.8.1 to 3.8.3 (#7667)
Bumps [https://github.com/rbubley/mirrors-prettier](https://github.com/rbubley/mirrors-prettier) from v3.8.1 to 3.8.3.
- [Commits](https://github.com/rbubley/mirrors-prettier/compare/v3.8.1...v3.8.3)

---
updated-dependencies:
- dependency-name: https://github.com/rbubley/mirrors-prettier
  dependency-version: 3.8.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-25 00:05:06 +09:00
Roman
7bb2fb0755 Fix pyclass memory layout to prevent silent UB in inherited getter dispatch (#7663) 2026-04-24 23:30:23 +09:00
dependabot[bot]
43ef2eabbe Bump indexmap from 2.13.0 to 2.14.0 (#7666) 2026-04-24 07:54:37 -04:00
Joshua Megnauth
dc0c814671 Match CPython's islower/isupper exactly (#7646)
This PR fixes a regression from my last islower/isupper patch.
Python's Bytes doesn't assume an encoding, so methods like islower
should only consider ASCII casing.

I updated islower/isupper for UTF-8 and WTF-8 to match CPython more
closely. The two functions now use the same properties as CPython and
now match CPython exactly.

I updated the unit tests to pass on Python 3.15. Unicode updates
sometimes cause properties to shift. I previously tested everything on
Python 3.14, but that lead to failures that I assumed were bugs but were
actually due to Unicode differences. For example, U+0295 is a lower case
letter in older Unicode versions but is NOT in newer versions.

One of the new tests is disabled on Python 3.14 for now because it will
fail in CI till CI is bumped to 3.15.
2026-04-24 13:30:02 +09:00
fanninpm
a7ea01a135 Change dependency groups (#7665)
* Add `ahash` to `random` group

* Add `unix` group with `nix`, `mac_address`, and `rustyline`
2026-04-24 13:29:07 +09:00
dependabot[bot]
cbfb313de2 Bump rustls-platform-verifier from 0.6.2 to 0.7.0 (#7664)
Bumps [rustls-platform-verifier](https://github.com/rustls/rustls-platform-verifier) from 0.6.2 to 0.7.0.
- [Release notes](https://github.com/rustls/rustls-platform-verifier/releases)
- [Changelog](https://github.com/rustls/rustls-platform-verifier/blob/main/CHANGELOG)
- [Commits](https://github.com/rustls/rustls-platform-verifier/compare/v/0.6.2...v/0.7.0)

---
updated-dependencies:
- dependency-name: rustls-platform-verifier
  dependency-version: 0.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-24 09:10:30 +09:00
dependabot[bot]
adb169e65b Bump webpki-roots from 1.0.6 to 1.0.7 in the webpki-root group (#7662)
Bumps the webpki-root group with 1 update: [webpki-roots](https://github.com/rustls/webpki-roots).


Updates `webpki-roots` from 1.0.6 to 1.0.7
- [Release notes](https://github.com/rustls/webpki-roots/releases)
- [Commits](https://github.com/rustls/webpki-roots/compare/v/1.0.6...v/1.0.7)

---
updated-dependencies:
- dependency-name: webpki-roots
  dependency-version: 1.0.7
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: webpki-root
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-24 07:51:38 +09:00
dependabot[bot]
5081f76faf Bump openssl from 0.10.77 to 0.10.78 (#7659)
Bumps [openssl](https://github.com/rust-openssl/rust-openssl) from 0.10.77 to 0.10.78.
- [Release notes](https://github.com/rust-openssl/rust-openssl/releases)
- [Commits](https://github.com/rust-openssl/rust-openssl/compare/openssl-v0.10.77...openssl-v0.10.78)

---
updated-dependencies:
- dependency-name: openssl
  dependency-version: 0.10.78
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-24 02:01:17 +09:00
Changjoon
f2e055f7d6 Raise ValueError for None in Expr lists to match CPython validator (#7656)
* Raise ValueError for None in Expr lists to match CPython validator

CPython raises ValueError("None disallowed in expression list") when
compile() encounters None as an element in a Vec<Expr> position
(Set/List/Tuple.elts, BoolOp.values, Call.args, comprehension generators,
etc.). RustPython reached the catch-all TypeError("expected some sort of
expr, but got {}") branch instead, failing a dozen test_ast validator
tests.

Add an explicit is_none() check in Expr::ast_from_object before the
catch-all so None short-circuits with the CPython-compatible ValueError.
Option<Expr> positions (e.g. Dict.keys for **unpack) are unaffected
since node.rs Option<T>::ast_from_object handles None earlier.

Unmasks 12 skip / expectedFailure markers in
Lib/test/test_ast/test_ast.py:
- test_boolop, test_set, test_list, test_tuple
- test_call, test_delete, test_assign
- test_dict, test_dictcomp, test_generatorexp, test_listcomp, test_setcomp

Addresses part of the skip-test inventory in #7611.

The Stmt-level analog (body=[None] -> "None disallowed in statement list",
used by test_classdef) needs a sibling change in statement.rs; out of
scope here.

* Drop redundant .to_owned() on new_value_error argument

Matches the other new_value_error call sites in the file.

Co-authored-by: Shahar Naveh <50263213+ShaharNaveh@users.noreply.github.com>

---------

Co-authored-by: Shahar Naveh <50263213+ShaharNaveh@users.noreply.github.com>
2026-04-23 15:32:33 +09:00
Shahar Naveh
f2f20175b3 oparg_enum! to support custom display value (#7654) 2026-04-23 15:32:01 +09:00
dependabot[bot]
a693a0c8aa Bump uuid from 1.22.0 to 1.23.0 (#7565)
* Bump uuid from 1.22.0 to 1.23.0

Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.22.0 to 1.23.0.
- [Release notes](https://github.com/uuid-rs/uuid/releases)
- [Commits](https://github.com/uuid-rs/uuid/compare/v1.22.0...v1.23.0)

---
updated-dependencies:
- dependency-name: uuid
  dependency-version: 1.23.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix CI for uuid 1.23.0 Context deprecation

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/bec0d567-f41e-407f-bf99-0463ca555f74

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

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@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-04-23 15:26:19 +09:00
Changjoon
71380bead9 Fix process abort on large float format precision (#7633)
* Fix process abort on large float format precision

Formatting a float with large precision (>= ~65535) aborted the
interpreter instead of raising a Python exception. CPython handles
the same input by returning a clean string.

  # Before
  ./rustpython -c "print(f'{1.5:.1000000}')"
  thread 'main' panicked at crates/literal/src/float.rs:135:
  Formatting argument out of range   (exit 101, abort)

  # After
  ./rustpython -c "print(f'{1.5:.1000000}')"
  1.5

Root cause: Rust's `format!("{:.*}", n, x)` panics when `n`
exceeds the fmt runtime's internal precision limit. `format_fixed`
already caps `n` at u16::MAX, but `format_general` and
`format_exponent` (and the `%` branch in `crates/common/src/format.rs`)
passed user-supplied precision straight through to `format!`.

Fix:

  * Introduce `FMT_MAX_PRECISION` + `clamp_fmt_precision()` in
    crates/literal/src/float.rs. Cap is `u16::MAX - 1` because
    `{:.*e}` hits a second panic (`ndigits > 0` in core flt2dec)
    at exactly u16::MAX; the smaller value covers both paths.
  * Apply the helper to `format_fixed` (replacing the existing
    ad-hoc cap), `format_exponent` (entry), and `format_general`
    (three separate format! calls with saturating arithmetic on
    derived precision values).
  * Apply the helper in the `FormatType::Percentage` branch in
    crates/common/src/format.rs.

This is harmless for all normal inputs — f64 carries only ~17
significant digits, so precision beyond 65K is padding zeros at
best. Complex-number and old-style `%`-formatting paths transitively
benefit because they dispatch to the same library functions.

Verified:

  * cargo run -- -m test test_float test_fstring test_format:
    144 passed, 0 regressed.
  * extra_tests/snippets/builtin_format.py: all assertions pass,
    including 7 new regression cases covering e / E / g / G / f /
    % at precision 1_000_000.
  * Probed with 10 magnitude values (0, ±1.5, ±inf, nan, 1e-300,
    1e300, f64::MAX, 5e-324) x 4 format types = 40 combinations,
    plus precision 0/1/2 boundary, complex formatting, old-style
    `%` formatting, and combined specs (fill/align/sign/grouping/
    zero-pad). All return clean strings; no process abort.

* Address CodeRabbit review: split cap + drop redundant clamp

Two refinements after CodeRabbit review:

1. Drop the redundant `format!("{:.*}", precision + 1, base)` in
   `format_general`'s scientific branch. It was a no-op pre-fix
   (magnitude is `.abs()`-ed at the caller, so `base` has no sign
   and its length was exactly `precision + 1`), but after I added
   the cap it turned into an active truncate — dropping 1 char of
   precision at the cap boundary. Reuse `base` directly and extract
   `exp_precision` for reuse by `decimal_point_or_empty`.

2. Split the cap into two helpers.

   `FMT_MAX_PRECISION = u16::MAX`           — for plain `{:.*}` (format_fixed,
                                                 %-branch, format_general's
                                                 non-scientific branch).
   `FMT_MAX_EXP_PRECISION = u16::MAX - 1`   — for `{:.*e}` (format_exponent,
                                                 format_general's scientific
                                                 entry).

   The second value is one lower because `{:.*e}` trips an additional
   `ndigits > 0` assertion in `core::num::flt2dec` at exactly
   `u16::MAX`. The first commit used the tighter cap uniformly,
   which silently regressed `format_fixed` by 1 char at
   `precision == u16::MAX` (it previously capped at exactly that
   value). Two helpers restore byte-identical CPython parity for
   fixed / percent / general-non-scientific paths up through
   `precision == u16::MAX`.

Verification:
  * precision 5 .. 65534:  360 outputs byte-identical to CPython
                           across 8 magnitudes x 9 precisions x 5 types.
  * precision == 65535:    f / g / G / % now match CPython (0 diff).
                           e / E remain 1 char shorter — unavoidable
                           within the `u16::MAX - 1` exp cap.
  * precision > 65535:     output stops at cap; CPython emits full
                           padding — same design divergence as before.
  * No panic regression:   f-string default, e/E, g/G, %, f at
                           precision 1_000_000 all return cleanly.
  * Test suite:            test_float + test_fstring + test_format,
                           162 passed, 0 regressed.

* Fix ruff format: single-line precision clamp

* Address @youknowone review: byte-identical CPython parity at boundary

Per review comment on `extra_tests/snippets/builtin_format.py:209`:
the patch declares `FMT_MAX_PRECISION = u16::MAX`, so the tests must
cover 65535 and 65536 and demonstrate CPython parity at the boundary.

The previous version only avoided panic — at the cap it silently
truncated 1 char short of CPython for e / E, and thousands of chars
short for f / %  at precision beyond the cap. This commit restores
byte-identical CPython output at every precision up to the format-
spec parser's own `i32::MAX` ceiling.

Fix: pad the Rust-format result with '0's up to the user-requested
precision.

Why this is correct, not a workaround: IEEE 754 double has at most
~767 significant decimal digits; past that, every digit is
deterministically '0' in both CPython and the native Rust output.
Our cap (65534 for exp, 65535 for plain) sits far above 767, so
appending zeros reconstructs precisely what CPython would have
produced. Verified on hard inputs: `1e-100`, `5e-324` (subnormal
boundary), `f64::MAX`, mixed magnitudes — the last 100 chars of
Rust-format output at precision 65534 are all '0' for every case.

Changes:

  * `format_fixed`: after format!(), extend with (precision - capped)
    '0' chars before appending the optional decimal point.
  * `format_exponent`: same, applied to the parsed mantissa before
    reassembling with the exponent marker.
  * `FormatType::Percentage` branch: same. Also fixed a bug the
    boundary audit surfaced: the finite-input overflow guard used
    `return Ok("inf%")`, which bypasses the outer sign handler.
    Changed to a match-arm value so `format_sign_and_align` still
    runs and produces "-inf%" for `-f64::MAX`, matching CPython.

Verification:

  * 7 magnitudes × 5 precisions × 6 format types = 210 comparisons
    against CPython at precisions {65534, 65535, 65536, 100000,
    200000}. All 210 byte-identical.
  * Gap audit (complex formatting, old-style % formatting, negative
    magnitudes, -0.0, combined specs with fill / sign / alternate /
    grouping) at boundary precisions. All but 20 byte-identical.
    The 20 remaining diffs all stem from a pre-existing
    complex-imaginary-part repr bug (`1e100j` expands to 100 '0's
    in RustPython vs CPython's `1e+100j`) which reproduces on
    upstream main without any part of this patch and is out of
    scope here.
  * `cargo run -- -m test test_float test_fstring test_format`:
    162 passed, 0 regressed.
  * `extra_tests/snippets/builtin_format.py` now pins exact
    expected strings at 65534 / 65535 / 65536 / 1_000_000 for
    every format type, plus the `f64::MAX × 100 → 'inf%'`
    overflow case.
  * `cargo fmt --check`: pass.

* Clarify boundary test labels + add past-cap depth assertions

Rename the boundary-test section so the three precision points per
format type are labeled below / at / past the cap inline, making the
"past MAX_PRECISION" unhappy-case coverage explicit. Add len-based
assertions at precision 1_000_000 for f, e, and % to exercise the
cap-then-pad path at a depth far beyond the boundary.
2026-04-23 15:25:52 +09:00
dependabot[bot]
5a45d41df0 Bump cranelift from 0.130.0 to 0.130.1 in the wasmtime group (#7652)
Bumps the wasmtime group with 1 update: [cranelift](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift` from 0.130.0 to 0.130.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.130.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-22 08:09:28 +09:00
dependabot[bot]
9b0c668f74 Bump cargo-bins/cargo-binstall from 1.17.9 to 1.18.1 (#7651)
Bumps [cargo-bins/cargo-binstall](https://github.com/cargo-bins/cargo-binstall) from 1.17.9 to 1.18.1.
- [Release notes](https://github.com/cargo-bins/cargo-binstall/releases)
- [Changelog](https://github.com/cargo-bins/cargo-binstall/blob/main/release-plz.toml)
- [Commits](0b24824336...dc19f1e484)

---
updated-dependencies:
- dependency-name: cargo-bins/cargo-binstall
  dependency-version: 1.18.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-22 08:09:16 +09:00
Shahar Naveh
dc65255fd2 Use cfg_select! (#7636) 2026-04-21 17:35:26 +00:00
Pravin
a9fd4bf41f Bump rust version to 1.94.0 (#7442) 2026-04-22 00:01:09 +09:00
dependabot[bot]
5058090a3f Bump zizmorcore/zizmor-action from 0.5.2 to 0.5.3 (#7638)
Bumps [zizmorcore/zizmor-action](https://github.com/zizmorcore/zizmor-action) from 0.5.2 to 0.5.3.
- [Release notes](https://github.com/zizmorcore/zizmor-action/releases)
- [Commits](71321a20a9...b1d7e1fb5d)

---
updated-dependencies:
- dependency-name: zizmorcore/zizmor-action
  dependency-version: 0.5.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-21 23:59:54 +09:00
Jeong, YunWon
b929a50647 compiler parity for typealias (#7645) 2026-04-21 23:59:20 +09:00
dependabot[bot]
f8862e4eed Bump j178/prek-action from 2.0.1 to 2.0.2 (#7637)
Bumps [j178/prek-action](https://github.com/j178/prek-action) from 2.0.1 to 2.0.2.
- [Release notes](https://github.com/j178/prek-action/releases)
- [Commits](53276d8b0d...cbc2f23eb5)

---
updated-dependencies:
- dependency-name: j178/prek-action
  dependency-version: 2.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-21 22:32:27 +09:00
dependabot[bot]
18c6c16e2a Bump the openssl group with 2 updates (#7643)
Bumps the openssl group with 2 updates: [openssl](https://github.com/rust-openssl/rust-openssl) and [openssl-sys](https://github.com/rust-openssl/rust-openssl).


Updates `openssl` from 0.10.76 to 0.10.77
- [Release notes](https://github.com/rust-openssl/rust-openssl/releases)
- [Commits](https://github.com/rust-openssl/rust-openssl/compare/openssl-v0.10.76...openssl-v0.10.77)

Updates `openssl-sys` from 0.9.112 to 0.9.114
- [Release notes](https://github.com/rust-openssl/rust-openssl/releases)
- [Commits](https://github.com/rust-openssl/rust-openssl/compare/openssl-sys-v0.9.112...openssl-sys-v0.9.114)

---
updated-dependencies:
- dependency-name: openssl
  dependency-version: 0.10.77
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: openssl
- dependency-name: openssl-sys
  dependency-version: 0.9.114
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: openssl
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-21 22:32:11 +09:00
Copilot
d5921d16af Create rustpython-host-env (#7582)
* Create rustpython-host-env crate; move host abstractions out of common

Move os, crt_fd, fileutils, windows, macros modules from
rustpython-common into the new rustpython-host-env crate.
This isolates host OS API wrappers behind a crate boundary
with zero Python runtime dependency.

- Add crates/host_env to workspace
- Drop nix, windows-sys, widestring deps from common
- Wire vm and stdlib to depend on rustpython-host-env
- Migrate all imports from common::{os,crt_fd,fileutils,windows}
  to rustpython_host_env::

* refactor: extract host helpers

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/48d1e64d-37ce-409f-b511-8e61a349665c

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

* lint: enforce direct host API boundaries

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/97225fb7-7b3d-4197-a77c-eb44aead5b13

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

* refactor: extract remaining host env helpers

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/d96f57e1-b196-4460-9983-97d5ff118835

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

* fix: clean extracted host env follow-up

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/d96f57e1-b196-4460-9983-97d5ff118835

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

* fix: document env mutation safety

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/d96f57e1-b196-4460-9983-97d5ff118835

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

* refactor: split host fs helpers from fileutils

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/c57424c5-0e1d-490a-82b3-2d2f6c8cf2cd

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

* fix: resolve latest host env ci regressions

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/899eb717-ebc6-4a4a-870c-2a15c5f33e02

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

* fix: resolve remaining windows clippy host fs calls

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/12f32740-8173-4b10-a1d6-00b29e90a8ec

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

* host_env

---------

Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2026-04-21 00:13:25 +09:00
Jeong, YunWon
9140ef583a Bytecode parity - boolop, comprehension, CFG passes (#7631)
* Bytecode parity - boolop, comprehension, CFG passes

- Flatten nested same-op BoolOp and add IfExpr to jump_if
- Simplify is_name_imported to module-level only
- Enable inlined comprehensions in module/class scope
- Add TweakInlinedComprehensionScopes with fast_hidden tracking
- Track fb_range in FBlockInfo for with-statement line info
- Add constant subscript folding and unary Not folding
- Add emit_return_const_no_location for implicit returns
- Use JumpNoInterrupt for ternary/except jumps
- Add STACK_USE_GUIDELINE threshold for collection building
- Reorder CFG pipeline: inline small blocks earlier, resolve
  line numbers before cold block extraction
- Add redirect_empty_unconditional_jump_targets,
  reorder_conditional_chain_and_jump_back_blocks,
  materialize_empty_conditional_exit_targets,
  duplicate_shared_jump_back_targets passes
- Add borrow deoptimization for multi-handler, named-except,
  protected conditional tail, and protected import joins
- Run folding/optimization passes twice around peephole

* Bytecode parity - slice augassign, async comp inline

- Augmented assignment with two-part slices uses BINARY_SLICE/STORE_SLICE
- Inline async comprehensions (remove await/async guards)
- Inlined comprehension cleanup jump uses JumpNoInterrupt
- Class firstlineno uses first decorator line when decorated
- Recurse into nested functions for static attribute collection
- Fold unary positive complex constants (+0.0j)
- Add deoptimize_borrow_for_folded_nonliteral_exprs pass
- Add inline_single_predecessor_artificial_expr_exit_blocks pass
- Skip shared artificial expr-stmt exit blocks in small-block inlining
- Mark folded boolop tail as folded_from_nonliteral_expr

* apply reviews
2026-04-21 00:10:00 +09:00
Changjoon
af41d11faf Fix complex repr to use scientific notation for large integer-valued components (#7634)
* Fix complex repr to use scientific notation for large integer-valued components

repr of a complex number whose real or imaginary part is an integer-valued
float with |x| >= 1e16 emitted the full decimal expansion instead of
scientific notation, diverging from CPython:

  Before (RustPython):
    repr(1e100 + 1e100j)
      (10000000000000000000000000000000000000000000000000000000000
       0000000000000000000000000000000000000000000+1000000000000000
       000000000000000000000000000000000000000000000000000000000000
       00000000000000000000000000000000000000j)

  After / CPython:
    (1e+100+1e+100j)

Root cause in crates/literal/src/complex.rs::to_string — it bifurcated
each component by .fract() == 0.0:

  if im.fract() == 0.0 { im.to_string() }       // Rust's default Display
  else                 { float::to_string(im) } // scientific for large/small

Rust's Display never uses scientific notation, so any integer-valued f64
(including 1e16, 1e17, 1e100 which are exactly representable as integers)
routed through the wrong branch and produced the full decimal expansion.
Non-integer magnitudes reached float::to_string and rendered correctly.

The fix is to use one helper per component that implements CPython's
actual PyOS_double_to_string(format='r') rule: scientific notation when
|x| < 1e-4 or |x| >= 1e16, otherwise Rust's default Display (which drops
the trailing '.0' for integer-valued floats — matching CPython's
(1+2j) convention rather than (1.0+2.0j)). The threshold matches
float::to_string; the only behavioral difference is that complex
components render 1.0 as "1" rather than "1.0".

Verified:
  * 29 CPython reference cases (normal / boundary / extremes / special /
    signed-zero) — all byte-identical after fix.
  * 18 additional edge cases (subnormal 5e-324, f64::MAX, MIN_POSITIVE,
    DBL_EPSILON, threshold-straddling values) — all byte-identical.
  * Lib/test/test_complex.py::test_repr_str /
    test_negative_zero_repr_str / test_repr_roundtrip — all pass.
  * cargo run -- -m test test_complex — 37 passed.
  * cargo run -- -m test test_float test_long — 101 passed.
  * ast.unparse() round-trip of source containing complex literals
    (e.g. 1e100 + 1e-100j, 1e17 + 1j) produces CPython-identical output.
  * extra_tests/snippets/builtin_complex.py — 20+ new regression cases.

* Address CodeRabbit review: clarify threshold boundary test comment

The comment claimed all three assertions stay in non-scientific form,
but the 1e-5 case explicitly verifies scientific notation (since
|1e-5| < 1e-4 falls outside the decimal-form range). Reworded the
header to describe the axis being tested (threshold boundary) and
added per-case inline notes indicating each assertion's expected
form.
2026-04-20 21:56:41 +09:00
Changjoon
175f12b664 Fix stack overflow on deeply-nested JSON in json.loads() (#7632)
* Fix stack overflow on deeply-nested JSON in json.loads()

json.loads() on a deeply-nested array or object payload (e.g.
'[' * 50000 + ']' * 50000) overflowed the native Rust stack and
crashed the interpreter process with SIGSEGV. CPython raises
RecursionError on the same input via _Py_EnterRecursiveCall in
Modules/_json.c.

The recursion lives in the mutual call chain:
  JsonScanner::parse_object / parse_array
    -> JsonScanner::call_scan_once
      -> JsonScanner::parse_object / parse_array

Every descent funnels through call_scan_once, so wrapping its body
with vm.with_recursion covers both '{' and '[' paths (and their
mixed nesting) with a single guard.

Before:
  ./rustpython -c "import json; json.loads('[' * 50000 + ']' * 50000)"
    -> SIGSEGV (exit 139)

After:
  -> RecursionError: maximum recursion depth exceeded while
     decoding a JSON object from a string

Verified:
  - extra_tests/snippets/stdlib_json.py: all assertions pass
    (includes 3 new regression cases: array, object, alternating
    nesting at depth 100000)
  - cargo run -- -m test test_json: 214 passed, 0 regressed
    (9 skipped, 13 expected failures, all pre-existing)
  - depth 500000 no longer crashes (RecursionError)
  - shallow parsing unchanged

* Enable test_highly_nested_objects_decoding

Per @ShaharNaveh's review on #7632: this test was previously marked
`@unittest.skip("TODO: RUSTPYTHON; crashes")` because json.loads
would SIGSEGV on the 500_000-deep input. The recursion-guard added
in this PR makes it raise RecursionError like CPython, so the skip
decorator can be removed.

  $ cargo run -- -m unittest \
        test.test_json.test_recursion.TestCRecursion.test_highly_nested_objects_decoding \
        test.test_json.test_recursion.TestPyRecursion.test_highly_nested_objects_decoding
  ...
  Ran 2 tests in 0.825s
  OK

  $ cargo run -- -m test test_json
  Ran 214 tests (7 skipped, 13 expected failures) — all pass.
2026-04-20 21:52:17 +09:00
Shahar Naveh
b18b71b2db Auto-retry flaky MP tests (#7603) 2026-04-19 10:37:22 -04:00
Changjoon
fdb49d83c5 Fix segfault on cyclic or deeply-nested AST in compile() (#7630) 2026-04-19 22:35:09 +09:00
Shahar Naveh
37707081f8 Update test_named_expressions.py from 3.14.4 (#7629) 2026-04-19 22:33:51 +09:00
Shahar Naveh
764e4de061 Update test_descr.py and test_decorators.py from 3.14.4 (#7628)
* Update `test_descr.py` and `test_decorators.py` from 3.14.4

* Mark failing tests

* Use correct test marker
2026-04-19 22:33:27 +09:00
Changjoon
b842a6c6c6 Fix struct_time field overflow to raise OverflowError in time module (#7627)
* Fix struct_time field overflow to raise OverflowError in time module

* Address CodeRabbit review: cover tm_gmtoff and chain AssertionError

* Fix ruff format: single space before inline comment
2026-04-19 22:32:57 +09:00
Joshua Megnauth
9669118d3c Use Unicode properties for alnum, alpha, etc. (#7626)
Rust and Python differ in which properties they use for alphanumeric,
numeric, et cetera. Both languages list which properties are used which
makes it easy to mimic Python's behavior in Rust.

My previous patch was a bit shortsighted because I filtered out
combining characters from is_alphanumeric. Using properties is exact and
also much cleaner. It also covers edge cases that my initial approach
missed.

Besides isalnum, I also fixed isnumeric and isdigit in the same way by
using properties.
2026-04-19 14:10:00 +09:00
Changjoon
67eedddcd7 Fix error messages in binary/ternary ops to match CPython format (#7625)
* Fix `divmod` error message to match CPython format

* Fix ternary op error message separator to match CPython
2026-04-19 09:15:12 +09:00
Changjoon
57ca1d59a6 Update test_base64.py from 3.14.4 (#7624) 2026-04-19 09:14:46 +09:00
Changjoon
9a0410dab4 Update test_cmath.py from 3.14.4 (#7623) 2026-04-19 09:14:35 +09:00
Jeong, YunWon
b80c2bd5ec Merge pull request #7622 from youknowone/bytecode-parity-string 2026-04-18 17:52:34 +09:00
Jeong, YunWon
a5b9f0e80b refactro 2026-04-18 17:20:08 +09:00
Jeong, YunWon
caf8d55da5 Bytecode parity - folding, class prologue, except cleanup
Constant folding:
- Add string/bytes multiply and bytes concat folding in IR
- Add constant subscript folding (str, bytes, tuple indexing)
- Delegate list/set constant folding to IR passes
- Stream big non-const list/set via BUILD+LIST_APPEND

Class/generic compilation:
- Reorder class body prologue: __type_params__ before __classdict__
- Build class function before .generic_base in generic classes
- Register .type_params/.generic_base symbols in proper scopes
- Use load_name/store_name helpers for synthetic variables

Return block handling:
- Only duplicate return-None epilogues, not arbitrary returns
- Add inline_pop_except_return_blocks pass
- Add duplicate_named_except_cleanup_returns pass

Other fixes:
- Fix eliminate_dead_stores to only collapse adjacent duplicates
- Skip STORE_FAST_LOAD_FAST superinstruction in generators after FOR_ITER
- Thread jumps through NOP-only blocks
- Transfer NOP line info to following unconditional jumps
- Extract scope_needs_conditional_annotations_cell helper
- Register __conditional_annotations__ for module future annotations
2026-04-18 15:17:56 +09:00
Jeong, YunWon
c79baa3317 Fix for-loop target NOP and t-string stack order
- Remove unnecessary NOP between FOR_ITER and unpack/store
  by compiling loop target directly on target range
- Fix t-string compilation to match stack order: build
  strings tuple first, then evaluate interpolations
- Split compile_tstring_into into collect_tstring_strings
  and compile_tstring_interpolations
- Handle debug text literals and default repr conversion
  for debug specifier in t-strings
- Always set bit 1 in BUILD_INTERPOLATION oparg encoding
2026-04-18 10:18:30 +09:00
Jeong, YunWon
f0bf8100c9 Inline with-suppress return blocks and extend return duplication
- Add inline_with_suppress_return_blocks pass to inline return
  epilogues after with-suppress cleanup sequences
- Extend duplicate_end_returns to handle conditional jumps to the
  final return block, not just unconditional ones
- Process jump targets in reverse order to preserve indices
- Add extra deoptimize_store_fast_store_fast pass after superinstructions
- Add tests for listcomp cleanup tail and with-suppress tail
2026-04-18 09:37:38 +09:00
Jeong, YunWon
1f1be5e29e Align bytecode codegen structure with CPython 3.14 (#7588)
* Align bytecode codegen structure with CPython 3.14

* Bytecode parity - constant folding, annotation ordering, superinstruction alignment

- Add BoolOp constant folding with short-circuit semantics in compile_expression
- Add constant truthiness evaluation for assert statement optimization
- Disable const collection/boolop folding in starred unpack and assignment contexts
- Move annotation block generation after body with AnnotationsPlaceholder splicing
- Reorder insert_superinstructions to run before push_cold_blocks (matching flowgraph.c)
- Lower LOAD_CLOSURE after superinstructions to avoid false LOAD_FAST_LOAD_FAST
- Add ToBool before PopJumpIf in comparisons and chained compare cleanup blocks
- Unify annotation dict building to always use incremental BuildMap + StoreSubscr
- Add TrueDivide constant folding for integer operands
- Fold constant sets to Frozenset (not Tuple) in try_fold_constant_collection
- Add PyVmBag for frozenset constant materialization in code objects
- Add remove_redundant_const_pop_top_pairs pass and peephole const+branch folding
- Emit Nop for skipped constant expressions and constant-true asserts
- Preserve comprehension local ordering by source-order bound name collection
- Simplify annotation scanning in symboltable (remove simple-name gate)

* Fix CI regressions in marshal and fast-local ops

* impl more

* Align bytecode codegen with CPython structure

* Bytecode parity - comprehension/except scope ordering, load_fast_borrow fixes

- Reorder comprehension symbol-table walk so the outermost iterator
  registers its sub_tables in the enclosing scope before the comp
  scope, and rescan elt/ifs in CPython's order. Codegen peeks past the
  outermost iterator's nested scopes to find the comprehension table.
- For plain try/except, emit handler sub_tables before the else block
  so codegen's linear sub_table cursor stays aligned.
- Rename `collect_simple_annotations` to `collect_annotations` and
  evaluate non-simple annotations during __annotate__ compilation to
  preserve source-order side effects while keeping the simple-name
  index stable.
- Dedupe equivalent code constants in `arg_constant` and add a
  structural equality check on `CodeObject`.
- Disable LOAD_FAST_BORROW for the tail end block when a try has a
  bare `except:` clause, and have `new_block` inherit the flag from
  the current block.
- Remove `cfg!(debug_assertions)` guard around the
  `optimize_load_fast_borrow` start-depth check so mismatches are
  handled (return instead of assert) in release builds.
- Collapse nop-only blocks that precede a return epilogue and hoist
  the prior line number into the next real instruction so the
  line table matches.
- Unmark now-passing `test_consts_in_conditionals`,
  `test_load_fast_unknown_simple`,
  `test_load_fast_known_because_already_loaded`, and PEP 646 f3/f4
  annotation checks.

* Bytecode parity - try/except line tracking, assert 0 shape

- In `compile_try_except`, drop the leading Nop and set the end
  block's source range from the last orelse/body statement so line
  events after the try fall on the right line.
- Recognise constant-false asserts as the direct-raise shape (no
  ToBool/PopJumpIfFalse) and flip the test assertion accordingly.
- Extend `remove_redundant_nops_in_blocks` to also look through a
  trailing nop before a return-epilogue pair (LoadConst/ReturnValue
  or LoadSmallInt/ReturnValue) so the epilogue keeps the correct
  line number.
- Rename `preds` to `predecessor_blocks` in the LOAD_FAST_BORROW
  disable pass and add a test-only `debug_late_cfg_trace` helper.
- Regenerate the `nested_double_async_with` snapshot: the tail
  reference to `stop_exc` now emits LOAD_FAST instead of
  LOAD_FAST_BORROW.

* Bytecode parity - iter folding, break/continue line, cold inlining

- Fold a constant list iterable into a constant tuple in for-loop
  iterable position, matching the CPython optimizer, and strip a
  redundant LIST_TO_TUPLE immediately before GET_ITER in the IR
  peephole pass.
- Emit a Nop at the break/continue source range before unwinding
  so line events land on the break/continue statement instead of
  the following instruction.
- Drop `propagate_disable_load_fast_borrow`; the forward propagation
  was over-zealous and the per-block inheritance in `new_block` plus
  the bare-except marker are enough.
- Relax `inline_small_or_no_lineno_blocks` so small exit blocks at
  the tail of a cold block are always inlined, not just return
  epilogues.
- Add codegen tests covering the LIST_TO_TUPLE/GET_ITER peephole and
  the late-CFG trace helper for a for-loop list-literal iterable.
2026-04-18 09:19:11 +09:00
Shahar Naveh
4f1cf6d401 Fix reviewdog permissions (#7619) 2026-04-17 20:07:19 +09:00
Shahar Naveh
3e1aa7cbe6 Update test_itertools.py from 3.14.4 (#7618) 2026-04-17 20:06:48 +09:00
Shahar Naveh
b9f9ba145e Add const methods for oparg enums (#7617)
* Add const methods for oparg enums

* Shorten doc link
2026-04-17 20:06:30 +09:00
Shahar Naveh
3d91197b38 Constify OpArgState methods (#7616) 2026-04-17 20:05:37 +09:00
Shahar Naveh
2827eca293 Simplify Intruction.deopt() (#7615)
* Simplify `Instruction.deopt()`

* Adjust `scripts/generate_opcode_metadata.py`
2026-04-17 20:04:22 +09:00
Joshua Megnauth
aac207003f fix: Python-Rust combining char diff in isalnum (#7612)
* fix: Python-Rust combining char diff in isalnum

Related to: #7518

Rust and Python differ on alphanumeric characters. Rust follows the
Unicode standard closer than Python. This means that is_alphanumeric
(char function in Rust) is different from isalnum (Python). To fix the
discrepancy, RustPython needs to mimic Python by rejecting certain
characters. Some classes of combining characters count as alphanumeric
in Rust but not Python. Combining characters are accent marks
that are combined with other characters to create a single grapheme.

It's possible that this PR is not exhaustive. I fixed the combining
character issue BUT I don't know the full range of discrepancies.

* fix: Ignore combining characters in SRE

Closes: #7518
2026-04-17 18:45:43 +09:00
Joshua Megnauth
f82b8d8eb7 Fix compiling with OpenSSL (#7621) 2026-04-17 18:27:49 +09:00
Noa
8d61a2217b Merge pull request #7620 from ShaharNaveh/ci-fix-clippy
CI: fix clippy lints
2026-04-16 15:15:27 -05:00
ShaharNaveh
640cbd7c4a Clippy lints 2026-04-16 16:54:28 +02:00
Shahar Naveh
aa12accdac Update test_struct.py from 3.14.4 (#7614) 2026-04-16 08:52:37 +09:00
Shahar Naveh
fd2117355e Simplify cache_entries match statement (#7613)
* Simplify cache_entries method

* Use `Opcode`
2026-04-16 08:52:11 +09:00
dependabot[bot]
36025386f3 Bump follow-redirects from 1.15.9 to 1.16.0 in /wasm/demo (#7596)
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.9 to 1.16.0.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.9...v1.16.0)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-version: 1.16.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-16 03:18:33 +09:00
Shahar Naveh
330aa08488 Macro for defining opcode & instruction enums (#7573)
* Macro for defining opcode & instruction enums

* Convert `Instruction` as well

* revert `#[repr(...)]` changes
2026-04-16 03:18:14 +09:00
Shahar Naveh
a2c3e65b81 Unify CI caches (reduce total cache size by 75% ±) (#7610)
* Singular job for creating caches

* Use shared cache
2026-04-15 14:19:17 +09:00
Shahar Naveh
8108b6a153 Update test_bisect.py from 3.14.4 (#7609) 2026-04-15 14:17:48 +09:00
Shahar Naveh
63a1c0e95c Update test_bz2.py from 3.14.4 (#7608)
* Update `test_bz2.py` from 3.14.4

* Mark failing test
2026-04-15 14:17:27 +09:00
Shahar Naveh
c98939a7c1 Update seq tests from 3.14.4 (#7606)
* Update seq related tests
2026-04-15 14:17:01 +09:00
Shahar Naveh
9f1429d95f Update test_compile.py from 3.14.4 (#7607) 2026-04-15 14:15:48 +09:00
Shahar Naveh
73218f42d5 Update test_range.py from 3.14.4 (#7605) 2026-04-15 14:15:27 +09:00
dependabot[bot]
f197699e3c Bump reviewdog/action-actionlint from 1.71.0 to 1.72.0
Bumps [reviewdog/action-actionlint](https://github.com/reviewdog/action-actionlint) from 1.71.0 to 1.72.0.
- [Release notes](https://github.com/reviewdog/action-actionlint/releases)
- [Commits](0d952c597e...6fb7acc99f)

---
updated-dependencies:
- dependency-name: reviewdog/action-actionlint
  dependency-version: 1.72.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-15 14:14:09 +09:00
ShaharNaveh
898da7f58c Udpate http from 3.14.4 2026-04-14 21:02:25 +09:00
ShaharNaveh
0ee07e3d0a Update test_http_cookies.py from 3.14.3 2026-04-14 21:02:25 +09:00
Jeong, YunWon
49048504f6 Merge pull request #7600 from ShaharNaveh/update-test-urllib 2026-04-14 21:02:07 +09:00
Jeong, YunWon
e3997ad1b8 Merge pull request #7597 from RustPython/dependabot/cargo/rand-0.9.3 2026-04-14 21:01:45 +09:00
ShaharNaveh
da01e617de Update libc to 0.2.185 2026-04-14 21:00:12 +09:00
Jeong, YunWon
891538d924 Merge pull request #7599 from ShaharNaveh/update-test-pyexpat 2026-04-14 20:59:41 +09:00
ShaharNaveh
3096d77ec5 Marking failing test 2026-04-14 13:04:50 +02:00
ShaharNaveh
9e2d03428c Add XMLParserType 2026-04-14 13:03:59 +02:00
ShaharNaveh
d1e9763ff3 Merge remote-tracking branch 'upstream/main' into update-test-pyexpat 2026-04-14 12:15:22 +02:00
dependabot[bot]
2b1b0ba805 Bump the wasmtime group with 2 updates (#7591)
Bumps the wasmtime group with 2 updates: [cranelift-jit](https://github.com/bytecodealliance/wasmtime) and [cranelift-module](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift-jit` from 0.130.0 to 0.130.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-module` from 0.130.0 to 0.130.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift-jit
  dependency-version: 0.130.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
- dependency-name: cranelift-module
  dependency-version: 0.130.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-14 16:08:35 +09:00
github-actions[bot]
e09b66dd86 Update doc DB for CPython 3.14.4 (#7598)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-04-14 16:07:22 +09:00
ShaharNaveh
a24ee58961 Remove newlines from test_urllib2_localnet.py 2026-04-14 08:58:51 +02:00
ShaharNaveh
1721f62804 Udpate test_pyexpat.py from 3.14.4 2026-04-14 08:57:35 +02:00
dependabot[bot]
8f71ff4b47 Bump rand from 0.9.2 to 0.9.3
Bumps [rand](https://github.com/rust-random/rand) from 0.9.2 to 0.9.3.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/0.9.3/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/rand_core-0.9.2...0.9.3)

---
updated-dependencies:
- dependency-name: rand
  dependency-version: 0.9.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-14 01:22:41 +00:00
Joshua Megnauth
4bbabe5810 fix: Handle char expansion in islower, isupper (#7583)
* fix: Handle char expansion in islower, isupper

Closes: #7526

`py_islower` and `py_isupper` need to handle expansions for letter
casing. Comparing chars directly can miss edge cases in certain
languages. Unfortunately, like the last PR, this allocates to handle
potential expansions.

I also had to add `icu_casemap` as a dependency.
RustPython is already using parts of icu4x so this doesn't add many
transitive dependencies.

* Ensure islower/isupper handles strs without chars

This fixes a regression mentioned by CodeRabbit. I also figured out how
to check a string's case without allocation using Unicode properties.
Thus, this commit removes `icu_casemap` again. `icu_casemap` and my old
solution is required for a robust case check, but it seems like the
current code is fine for Python.
2026-04-14 10:19:31 +09:00
Bas Schoenmaeckers
7544628268 Allow creating PyCapsule objects (#7595) 2026-04-14 09:44:02 +09:00
Copilot
7e637e8cbd Add __callback__ property to weakref type (#7590)
* Initial plan

* Add __callback__ property to PyWeak for weakref compatibility

Add get_callback() method to PyWeak in core.rs that safely reads the
callback field under the stripe lock. Expose it as a read-only
__callback__ property on the weakref type, matching CPython behavior:
- Returns the callback function when one was provided and referent is alive
- Returns None when no callback was provided
- Returns None after the referent has been collected
- Raises AttributeError on assignment (read-only)

Remove @unittest.expectedFailure from test_callback_attribute and
test_callback_attribute_after_deletion in test_weakref.py.

Add regression tests to extra_tests/snippets/stdlib_weakref.py.

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/a8689daa-4476-4645-a935-0e13c7f7bb42

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

* Fix ruff formatting in stdlib_weakref.py snippet

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/4995198f-e083-4dac-823a-166fcf54adc4

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-04-13 23:58:58 +09:00
Jeong, YunWon
7e5e026941 Add InstructionMetadata::stack_effect_jump for branch stack effects (#7585)
* Add InstructionMetadata::stack_effect_jump for branch stack effects

CPython's compile.c provides stack_effect(opcode, oparg, jump) where the
jump parameter selects between fallthrough and branch effects. The existing
stack_effect() only returns the fallthrough effect.

Add stack_effect_jump() that returns the branch effect. Most instructions
have identical fallthrough/branch effects; ForIter and Send are the
exceptions (ForIter: fallthrough=+1, branch=-1; Send: fallthrough=0,
branch=-1).

* apply review
2026-04-13 17:25:26 +09:00
🍌Shawn
27aed85599 Update LICENSE (#7581) 2026-04-13 12:49:32 +09:00
Jeong, YunWon
d201c48e1c Bytecode parity - for-loop cleanup, return duplication, late jump threading fix (#7580)
- Use POP_TOP instead of POP_ITER for for-loop break/return cleanup
- Expand duplicate_end_returns to clone final return for jump predecessors
- Restrict late jump threading pass to unconditional jumps only
- Skip exception blocks in inline/reorder passes
- Simplify threaded_jump_instr NoInterrupt handling
2026-04-12 22:43:35 +09:00
Shahar Naveh
9cf7bcd64a Fail if prek fails (#7574) 2026-04-10 18:50:03 +09:00
Shahar Naveh
31edcfa97e Remove overly broad permissions from release.yml (#7577) 2026-04-10 18:49:37 +09:00
Jeong, YunWon
eac45727d2 Bytecode parity - direct loop backedges (#7578) 2026-04-10 18:48:57 +09:00
Shahar Naveh
28acbc66f9 Revert "Only run cargo check when rust code is changed (#7572)" (#7579) 2026-04-10 18:07:11 +09:00
Jeong, YunWon
a49ce5bf34 Bytecode parity - exception (#7557)
* Fix exception handling: except* chaining, finally cleanup, RERAISE

- Align except* bytecode chaining
- Fix exception state model and finally handler cleanup
- Fix RERAISE to only pop exception, preserve values below

* Port IR optimization passes from flowgraph.c

- BUILD_TUPLE n + UNPACK_SEQUENCE n elimination
- Dead store elimination within basic blocks
- apply_static_swaps for SWAP reduction

* Add bytecode comparison and disassembly dump scripts

- compare_bytecode.py: compare CPython vs RustPython bytecode output
- dis_dump.py: extract disassembly in normalized JSON format
2026-04-10 12:51:48 +09:00
Shahar Naveh
7b5ac61026 Update some libs and tests from 3.14.3 to 3.14.4 (#7576)
* Update some libs and tests to 3.14.4

* Update `pydoc_data`
2026-04-10 09:16:10 +09:00
Shahar Naveh
ad66d9acd0 Only run cargo check when rust code is changed (#7572) 2026-04-10 02:40:15 +09:00
Shahar Naveh
00dd9a5ed1 Unify python version used by CI. Update to 3.14.4 (#7571)
* Add `.python-version` file

* Modify CI to use `.python-version` file

* Use correct path for `.python-version` file
2026-04-10 02:38:14 +09:00
dependabot[bot]
d5a90e5c1f Bump cargo-bins/cargo-binstall from 1.17.8 to 1.17.9 (#7566)
Bumps [cargo-bins/cargo-binstall](https://github.com/cargo-bins/cargo-binstall) from 1.17.8 to 1.17.9.
- [Release notes](https://github.com/cargo-bins/cargo-binstall/releases)
- [Changelog](https://github.com/cargo-bins/cargo-binstall/blob/main/release-plz.toml)
- [Commits](113a77a4ce...0b24824336)

---
updated-dependencies:
- dependency-name: cargo-bins/cargo-binstall
  dependency-version: 1.17.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-06 23:30:13 +09:00
dependabot[bot]
72f397c6df Bump pyo3 from 0.28.2 to 0.28.3 in the pyo3 group (#7563)
Bumps the pyo3 group with 1 update: [pyo3](https://github.com/pyo3/pyo3).


Updates `pyo3` from 0.28.2 to 0.28.3
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pyo3/pyo3/compare/v0.28.2...v0.28.3)

---
updated-dependencies:
- dependency-name: pyo3
  dependency-version: 0.28.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: pyo3
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-06 23:29:58 +09:00
Joshua Megnauth
e009cc0c3b fix: Swapcase must handle multibyte expansions (#7559)
`swapcase` used `to_ascii_lowercase` and uppercase to swap cases. This
is fine for ASCII, but code points may expand into multiple bytes which
leads to incorrect case swaps for some languages. The fix is to use
`to_lowercase` and `to_uppercase` instead.

Unfortunately, this leads to a realloc in `swapcase` when bytes are
expanded.

Part of #7526.
2026-04-06 23:29:30 +09:00
Copilot
eed618d858 Fix str.zfill() width calculation for non-ASCII strings (#7534) 2026-04-04 14:45:30 +09:00
Bo Maryniuk
87fc4540c4 Fix VM's infinite recursion crash with musl libc (#7558)
* Fix VM's infinite recursion crash with musl libc

* Lintfix/cleanup warnings
2026-04-04 09:46:46 +09:00
dependabot[bot]
a09afab912 Bump lodash from 4.17.23 to 4.18.1 in /wasm/demo (#7556)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.23 to 4.18.1.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.23...4.18.1)

---
updated-dependencies:
- dependency-name: lodash
  dependency-version: 4.18.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-03 01:44:50 +09:00
Shahar Naveh
3d9688402a Replace unmaintained unic crates (#7555) 2026-04-03 01:43:11 +09:00
Shahar Naveh
b61dfdc534 Updtae test_optimizer.py from 3.14.3 (#7554) 2026-04-03 01:33:50 +09:00
Shahar Naveh
6d7d74cc0b Update test_opcache.py from 3.14.3 (#7553) 2026-04-03 01:33:34 +09:00
Shahar Naveh
3f49f42702 Update test_module from 3.14.3 (#7552)
* Update `test_module` from 3.14.3

* Unmark passing test
2026-04-03 01:33:19 +09:00
Shahar Naveh
5afa3493a1 Add test_perfmaps.py from 3.14.3 (#7551) 2026-04-03 00:50:25 +09:00
Shahar Naveh
1adda8a73d Update test_file & test_largefile from 3.14.3 (#7550) 2026-04-03 00:49:55 +09:00
Shahar Naveh
344b7a5abd [zizmor] ignore superfluous-actions (#7548) 2026-04-03 00:44:58 +09:00
Jeong, YunWon
d9c4c95369 fix crates (#7549) 2026-03-31 21:05:08 +09:00
Jeong, YunWon
403c2be01d Improve codegen bytecode parity (#7541)
- Add CFG block splitting, jump threading, backward jump normalization
- Add genexpr StopIteration wrapper
- Add ConstantData::Slice and constant slice folding
- Add duplicate_exits_without_lineno and Block: Clone
- Add builtin(genexpr) optimization for tuple/list/set/all/any
- Add compile_try_except_no_finally for try-except without finally
- Add module_name_declared_global_in_nested_scope
- Add constant tuple folding in try_fold_constant_expr
- Add fstring literal-only optimization and empty literal elision
- Fix duplicate_exits_without_lineno: splice new blocks into linked list
2026-03-31 15:45:18 +09:00
Shahar Naveh
5cc9eab2dd Resolve excessive-permissions warning in ci.yaml (#7547)
* Resolve `excessive-permissions` warning in `ci.yaml`

* Update .github/workflows/ci.yaml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-03-31 14:53:08 +09:00
dependabot[bot]
b275a90cf9 Bump j178/prek-action from 2.0.0 to 2.0.1 (#7544)
Bumps [j178/prek-action](https://github.com/j178/prek-action) from 2.0.0 to 2.0.1.
- [Release notes](https://github.com/j178/prek-action/releases)
- [Commits](79f765515b...53276d8b0d)

---
updated-dependencies:
- dependency-name: j178/prek-action
  dependency-version: 2.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-30 18:38:01 +02:00
dependabot[bot]
43851c21b9 Bump minimatch and serve in /wasm/demo (#7539)
Bumps [minimatch](https://github.com/isaacs/minimatch) to 3.1.5 and updates ancestor dependency [serve](https://github.com/vercel/serve). These dependencies need to be updated together.


Updates `minimatch` from 3.1.2 to 3.1.5
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.1.2...v3.1.5)

Updates `serve` from 14.2.5 to 14.2.6
- [Release notes](https://github.com/vercel/serve/releases)
- [Changelog](https://github.com/vercel/serve/blob/main/CHANGELOG.md)
- [Commits](https://github.com/vercel/serve/compare/v14.2.5...v14.2.6)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-version: 3.1.5
  dependency-type: indirect
- dependency-name: serve
  dependency-version: 14.2.6
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-31 01:31:08 +09:00
Shahar Naveh
611b122ed7 Resolve template injection (#7546) 2026-03-31 01:30:41 +09:00
dependabot[bot]
1a4964b741 Bump dtolnay/rust-toolchain (#7545)
Bumps [dtolnay/rust-toolchain](https://github.com/dtolnay/rust-toolchain) from efa25f7f19611383d5b0ccf2d1c8914531636bf9 to 3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9.
- [Release notes](https://github.com/dtolnay/rust-toolchain/releases)
- [Commits](efa25f7f19...3c5f7ea28c)

---
updated-dependencies:
- dependency-name: dtolnay/rust-toolchain
  dependency-version: 3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-31 01:30:08 +09:00
dependabot[bot]
106f1c9f37 Bump env_logger from 0.11.9 to 0.11.10 (#7543)
Bumps [env_logger](https://github.com/rust-cli/env_logger) from 0.11.9 to 0.11.10.
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.11.9...v0.11.10)

---
updated-dependencies:
- dependency-name: env_logger
  dependency-version: 0.11.10
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-31 01:29:47 +09:00
dependabot[bot]
c45f69977b Bump schannel from 0.1.28 to 0.1.29 (#7542)
Bumps [schannel](https://github.com/steffengy/schannel-rs) from 0.1.28 to 0.1.29.
- [Release notes](https://github.com/steffengy/schannel-rs/releases)
- [Commits](https://github.com/steffengy/schannel-rs/compare/v0.1.28...v0.1.29)

---
updated-dependencies:
- dependency-name: schannel
  dependency-version: 0.1.29
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-31 01:29:35 +09:00
Shahar Naveh
2703f94c3e Split cargo check matrix to individual targets. Avoid cache poisoning (#7540)
* Split check matrix. Prevent cache poisoning

* Use `rustup`

* Change name

* Align cargo args
2026-03-30 23:59:48 +09:00
Shahar Naveh
9900c761ca Fix lint warnings in release.yml (#7538) 2026-03-30 18:53:38 +09:00
Shahar Naveh
959b088d25 Remove oparg builders (#7537) 2026-03-30 18:53:13 +09:00
Jeong, YunWon
1c39fdb7f9 Bytecode parity (#7536)
* Add CFG block splitting, jump threading, backward jump normalization, genexpr StopIteration wrapper

- split_blocks_at_jumps: split blocks at branch points so each has one exit
- jump_threading: thread jumps through single-jump blocks (flowgraph.c jump_thread)
- Backward conditional jump normalization: invert and create NOT_TAKEN+JUMP block
- Follow empty blocks in jump-to-return optimization (next_nonempty_block)
- Add PEP 479 StopIteration handler to compile_comprehension for generators

* Add ConstantData::Slice and constant slice folding

- Add Slice variant to ConstantData and BorrowedConstant
- Fold constant slices (x[:3], x[1:4]) into LOAD_CONST(slice(...))
- Marshal serialization/deserialization for Slice type
- Box::leak in borrow_obj_constant for PySlice roundtrip

* Add duplicate_exits_without_lineno (disabled) and Block: Clone

Prepare infrastructure for exit block duplication optimization.
Currently disabled pending stackdepth integration.

* Improve codegen bytecode parity
2026-03-30 18:50:58 +09:00
Jeong, YunWon
3706c5376e Bytecode parity (#7535)
* Add CFG block splitting, jump threading, backward jump normalization, genexpr StopIteration wrapper

- split_blocks_at_jumps: split blocks at branch points so each has one exit
- jump_threading: thread jumps through single-jump blocks (flowgraph.c jump_thread)
- Backward conditional jump normalization: invert and create NOT_TAKEN+JUMP block
- Follow empty blocks in jump-to-return optimization (next_nonempty_block)
- Add PEP 479 StopIteration handler to compile_comprehension for generators

* Add ConstantData::Slice and constant slice folding

- Add Slice variant to ConstantData and BorrowedConstant
- Fold constant slices (x[:3], x[1:4]) into LOAD_CONST(slice(...))
- Marshal serialization/deserialization for Slice type
- Box::leak in borrow_obj_constant for PySlice roundtrip

* Add ConstantData::Frozenset variant (type only, folding deferred)

Add Frozenset to ConstantData, BorrowedConstant, and marshal support.
Actual frozenset folding (BUILD_SET + CONTAINS_OP → LOAD_CONST frozenset)
requires VirtualMachine for element hashing and is deferred.

* Add duplicate_exits_without_lineno (disabled) and Block: Clone

Prepare infrastructure for exit block duplication optimization.
Currently disabled pending stackdepth integration.
2026-03-30 12:52:04 +09:00
Huy Vũ (Josh)
e6bcd64066 Validate SyntaxError details tuple shape (#7533) 2026-03-29 22:37:08 +09:00
Jeong, YunWon
2ebd7026e4 Compiler parity: docstring dedent, StopIteration wrapper, constant folding (#7530) 2026-03-29 22:36:20 +09:00
Jeong, YunWon
6826557884 ruff from fork (#7532) 2026-03-29 19:26:24 +09:00
Jeong, YunWon
1f6b4c6bf1 ruff 0.15.8 (#7531) 2026-03-29 15:21:09 +09:00
Copilot
902985def7 Fix inspect.getsource returning truncated source for multi-line function definitions (#7519)
* Initial plan

* fix: restore def-line source range before entering function scope so co_firstlineno is correct

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/94701403-2011-4525-88f1-6e06891da6a4

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

* fix: remove pre-existing expectedFailure decorators from test_gettext plural form tests

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/ce27bf53-569f-45a0-ad5a-08e8f322c717

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

* remove extra_tests/snippets/inspect_getsource.py (covered by test_inspect)

Agent-Logs-Url: https://github.com/RustPython/RustPython/sessions/2b64da1b-8aab-4fec-8b28-3a21d46ac2f9

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-03-29 00:52:34 +09:00
dependabot[bot]
90c5464901 Bump serialize-javascript and terser-webpack-plugin in /wasm/demo (#7523)
Removes [serialize-javascript](https://github.com/yahoo/serialize-javascript). It's no longer used after updating ancestor dependency [terser-webpack-plugin](https://github.com/webpack/terser-webpack-plugin). These dependencies need to be updated together.


Removes `serialize-javascript`

Updates `terser-webpack-plugin` from 5.3.16 to 5.4.0
- [Release notes](https://github.com/webpack/terser-webpack-plugin/releases)
- [Changelog](https://github.com/webpack/terser-webpack-plugin/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webpack/terser-webpack-plugin/compare/v5.3.16...v5.4.0)

---
updated-dependencies:
- dependency-name: serialize-javascript
  dependency-version: 
  dependency-type: indirect
- dependency-name: terser-webpack-plugin
  dependency-version: 5.4.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-29 00:52:00 +09:00
Huy Vũ (Josh)
da440dbbbe type.__new__: preserve caller namespace when reading __qualname__ (#7524)
* type.__new__: preserve caller namespace when reading __qualname__

* type.__new__: preserve caller namespace when reading __qualname__
2026-03-29 00:51:49 +09:00
dependabot[bot]
1a9b10ece5 Bump winresource from 0.1.30 to 0.1.31 (#7522)
Bumps [winresource](https://github.com/BenjaminRi/winresource) from 0.1.30 to 0.1.31.
- [Commits](https://github.com/BenjaminRi/winresource/commits)

---
updated-dependencies:
- dependency-name: winresource
  dependency-version: 0.1.31
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-28 14:47:55 +09:00
dependabot[bot]
dd632363c8 Bump the wasmtime group with 3 updates (#7521)
Bumps the wasmtime group with 3 updates: [cranelift](https://github.com/bytecodealliance/wasmtime), [cranelift-jit](https://github.com/bytecodealliance/wasmtime) and [cranelift-module](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift` from 0.129.1 to 0.130.0
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-jit` from 0.129.1 to 0.130.0
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-module` from 0.129.1 to 0.130.0
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.130.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: wasmtime
- dependency-name: cranelift-jit
  dependency-version: 0.130.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: wasmtime
- dependency-name: cranelift-module
  dependency-version: 0.130.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: wasmtime
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-28 14:47:42 +09:00
Jeong, YunWon
f7556b00c1 Bytecode parity (#7514)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-28 09:19:12 +09:00
Jeong, YunWon
3dae07cd60 winapi functions (#7516) 2026-03-28 00:02:49 +09:00
Jeong, YunWon
fddd7cb690 fix cron-ci (#7483)
* fix cron-ci

* fix custom_text_test_runner
2026-03-27 23:55:30 +09:00
Shahar Naveh
410721740d Oparg resume depth (#7515)
* Base resume context

* Fixes for api change

* Align codegen

* Align `frame.rs` to the api changes

* fix jit

* Use new oparg

* Fix doc

* let `ir` to decide exception depth
2026-03-27 21:47:52 +09:00
dependabot[bot]
e3ac1bf8dc Bump node-forge from 1.3.2 to 1.4.0 in /wasm/demo (#7513)
Bumps [node-forge](https://github.com/digitalbazaar/forge) from 1.3.2 to 1.4.0.
- [Changelog](https://github.com/digitalbazaar/forge/blob/main/CHANGELOG.md)
- [Commits](https://github.com/digitalbazaar/forge/compare/v1.3.2...v1.4.0)

---
updated-dependencies:
- dependency-name: node-forge
  dependency-version: 1.4.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-27 12:44:55 +09:00
Jeong, YunWon
3a8fb76014 Bytecode parity (#7507)
* Bytecode parity phase 3

Compiler changes:
- Emit TO_BOOL in and/or short-circuit evaluation (COPY+TO_BOOL+JUMP)
- Add module-level __conditional_annotations__ cell (PEP 649)
- Only set conditional annotations for AnnAssign, not function params
- Skip __classdict__ cell when future annotations are active
- Convert list literals to tuples in for-loop iterables
- Fix cell variable ordering: parameters first, then alphabetical
- Fix RESUME DEPTH1 flag for yield-from/await
- Don't propagate __classdict__/__conditional_annotations__ freevar
  through regular functions — only annotation/type-param scopes
- Inline string compilation path

* Skip test_thread_safety in _test_multiprocessing

SIGSEGV in _finalizer_registry dict access under aggressive GC
and thread switching. Root cause is dict thread-safety in VM.

* Skip list→tuple optimization for async for; propagate future_annotations to nested scopes
2026-03-27 12:42:29 +09:00
Jeong, YunWon
a91127c91a Reorder PyNumberBinaryOp to match NB_* constants (#7512)
Align variant ordering with BinaryOperator enum and
CPython's NB_* constants from opcode.h. Divmod is placed
last as it has no corresponding NB_* constant.
2026-03-27 12:41:02 +09:00
Jeong, YunWon
af0c2526a7 Fix GC TOCTOU race in collect_inner referent traversal (#7511)
Pre-compute referent pointers once per object in step 3 and reuse
them in step 4 (BFS reachability). Previously, gc_get_referent_ptrs()
was called independently in both steps. If a dict's write lock state
changed between the two calls (e.g., held by another thread during
one traversal but not the other), the two traversals could return
different results. This caused live objects to be incorrectly
classified as unreachable and cleared by GC.
2026-03-27 12:39:45 +09:00
dependabot[bot]
f42ffd61a1 Bump strum from 0.27.2 to 0.28.0 (#7510)
Bumps [strum](https://github.com/Peternator7/strum) from 0.27.2 to 0.28.0.
- [Release notes](https://github.com/Peternator7/strum/releases)
- [Changelog](https://github.com/Peternator7/strum/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Peternator7/strum/compare/v0.27.2...v0.28.0)

---
updated-dependencies:
- dependency-name: strum
  dependency-version: 0.28.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-27 11:27:19 +09:00
dependabot[bot]
3f92c3ad1c Bump aws-lc-rs from 1.16.0 to 1.16.2 (#7509)
Bumps [aws-lc-rs](https://github.com/aws/aws-lc-rs) from 1.16.0 to 1.16.2.
- [Release notes](https://github.com/aws/aws-lc-rs/releases)
- [Commits](https://github.com/aws/aws-lc-rs/compare/v1.16.0...v1.16.2)

---
updated-dependencies:
- dependency-name: aws-lc-rs
  dependency-version: 1.16.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-27 10:55:12 +09:00
Shahar Naveh
9282a870db Unify lint CI job (#7505)
* use `prek` for unified linting

* Fix actionlint error

* Generate metadata when specific files change

* `check_redundant_patches.py` to accept glob path

* Test

* revert defective changes

* use `rustfmt` over `cargo fmt` for individual files

* debug reviewdog

* rustfmt

* Move comment to correct location

* defevtive fmt test

* Fail with reviewdog

* fix reviewdog perms

* Try to use present token

* without checks oerms

* put normal perms

* fmt
2026-03-26 21:43:34 +09:00
Shahar Naveh
7a6dbd6624 Align concurrency CI groups names (#7508) 2026-03-26 14:33:14 +09:00
dependabot[bot]
6c3dd2885d Bump picomatch from 2.3.1 to 2.3.2 in /wasm/demo (#7506)
Bumps [picomatch](https://github.com/micromatch/picomatch) from 2.3.1 to 2.3.2.
- [Release notes](https://github.com/micromatch/picomatch/releases)
- [Changelog](https://github.com/micromatch/picomatch/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/picomatch/compare/2.3.1...2.3.2)

---
updated-dependencies:
- dependency-name: picomatch
  dependency-version: 2.3.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-26 12:51:49 +09:00
Jeong, YunWon
c9cfb3d606 Bytecode parity (#7504)
* Match CPython LOAD_SPECIAL stack semantics for with/async-with

LOAD_SPECIAL now pushes (callable, self_or_null) matching CPython's
CALL convention, instead of a single bound method:
- Function descriptors: push (func, self)
- Plain attributes: push (bound, NULL)

Updated all with-statement paths:
- Entry: add SWAP 3 after SWAP 2, remove PUSH_NULL before CALL 0
- Normal exit: remove PUSH_NULL before CALL 3
- Exception handler (WITH_EXCEPT_START): read exit_func at TOS-4
  and self_or_null at TOS-3
- Suppress block: 3 POP_TOPs after POP_EXCEPT (was 2)
- FBlock exit (preserve_tos): SWAP 3 + SWAP 2 rotation
- UnwindAction::With: remove PUSH_NULL

Stack effects updated: LoadSpecial (2,1), WithExceptStart (7,6)

* Normalize LOAD_FAST_CHECK and JUMP_BACKWARD_NO_INTERRUPT

Add LOAD_FAST_CHECK → LOAD_FAST and JUMP_BACKWARD_NO_INTERRUPT →
JUMP_BACKWARD to opname normalization in dis_dump.py. These are
optimization variants with identical semantics.

* Add EXTENDED_ARG to SKIP_OPS, normalize LOAD_FAST_CHECK and JUMP_BACKWARD_NO_INTERRUPT

* Remove duplicate return-None when block already has return

Skip duplicate_end_returns for blocks that already end with
LOAD_CONST + RETURN_VALUE. Run DCE + unreachable elimination
after duplication to remove the now-unreachable original return
block.

* Improve __static_attributes__ collection accuracy

- Support tuple/list unpacking targets: (self.x, self.y) = val
- Skip @staticmethod and @classmethod decorated methods
- Use scan_target_for_attrs helper for recursive target scanning

* Use method mode for function-local import attribute calls

Function-local imports (scope is Local+IMPORTED) should use method
mode LOAD_ATTR like regular names, not plain mode. Only module/class
scope imports use plain LOAD_ATTR + PUSH_NULL.

* Optimize constant iterable before GET_ITER to LOAD_CONST tuple

Convert BUILD_LIST/SET 0 + LOAD_CONST + LIST_EXTEND/SET_UPDATE + GET_ITER
to just LOAD_CONST (tuple) + GET_ITER, matching CPython's optimization
for constant list/set literals in for-loop iterables.

Also fix is_name_imported to use method mode for function-local imports,
and improve __static_attributes__ accuracy (skip @classmethod/@staticmethod,
handle tuple/list unpacking targets).

* Fix cell variable ordering: parameters first, then alphabetical

CPython orders cell variables with parameter cells first (in
parameter definition order), then non-parameter cells sorted
alphabetically. Previously all cells were sorted alphabetically.

Also add for-loop iterable optimization: constant BUILD_LIST/SET
before GET_ITER is folded to just LOAD_CONST tuple.

* Emit COPY_FREE_VARS before MAKE_CELL matching CPython order

CPython emits COPY_FREE_VARS first, then MAKE_CELL instructions.
Previously RustPython emitted them in reverse order.

* Fix RESUME AfterYield encoding to match CPython 3.14 (value 5)

CPython 3.14 uses RESUME arg=5 for after-yield, not 1.
Also reorder COPY_FREE_VARS before MAKE_CELL and fix cell
variable ordering (parameters first, then alphabetical).

* Address code review feedback from #7481

- Set is_generator flag for generator expressions in scan_comprehension
- Fix posonlyargs priority in collect_static_attributes first param
- Add match statement support to scan_store_attrs
- Fix stale decorator stack comment
- Reorder NOP removal after fold_unary_negative for better collection folding

* Fold constant list/set/tuple literals in compiler

When all elements of a list/set/tuple literal are constants and
there are 3+ elements, fold them into a single constant:
- list: BUILD_LIST 0 + LOAD_CONST (tuple) + LIST_EXTEND 1
- set:  BUILD_SET 0  + LOAD_CONST (tuple) + SET_UPDATE 1
- tuple: LOAD_CONST (tuple)

This matches CPython's compiler optimization and fixes the most
common bytecode difference (92/200 sampled files).

Also add bytecode comparison scripts (dis_dump.py, compare_bytecode.py)
for systematic parity tracking.

* Use BUILD_MAP 0 + MAP_ADD for large dicts (>= 16 pairs)

Match CPython's compiler behavior: dicts with 16+ key-value pairs
use BUILD_MAP 0 followed by MAP_ADD for each pair, instead of
pushing all keys/values on the stack and calling BUILD_MAP N.

* Fix clippy warnings and cargo fmt

* fix surrogate
2026-03-25 22:25:21 +09:00
lif
e1ecb87f32 fix: Flush stdout on shutdown matching CPython behavior (#7503)
* fix: flush stdout on interpreter shutdown matching CPython behavior

When stdout flush fails during shutdown, report the error via
run_unraisable and exit with code 120 (matching CPython's
Py_FinalizeEx). Skip flushing already-closed or None streams.
Stderr flush errors remain silently ignored per CPython behavior.

Fixes #5521

Signed-off-by: majiayu000 <1835304752@qq.com>

* refactor: replace magic number 120 with named constant EXITCODE_FLUSH_FAILURE

Address review feedback on PR #7503: improve readability by extracting
the CPython-compat exit code into a named constant.

Signed-off-by: majiayu000 <1835304752@qq.com>

---------

Signed-off-by: majiayu000 <1835304752@qq.com>
2026-03-25 19:59:16 +09:00
Jeong, YunWon
ea5a6cd9c0 Bytecode parity (#7481)
* Bytecode parity

 Compiler changes:
    - Remove PUSH_NULL from decorator cal
ls, use CALL 0
    - Collect __static_attributes__ from self.xxx = patterns
    - Sort __static_attributes__ alphabetically
    - Move __classdict__ init before __doc__ in class prologue
    - Fold unary negative constants
    - Fold constant list/set literals (3+ elements)
    - Use BUILD_MAP 0 + MAP_ADD for 16+ dict pairs
    - Always run peephole optimizer for s
uperinstructions
    - Emit RETURN_GENERATOR for generator
 functions
    - Add is_generator flag to SymbolTabl
e

* Fix formatting and collapsible_if clippy warnings in compile.rs

* Fix clippy, fold_unary_negative chaining, and generator line tracing

- Replace irrefutable if-let with let for ExceptHandler
- Remove folded UNARY_NEGATIVE instead of replacing with NOP,
  enabling chained negation folding
- Initialize prev_line to def line for generators/coroutines
  to suppress spurious LINE events from preamble instructions
- Remove expectedFailure markers for now-passing tests

* Fix JIT StoreFastStoreFast, format, and remove expectedFailure markers

- Add StoreFastStoreFast handling in JIT instructions
- Fix cargo fmt in frame.rs
- Remove 11 expectedFailure markers for async jump tests in
  test_sys_settrace that now pass

* Fix peephole optimizer: use NOP replacement instead of remove()

Using remove() shifts instruction indices and corrupts subsequent
references, causing "pop stackref but null found" panics at runtime.
Replace folded/combined instructions with NOP instead, which are
cleaned up by the existing remove_nops pass.

* Revert peephole_optimize to use remove() for chaining support

NOP replacement broke chaining of peephole optimizations (e.g.
LOAD_CONST+TO_BOOL then LOAD_CONST+UNARY_NOT for 'not True').
The remove() approach is used by upstream and works correctly here;
fold_unary_negative keeps NOP replacement since it doesn't need chaining.

* Fix StoreFastStoreFast to handle NULL from LoadFastAndClear

StoreFast uses pop_value_opt() to allow NULL values from
LoadFastAndClear in inlined comprehension cleanup paths.
StoreFastStoreFast must do the same, otherwise the peephole
optimizer's fusion of two StoreFast instructions panics when
restoring unbound locals after an inlined comprehension.
2026-03-25 16:10:19 +09:00
Jeong, YunWon
6b5c5a9e92 Handle EINTR retry in os.write() (PEP 475) (#7482)
* Handle EINTR retry in os.write() (PEP 475)

Add EINTR retry loop to os.write(), matching the existing
pattern in os.read() and os.readinto(). Remove the
expectedFailure marker from test_write in _test_eintr.py.

* Add atomic snapshot for dict/dict_keys in extract_elements

Add fast paths for dict and dict_keys types in
extract_elements_with, matching _list_extend() in CPython
Objects/listobject.c. Each branch takes an atomic snapshot
under a single read lock, preventing race conditions from
concurrent dict mutation without the GIL.

Remove expectedFailure from test_thread_safety.
2026-03-25 14:02:38 +09:00
Shahar Naveh
211649d148 Pin setup-node action to a commit hash (#7495)
* Pin `setup-node` action to a commit hash

* Don't use cache for release

* Revert changes of `release.yml`
2026-03-25 12:05:19 +09:00
Shahar Naveh
4ebc3112d9 Cleanup release.yml a bit (#7499)
* Cleanup matrix usage. enables jit on macos

* Pin some actions to commit hash

* Disable node cache

* Inline `CARGO_ARGS`

* Add `stdio` and `host_env` features

* Only upload to pages if not running on fork
2026-03-25 12:04:56 +09:00
Shahar Naveh
6db7910ca4 Pin rust-toolchain action to a commit hash (#7500) 2026-03-25 12:04:34 +09:00
Shahar Naveh
8d3bc4cb54 Add test_concurrent_futures to FLAKY_MP_TESTS (#7502) 2026-03-25 12:04:14 +09:00
Shahar Naveh
20c6505bb9 Resolve shellcheck warning on ci.yaml (#7501) 2026-03-25 12:03:25 +09:00
Shahar Naveh
372280ede4 Pin setup-python action to a commit hash (#7494) 2026-03-25 11:58:39 +09:00
dependabot[bot]
82432be962 Bump lz4_flex from 0.12.1 to 0.13.0 (#7497)
Bumps [lz4_flex](https://github.com/pseitz/lz4_flex) from 0.12.1 to 0.13.0.
- [Release notes](https://github.com/pseitz/lz4_flex/releases)
- [Changelog](https://github.com/PSeitz/lz4_flex/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pseitz/lz4_flex/compare/0.12.1...0.13.0)

---
updated-dependencies:
- dependency-name: lz4_flex
  dependency-version: 0.13.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-24 17:51:11 +09:00
psyche
40c84f51c8 Expose rustpython_pylib in rustpython (#7498)
Co-authored-by: EtherealPsyche <EtherealPsyche@users.noreply.github.com>
2026-03-24 17:51:01 +09:00
Shahar Naveh
5408627594 Pin setup-python action to a commit hash (#7492) 2026-03-24 12:53:21 +09:00
dependabot[bot]
fb6520e5cc Bump cargo-bins/cargo-binstall from 1.17.7 to 1.17.8 (#7488)
Bumps [cargo-bins/cargo-binstall](https://github.com/cargo-bins/cargo-binstall) from 1.17.7 to 1.17.8.
- [Release notes](https://github.com/cargo-bins/cargo-binstall/releases)
- [Changelog](https://github.com/cargo-bins/cargo-binstall/blob/main/release-plz.toml)
- [Commits](1800853f25...113a77a4ce)

---
updated-dependencies:
- dependency-name: cargo-bins/cargo-binstall
  dependency-version: 1.17.8
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-24 12:52:39 +09:00
dependabot[bot]
e9b45a1419 Bump actions/cache from 5.0.3 to 5.0.4 (#7487)
Bumps [actions/cache](https://github.com/actions/cache) from 5.0.3 to 5.0.4.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](cdf6c1fa76...668228422a)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: 5.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-24 12:52:25 +09:00
dependabot[bot]
2acf76bbaf Bump github/gh-aw from 0.58.3 to 0.62.5 (#7486)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.58.3 to 0.62.5.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](08a903b1fb...48d8fdfddc)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.62.5
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-24 12:52:10 +09:00
dependabot[bot]
dc95db7ae3 Bump libsqlite3-sys from 0.36.0 to 0.37.0 (#7485)
Bumps [libsqlite3-sys](https://github.com/rusqlite/rusqlite) from 0.36.0 to 0.37.0.
- [Release notes](https://github.com/rusqlite/rusqlite/releases)
- [Changelog](https://github.com/rusqlite/rusqlite/blob/master/Changelog.md)
- [Commits](https://github.com/rusqlite/rusqlite/compare/v0.36.0...v0.37.0)

---
updated-dependencies:
- dependency-name: libsqlite3-sys
  dependency-version: 0.37.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-24 12:52:02 +09:00
Shahar Naveh
20ae3ccda2 Set dependabot cooldown (#7490)
* Set dependabot cooldown

* Increase default to 7 days
2026-03-24 12:45:30 +09:00
Shahar Naveh
f1d0fc31c5 Adjust permissions of update-doc-db job (#7496) 2026-03-24 12:45:06 +09:00
Shahar Naveh
56c3a37266 Pin setup-python action to a commit hash (#7491) 2026-03-24 12:44:42 +09:00
Jeong, YunWon
8c016157f4 marshal (#7467)
* CPython-compatible marshal format

Unify marshal to a single CPython-compatible format. No separate
"cpython_marshal" reader — one format for frozen modules, .pyc
files, and the Python-level marshal module.

- ComparisonOperator: `(cmp_index << 5) | mask` matching COMPARE_OP
- MakeFunctionFlag: bit-position matching SET_FUNCTION_ATTRIBUTE
- Exception table varint: big-endian (matching Python/assemble.c)
- Linetable varint: little-endian (unchanged)
- Integer: TYPE_INT (i32) / TYPE_LONG (base-2^15 digits)
- Code objects: CPython field order (argcount, posonlyargcount, ...,
  co_localsplusnames, co_localspluskinds, ..., co_exceptiontable)

- FLAG_REF / TYPE_REF for object deduplication (version >= 3)
- allow_code keyword argument on dumps/loads/dump/load
- Subclass rejection (int/float/complex/tuple/list/dict/set/frozenset)
- Slice serialization (version >= 5)
- Buffer protocol fallback for memoryview/array
- Recursion depth limit (2000) for both reads and writes
- Streaming load (reads one object, seeks file position)
- TYPE_INT64, TYPE_FLOAT (text), TYPE_COMPLEX (text) for compat

serialize_code writes co_localsplusnames/co_localspluskinds from
split varnames/cellvars/freevars. deserialize_code splits them back.
Cell variable DEREF indices are translated between flat (wire) and
cell-relative (internal) representations in both directions.

Replace bitwise trick with match for new ComparisonOperator values.

21 -> 3 expected failures. Remaining: test_bad_reader (IO layer),
test_deterministic_sets (PYTHONHASHSEED), testIntern (string interning).

* Address code review: preserve CO_FAST_HIDDEN, fix varint overflow

- Use original localspluskinds from marshal data instead of
  rebuilding, preserving CO_FAST_HIDDEN and other flags
- Fix write_varint_be to handle values >= 2^30 (add 6th chunk)
- Remove unused build_localspluskinds_from_split

* Add depth guard to deserialize_value_typed

Prevents usize underflow when dict key deserialization path calls
deserialize_value_typed with depth=0 on composite types.
2026-03-23 13:10:51 +09:00
Jeong, YunWon
907ce4d895 Bytecode parity (#7475)
* Emit TO_BOOL before conditional jumps, fix class/module prologue

- Emit TO_BOOL before POP_JUMP_IF_TRUE/FALSE in the general case
  of compile_jump_if (Compare expressions excluded since they
  already produce a bool)
- Module-level __doc__: use STORE_NAME instead of STORE_GLOBAL
- Class body __module__: use LOAD_NAME instead of LOAD_GLOBAL
- Class body: store __firstlineno__ before __doc__

* Emit MAKE_CELL and COPY_FREE_VARS before RESUME

Emit MAKE_CELL for each cell variable and COPY_FREE_VARS N for
free variables at the start of each code object, before RESUME.
These instructions are no-ops in the VM but align the bytecode
with CPython 3.14's output.

* Emit __static_attributes__ at end of class bodies

Store a tuple of attribute names (currently always empty) as
__static_attributes__ in the class namespace, matching CPython
3.14's class body epilogue. Attribute name collection from
self.xxx accesses is a follow-up task.

* Remove expectedFailure from DictProxyTests iter tests

test_iter_keys, test_iter_values, test_iter_items now pass
because class bodies emit __static_attributes__ and
__firstlineno__, matching the expected dict key set.

* Use 1-based stack indexing for LIST_EXTEND, SET_UPDATE, etc.

Switch LIST_APPEND, LIST_EXTEND, SET_ADD, SET_UPDATE, MAP_ADD
from 0-based to 1-based stack depth argument, matching CPython's
PEEK(oparg) convention. Adjust the VM to subtract 1 before
calling nth_value.

* Use plain LOAD_ATTR + PUSH_NULL for calls on imported names

When the call target is an attribute of an imported name (e.g.,
logging.getLogger()), use plain LOAD_ATTR (method_flag=0) with
a separate PUSH_NULL instead of method-mode LOAD_ATTR. This
matches CPython 3.14's behavior which avoids the method call
optimization for module attribute access.

* Duplicate return-None epilogue for fall-through blocks

When the last block in a code object is exactly LOAD_CONST None +
RETURN_VALUE (the implicit return), duplicate these instructions
into blocks that would otherwise fall through to it. This matches
CPython 3.14's behavior of giving each code path its own explicit
return instruction.

* Run cargo fmt on ir.rs

* Remove expectedFailure from test_intrinsic_1 in test_dis

* Emit TO_BOOL before conditional jumps for all expressions including Compare

* Add __classdict__ cell for classes with function definitions

Set needs_classdict=true for class scopes that contain function
definitions (def/async def), matching CPython 3.14's behavior for
PEP 649 deferred annotation support. Also restore the Compare
expression check in compile_jump_if to skip TO_BOOL for comparison
operations.

* Emit __classdictcell__ store in class body epilogue

Store the __classdict__ cell reference as __classdictcell__ in
the class namespace when the class has __classdict__ as a cell
variable. Uses LOAD_DEREF (RustPython separates cell vars from
fast locals unlike CPython's unified array).

* Always run DCE to remove dead code after terminal instructions

Run basic dead code elimination (truncating instructions after
RETURN_VALUE/RAISE/JUMP within blocks) at all optimization
levels, not just optimize > 0. CPython always removes this dead
code during assembly.

* Restrict LOAD_ATTR plain mode to module/class scope imports

Only use plain LOAD_ATTR + PUSH_NULL for imports at module or
class scope. Function-local imports use method call mode LOAD_ATTR,
matching CPython 3.14's behavior.

* Eliminate unreachable blocks after jump normalization

Split DCE into two phases: (1) within-block truncation after
terminal instructions (always runs), (2) whole-block elimination
for blocks only reachable via fall-through from terminal blocks
(runs after normalize_jumps when dead jump instructions exist).

* Fold BUILD_TUPLE 0 into LOAD_CONST empty tuple

Convert BUILD_TUPLE with size 0 to LOAD_CONST () during constant
folding, matching CPython's optimization for empty tuple literals.

* Handle __classcell__ and __classdictcell__ in type.__new__

- Remove __classcell__ from class dict after setting the cell value
- Add __classdictcell__ handling: set cell to class namespace dict,
  then remove from class dict
- Register __classdictcell__ identifier
- Use LoadClosure instead of LoadDeref for __classdictcell__ emission
- Reorder MakeFunctionFlag bits to match CPython
- Run ruff format on scripts

* Revert __classdict__ cell and __classdictcell__ changes

The __classdict__ cell addition (for classes with function defs)
and __classdictcell__ store caused cell initialization failures
in importlib. These require deeper VM changes to properly support
the cell variable lifecycle. Reverted for stability.

* Fix unreachable block elimination with fixpoint reachability

Use fixpoint iteration to properly determine block reachability:
only mark jump targets of already-reachable blocks, preventing
orphaned blocks from falsely marking their targets as reachable.
Also add a final DCE pass after assembly NOP removal to catch
dead code created by normalize_jumps.

* Check enclosing scopes for IMPORTED flag in LOAD_ATTR mode

When deciding whether to use plain LOAD_ATTR for attribute calls,
check if the name is imported in any enclosing scope (not just
the current scope). This handles the common pattern where a module
is imported at module level but used inside functions.

* Add __classdict__ cell for classes with function definitions

Set needs_classdict=true when a class scope contains function
definitions (def/async def), matching CPython 3.14 which always
creates a __classdict__ cell for PEP 649 support in such classes.

* Store __classdictcell__ in class body epilogue

Store the __classdict__ cell reference as __classdictcell__ in
the class namespace using LoadClosure (which loads the cell
object itself, not the value inside). This matches CPython 3.14's
class body epilogue.

* Fix clippy collapsible_if warnings and cargo fmt

* Revert __classdict__ and __classdictcell__ changes (cause import failures)

* Revert type.__new__ __classcell__ removal and __classdictcell__ handling

Revert the class cell cleanup changes from e6975f973 that cause
import failures when frozen module bytecode is stale. The original
behavior (not removing __classcell__ from class dict) is restored.

* Re-add __classdict__ cell and __classdictcell__ store

Restore the __classdict__ cell for classes with function
definitions and __classdictcell__ store in class body epilogue.
Previous failure was caused by stale .pyc cache files containing
bytecode from an intermediate MakeFunctionFlag reorder attempt,
not by these changes themselves.

* Reorder MakeFunctionFlag to match CPython's SET_FUNCTION_ATTRIBUTE

Reorder discriminants: Defaults=0, KwOnlyDefaults=1, Annotations=2,
Closure=3, Annotate=4, TypeParams=5. This aligns the oparg values
with CPython 3.14's convention.

Note: after this change, stale .pyc cache files must be deleted
(find . -name '*.pyc' -delete) to avoid bytecode mismatch errors.

* Use CPython-compatible power-of-two encoding for SET_FUNCTION_ATTRIBUTE

Override From/TryFrom for MakeFunctionFlag to use power-of-two
values (1,2,4,8,16,32) matching CPython's SET_FUNCTION_ATTRIBUTE
oparg encoding, instead of sequential discriminants (0,1,2,3,4,5).

* Remove expectedFailure from test_elim_jump_after_return1 and test_no_jump_over_return_out_of_finally_block

* Remove __classcell__ and __classdictcell__ from class dict in type.__new__

* Remove expectedFailure from test___classcell___expected_behaviour, cargo fmt

* Handle MakeCell and CopyFreeVars as no-ops in JIT

These prologue instructions are handled at frame creation time
by the VM. The JIT operates on already-initialized frames, so
these can be safely skipped during compilation.

* Remove expectedFailure from test_load_fast_known_simple

* Restore expectedFailure for test_load_fast_known_simple

The test expects LOAD_FAST_BORROW_LOAD_FAST_BORROW superinstruction
which RustPython does not emit yet.
2026-03-23 11:31: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
Lee Dogeon
3c62b5679f Implement bytearray.__str__ && bytes.__str__ (#7477)
* Implement bytearray.__str__

* Implement bytes.__str__

* Turn __str__ method into slot
2026-03-22 12:50:31 +09:00
dependabot[bot]
dfcb07cd93 Bump rustls-webpki from 0.103.9 to 0.103.10 (#7479)
Bumps [rustls-webpki](https://github.com/rustls/webpki) from 0.103.9 to 0.103.10.
- [Release notes](https://github.com/rustls/webpki/releases)
- [Commits](https://github.com/rustls/webpki/compare/v/0.103.9...v/0.103.10)

---
updated-dependencies:
- dependency-name: rustls-webpki
  dependency-version: 0.103.10
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-21 22:49:25 +09:00
Jeong, YunWon
2d676e7f4d A few windows fix (#7458)
* Disallow instantiation of sys.getwindowsversion type

Add slot_new to PyWindowsVersion that raises TypeError,
matching sys.flags behavior.

* Remove incorrect WSAHOS errno constant

WSAHOS was hardcoded as an alias for WSAHOST_NOT_FOUND, but
CPython guards it with #ifdef WSAHOS which doesn't exist in
modern Windows SDK headers.

* Fix mmap resize to raise OSError instead of SystemError

* Fix CreateProcess with empty environment on Windows

Empty env dict produced a single null terminator, but
CreateProcessW requires a double null for a valid empty
environment block.

* Revert mmap resize error to SystemError and fix errno.rs formatting

mmap resize raises SystemError (not OSError) when mremap is unavailable,
matching CPython behavior. test_mmap catches SystemError to skip unsupported
resize operations.

* Fix named mmap resize to raise OSError and unmark test_sleep expectedFailure

Named mmap resize on Windows should raise OSError (not SystemError).
Remove expectedFailure mark from TimeEINTRTest.test_sleep as it now passes.

* Use expectedFailureIf for TimeEINTRTest.test_sleep on Linux

test_sleep passes on macOS but fails on Linux due to timing.

* Remove expectedFailure for TimeEINTRTest.test_sleep

test_sleep now passes on all platforms.
2026-03-21 22:49:09 +09:00
Jeong, YunWon
3e9f825e1d Enable PEP 709 inlined comprehensions (#7412)
* Enable PEP 709 inlined comprehensions for function-like scopes

Activate the existing compile_inlined_comprehension() implementation
by fixing 6 bugs that prevented it from working:

- LoadFastAndClear: push NULL (not None) when slot is empty so
  StoreFast can restore empty state after comprehension
- StoreFast: accept NULL from stack for the restore path
- sub_tables.remove(0) replaced with next_sub_table cursor to
  match the pattern used elsewhere in the compiler
- in_inlined_comp flag moved from non-inlined to inlined path
- is_inlined_comprehension_context() now checks comp_inlined flag
  and restricts inlining to function-like scopes
- comp_inlined set only when parent scope uses fastlocals

Symbol table analysis handles conflict detection:
- Nested scopes in comprehension → skip inlining
- Bound name conflicts with parent symbol → skip inlining
- Cross-comprehension reference conflicts → skip inlining
- Splice comprehension sub_tables into parent for nested scope tracking

* Add localspluskinds, unify DEREF to localsplus index

- Add CO_FAST_LOCAL/CELL/FREE/HIDDEN constants and
  localspluskinds field to CodeObject for per-slot metadata
- Change DEREF instruction opargs from cell-relative indices
  (NameIdx) to localsplus absolute indices (oparg::VarNum)
- Add fixup_deref_opargs pass in ir.rs to convert cell-relative
  indices to localsplus indices after finalization
- Replace get_cell_name with get_localsplus_name in
  InstrDisplayContext trait
- Update VM cell_ref/get_cell_contents/set_cell_contents to use
  localsplus indices directly (no nlocals offset)
- Update function.rs cell2arg, super.rs __class__ lookup with
  explicit nlocals offsets

* Fix clippy warnings, formatting, restore _opcode_metadata.py

Fix cast_possible_truncation, nonminimal_bool, collapsible_if,
manual_contains clippy lints. Restore _opcode_metadata.py to
upstream/main version (3.14 aligned).

Pre-copy closure cells in Frame::new for coroutine locals().
Handle raw values in merged cell slots during inlined comps.
Exclude async comprehensions from inlining path.

* Exclude async/await comprehensions from PEP 709 inlining in symboltable

Async comprehensions and comprehensions with await in the element
expression need their own coroutine scope and cannot be inlined.
The symboltable builder was not checking these conditions, causing
incorrect symbol scope resolution when an async comprehension was
nested inside an inlined comprehension (e.g. [[x async for x in g]
for j in items]).
2026-03-21 22:48:35 +09:00
dependabot[bot]
4abe4c5bf0 Bump aws-lc-fips-sys from 0.13.12 to 0.13.13 (#7478)
Bumps [aws-lc-fips-sys](https://github.com/aws/aws-lc-rs) from 0.13.12 to 0.13.13.
- [Release notes](https://github.com/aws/aws-lc-rs/releases)
- [Commits](https://github.com/aws/aws-lc-rs/compare/aws-lc-fips-sys/v0.13.12...aws-lc-fips-sys/v0.13.13)

---
updated-dependencies:
- dependency-name: aws-lc-fips-sys
  dependency-version: 0.13.13
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-21 09:46:15 +09:00
Lee Dogeon
a1203ae207 Improve CPython compatibility related with PyBoundMethod (#7476)
* Add GetDescriptor for PyBoundMethod (return self)

CPython's method_descr_get always returns the bound method unchanged.
This preserves the original binding when __get__ is called on an
already-bound method (e.g. a.meth.__get__(b, B) still returns a).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add constructor validation for PyBoundMethod

Reject non-callable functions and None instances, matching CPython's
method_new which checks PyCallable_Check(func) and instance != Py_None.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix PyBoundMethod __reduce__ to propagate errors

Previously swallowed errors from get_attr with .ok(), silently
returning None. Now propagates errors matching CPython's method_reduce.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 00:33:40 +09:00
dependabot[bot]
5b6a479a1d Bump lexopt from 0.3.1 to 0.3.2 (#7470)
Bumps [lexopt](https://github.com/blyxxyz/lexopt) from 0.3.1 to 0.3.2.
- [Release notes](https://github.com/blyxxyz/lexopt/releases)
- [Changelog](https://github.com/blyxxyz/lexopt/blob/master/CHANGELOG.md)
- [Commits](https://github.com/blyxxyz/lexopt/compare/v0.3.1...v0.3.2)

---
updated-dependencies:
- dependency-name: lexopt
  dependency-version: 0.3.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-20 22:49:41 +09:00
Lee Dogeon
38f742aa8d Implement Hashable for PyBoundMethod (#7474) 2026-03-20 13:15:40 +00:00
김은빈
1b9dc4ef14 Detect list mutation during sort even when list length is unchanged (#7432)
* Detect list mutation during sort even when list length is unchanged

* Use mutation counter instead of capacity check for sort mutation detection

The capacity heuristic missed mutations when `clear()` reset capacity to
0 via `mem::take`. An AtomicU32 counter on PyList, incremented in
`borrow_vec_mut()`, reliably detects all mutations during sort.

* Hold write guard during sort mutation counter reads

* Fix list mutation counter race in `borrow_vec_mut`
2026-03-20 21:40:54 +09:00
Shahar Naveh
4141e74e14 Add zizmor CI (#7463) 2026-03-20 21:37:12 +09:00
Shahar Naveh
2ef77f82e1 Run CI tests with max processes (#7254)
* Run CI witb max cores

* Step for flaky MP tests

* Add `test_class` to flkay mp tests
2026-03-20 20:35:18 +09:00
Jeong, YunWon
8be5230a9b Fix allow_threads and EINTR handling (#7457)
* Fix allow_threads and EINTR handling

- Wrap Windows SemLock acquire wait with allow_threads
- Retry nanosleep on EINTR with remaining time instead of
  returning early
- Remove expectedFailure for test_sleep in _test_eintr.py

* Remove expectedFailureIfWindows for testHashComparisonOfMethods
2026-03-20 19:59:13 +09:00
dependabot[bot]
247044a805 Bump which from 8.0.0 to 8.0.2 (#7469)
Bumps [which](https://github.com/harryfei/which-rs) from 8.0.0 to 8.0.2.
- [Release notes](https://github.com/harryfei/which-rs/releases)
- [Changelog](https://github.com/harryfei/which-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/harryfei/which-rs/compare/8.0.0...8.0.2)

---
updated-dependencies:
- dependency-name: which
  dependency-version: 8.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-20 12:43:07 +09:00
Shahar Naveh
68cf736a9f Add cargo shear CI step (#7461)
* Add `cargo shear` CI step

* Remove some deps

* Move `ruff_python_parser` to dev deps

* Remove `thread_local` crate

* Cleanup `num-integer` usage

* Remove parser fro. wasm

* Remove windows-sys from venv launcher

* Update lock

* Resolve more

* Fix wasm

* Update lock
2026-03-20 12:42:51 +09:00
Shahar Naveh
53fa525fc9 Resume opcode to hold ResumeType (#7465) 2026-03-19 14:24:07 +00:00
Shahar Naveh
b11b8e66ce Add actionlint step (#7464) 2026-03-19 20:41:59 +09:00
김은빈
79e17cb1cf Fix subclass right-op dispatch for Python classes (#7462)
* Fix subclass right-op dispatch for Python classes

* Separate fallback queueing from subclass priority in op dispatch
2026-03-19 09:51:56 +09:00
Copilot
2f181efed8 Preserve str subclasses in ascii() for ASCII-only __repr__ results (#7455) 2026-03-19 09:48:42 +09:00
Shahar Naveh
9a5de28b79 Align _opcode_metadata.py to 3.14.3 (#7456)
* Align `_opcode_metadata.py` to 3.14.3

* Unmark passing test

* Ensure python 3.14 runs on CI

* Update banner

* Fix `test__opcode.py`

* Adjust generate script

* Fix docs
2026-03-18 22:09:00 +09:00
Shahar Naveh
31480243f0 Only save cache if running on main (#7460) 2026-03-18 21:57:19 +09:00
Shahar Naveh
f2765982cd Remove some tests from PLATFORM_INDEPENDENT_TESTS (#7459)
* Remove some platform dependent tests

* Mark failing tests
2026-03-18 21:55:56 +09:00
Jeong, YunWon
62edc4722a Add per-type vectorcall for builtin constructors (#7407)
Add vectorcall fast paths for dict, list, set, int, float, str,
bool, tuple, frozenset. Clear vectorcall when __init__/__new__ is
overridden in Python. Prevent constructor vectorcall inheritance
to heap subclasses. Fix stat_result to use struct_sequence_new
with reference-copy for hidden time fields.
2026-03-18 21:44:35 +09:00
Jeong, YunWon
0768cf80d3 Merge pull request #7440 from youknowone/pycode
Upgrade test_code and fix code bugs
2026-03-17 20:53:42 +09:00
Lee Dogeon
f868f81db6 Implement complex.from_number (#7453)
Co-authored-by: CPython Developers <>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 20:50:28 +09:00
Shahar Naveh
6b768ff702 Cleanup ci.yaml matrix usage (#7260)
* cleanup

* Don't enable all resources on windows
2026-03-17 20:46:33 +09:00
Jeong, YunWon
2ea5960998 update cspell config (#7452)
* add allowCompoundWords

* cspell dict
2026-03-17 20:18:31 +09:00
dependabot[bot]
2a61237341 Bump lz4_flex from 0.12.0 to 0.12.1 (#7449)
Bumps [lz4_flex](https://github.com/pseitz/lz4_flex) from 0.12.0 to 0.12.1.
- [Release notes](https://github.com/pseitz/lz4_flex/releases)
- [Changelog](https://github.com/PSeitz/lz4_flex/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pseitz/lz4_flex/compare/0.12.0...0.12.1)

---
updated-dependencies:
- dependency-name: lz4_flex
  dependency-version: 0.12.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-17 12:57:31 +09:00
dependabot[bot]
87f5c7dd29 Bump rustix from 1.1.3 to 1.1.4 (#7444)
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 1.1.3 to 1.1.4.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Changelog](https://github.com/bytecodealliance/rustix/blob/main/CHANGES.md)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v1.1.3...v1.1.4)

---
updated-dependencies:
- dependency-name: rustix
  dependency-version: 1.1.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-17 12:57:23 +09:00
dependabot[bot]
cda9f8247f Bump num_enum from 0.7.5 to 0.7.6 in the num_enum group (#7443)
Bumps the num_enum group with 1 update: [num_enum](https://github.com/illicitonion/num_enum).


Updates `num_enum` from 0.7.5 to 0.7.6
- [Commits](https://github.com/illicitonion/num_enum/compare/0.7.5...0.7.6)

---
updated-dependencies:
- dependency-name: num_enum
  dependency-version: 0.7.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: num_enum
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-17 12:57:14 +09:00
dependabot[bot]
d04490ee25 Bump actions/download-artifact from 8.0.0 to 8.0.1 (#7448)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 8.0.0 to 8.0.1.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v8...v8.0.1)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 8.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-17 12:56:58 +09:00
dependabot[bot]
b2b337588d Bump strum_macros from 0.27.2 to 0.28.0 (#7445)
Bumps [strum_macros](https://github.com/Peternator7/strum) from 0.27.2 to 0.28.0.
- [Release notes](https://github.com/Peternator7/strum/releases)
- [Changelog](https://github.com/Peternator7/strum/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Peternator7/strum/compare/v0.27.2...v0.28.0)

---
updated-dependencies:
- dependency-name: strum_macros
  dependency-version: 0.28.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-17 12:24:29 +09:00
Jeong, YunWon
c57f4decd5 Fix test_code: compiler and code object improvements
- Add CO_NESTED flag (0x10) for nested function scopes
- Emit LOAD_SMALL_INT for integers 0..=255 instead of LOAD_CONST
- Eliminate dead constant expression statements (no side effects)
- Ensure None in co_consts for functions with no other constants
- Add code.__replace__() for copy.replace() support
- Mark test_co_lnotab and test_invalid_bytecode as expectedFailure
2026-03-17 10:54:12 +09:00
dependabot[bot]
423b6ca59b Bump marocchino/sticky-pull-request-comment from 2 to 3 (#7447)
Bumps [marocchino/sticky-pull-request-comment](https://github.com/marocchino/sticky-pull-request-comment) from 2 to 3.
- [Release notes](https://github.com/marocchino/sticky-pull-request-comment/releases)
- [Commits](https://github.com/marocchino/sticky-pull-request-comment/compare/v2...v3)

---
updated-dependencies:
- dependency-name: marocchino/sticky-pull-request-comment
  dependency-version: '3'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-16 23:45:52 +09:00
dependabot[bot]
caca67cf27 Bump github/gh-aw from 0.56.2 to 0.58.3 (#7446)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.56.2 to 0.58.3.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](f1073c5498...08a903b1fb)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.58.3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-16 23:45:26 +09:00
Lee Dogeon
5f1d5d2815 Cleanup some direct magic method definitions (#7441)
* Migrate direct __repr__ definitions to Representable trait

Move legacy #[pymethod] __repr__ to impl Representable for:
- PySSLContext, PySSLSocket (ssl.rs)
- BufferedReader, BufferedWriter, BufferedRandom (_io.rs)

Enable __repr__ guard in derive to prevent future direct definitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Migrate direct __del__ definition to Destructor trait for PySocket

Move #[pymethod] __del__ to impl Destructor for PySocket.
Preserves ResourceWarning emission and close behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Remove redundant __iter__ pymethods from PyFuture and PyTask

Both types already have impl Iterable, so the direct #[pymethod]
__iter__ definitions were duplicates. Enable __iter__/__next__
guards in derive to prevent future direct definitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Enable derive guards for __get__/__set__/__delete__ descriptor methods

All concrete types already use GetDescriptor/SetDescriptor traits.
Activate the compile-time guard to prevent future direct definitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Enable derive guards for AsMapping/AsSequence slot methods

Remove redundant #[pymethod(name = "__len__")] from PyStr
(already provided via AsMapping/AsSequence trait impls).

Enable compile-time guards for __len__, __contains__, __getitem__,
__setitem__, __delitem__ to prevent future direct definitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 22:49:45 +09:00
Jeong, YunWon
f27490c92b Consume nested scope tables in optimized-out asserts (#7438)
When -O flag removes assert statements, any nested scopes
(generators, comprehensions, lambdas) inside the assert
expression still have symbol tables in the sub_tables list.
Without consuming them, the next_sub_table index gets
misaligned, causing later scopes to use wrong symbol tables.

Walk the skipped assert expression with an AST visitor to
find and consume nested scope symbol tables, keeping the
index aligned with AST traversal order.
2026-03-16 16:09:17 +09:00
Jeong, YunWon
d2d2822bb9 Implement code object __eq__/__hash__
- Add Comparable and Hashable traits for PyCode
- Compare by name, args, flags, bytecode, consts, names, vars, linetable
- Hash by tuple of key attributes matching CPython's code_hash
- Remove unused custom_ops slice in Instruction::try_from
- Add co_lnotab intentional non-implementation comment
2026-03-16 15:25:29 +09:00
Jeong, YunWon
47c2acd40e Fix code_offset_to_line handling 2026-03-16 15:25:29 +09:00
CPython Developers
2b06a0b172 Upgrade test_code from CPython 3.14.3 2026-03-16 15:25:29 +09:00
Shahar Naveh
f1ddb4fc5e Pin checkout to commit. Don't persist creds if not needed (#7430) 2026-03-16 12:34:43 +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
03b7c4ebb8 Mark RustPython 0.5.0 2026-03-16 11:32:27 +09:00
ShaharNaveh
f49af3fd48 Update _test_eintr.py from 3.14.3 2026-03-16 00:10:09 +09:00
Lee Dogeon
9ddd07a656 Preserve imaginary zero signs when adding real values to complex numbers (#7421)
* Preserve imaginary zero signs when adding real values to complex numbers

* Refactor complex_add with match expression

* Correct complex real subtract op

* Remove unnecessary vm arugment
2026-03-15 17:04:23 +09:00
Shahar Naveh
9a297aad2b Newtype var_nums oparg (#7431) 2026-03-15 17:01:03 +09:00
Shahar Naveh
005860cc0b Don't trigger update libs status on forks (#7428) 2026-03-14 20:23:08 +09:00
Shahar Naveh
0c14ad195e Update ruff to 0.15.6 (#7427)
* Update ruff to `0.15.6`

* Unmark passing tests
2026-03-14 20:22:42 +09:00
Lee Dogeon
d1ea35962b Match divmod zero-division message with CPython (#7426) 2026-03-14 20:21:23 +09:00
Jeong, YunWon
40fc7c210d Upgrade pymath to 0.2.0 (#7429) 2026-03-14 20:13:30 +09:00
Jiseok CHOI
430eb5ffe4 Fix sqlite3 Cursor.fetchmany to not fetch rows when size=0 (#7425) 2026-03-14 15:49:55 +09:00
Lee Dogeon
e7d2b57dcc Match __module__ setter behavior to CPython (#7424)
* Remove stale __firstlineno__ when updating type.__module__

* Register and use __firstlineno__ as identifier
2026-03-14 15:48:48 +09:00
Lee Dogeon
21d549caf6 Handle chr() range checks without Rust integer overflow (#7422) 2026-03-14 15:47:45 +09:00
Lee Dogeon
ed032d31fb Make singleton builtin types immutable (#7423) 2026-03-14 09:45:43 +09:00
Shahar Naveh
4483c31c65 Update test_marshal.py from 3.14.3 (#7409)
---------

Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>
2026-03-14 09:45:12 +09:00
Jeong, YunWon
be6025ab03 Adapt bitflagset to use enum (#7419) 2026-03-14 09:44:02 +09:00
Jiseok CHOI
7d63f65f21 Fix classmethod descr_get to match CPython behavior (#7420)
Simplify classmethod.__get__ to always create a PyBoundMethod binding
  the callable to the class, matching CPython's cm_descr_get which simply
  calls PyMethod_New(cm->cm_callable, type).

  The previous implementation incorrectly tried to call __get__ on the
  wrapped callable, which broke when a bound method was passed to
  classmethod() (e.g. classmethod(A().foo)).
2026-03-14 03:40:16 +09:00
Jeong, YunWon
073adbd8da Fix SSL read over-consuming TCP data (#7418)
Use single-record reading (recv_one_tls_record) for all SSL
reads, not just handshake. This prevents rustls from eagerly
consuming close_notify alongside application data, which left
the TCP buffer empty and caused select()-based servers to miss
readability and time out.

Also fix recv_one_tls_record to return Eof (not WantRead) when
peek returns empty bytes, since empty peek means the peer has
closed the TCP connection.
2026-03-13 21:02:31 +09:00
Jeong, YunWon
7c0981b9ce Fix SSL handshake over-reading in STARTTLS (#7417)
During STARTTLS handshake, sock_recv(16KB) could consume
application data that arrived alongside handshake records.
The consumed data ended up in rustls's internal buffer where
select() could not detect it, causing asyncore-based servers
to miss readable events and the peer to time out.

Use MSG_PEEK to find the TLS record boundary, then recv()
only one complete record. Remaining data stays in the kernel
TCP buffer, visible to select(). This matches OpenSSL's
default no-read-ahead behaviour.

Fixes flaky test_poplib (TestPOP3_TLSClass) failures.
2026-03-13 11:46:35 +09:00
김은빈
a733c8baa7 Fix weakref proxy number protocol, right-side ops, and non-iterator error (#7410) 2026-03-13 11:36:16 +09:00
dependabot[bot]
83e3785a1c Bump memmap2 from 0.9.9 to 0.9.10 (#7415)
Bumps [memmap2](https://github.com/RazrFalcon/memmap2-rs) from 0.9.9 to 0.9.10.
- [Changelog](https://github.com/RazrFalcon/memmap2-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/RazrFalcon/memmap2-rs/compare/v0.9.9...v0.9.10)

---
updated-dependencies:
- dependency-name: memmap2
  dependency-version: 0.9.10
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-13 10:19:04 +09:00
dependabot[bot]
f4eaee1a62 Bump quote from 1.0.44 to 1.0.45 (#7414)
Bumps [quote](https://github.com/dtolnay/quote) from 1.0.44 to 1.0.45.
- [Release notes](https://github.com/dtolnay/quote/releases)
- [Commits](https://github.com/dtolnay/quote/compare/1.0.44...1.0.45)

---
updated-dependencies:
- dependency-name: quote
  dependency-version: 1.0.45
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-13 08:53:48 +09:00
dependabot[bot]
021286e9ab Bump the openssl group with 2 updates (#7413)
Bumps the openssl group with 2 updates: [openssl](https://github.com/rust-openssl/rust-openssl) and [openssl-sys](https://github.com/rust-openssl/rust-openssl).


Updates `openssl` from 0.10.75 to 0.10.76
- [Release notes](https://github.com/rust-openssl/rust-openssl/releases)
- [Commits](https://github.com/rust-openssl/rust-openssl/compare/openssl-v0.10.75...openssl-v0.10.76)

Updates `openssl-sys` from 0.9.111 to 0.9.112
- [Release notes](https://github.com/rust-openssl/rust-openssl/releases)
- [Commits](https://github.com/rust-openssl/rust-openssl/compare/openssl-sys-v0.9.111...openssl-sys-v0.9.112)

---
updated-dependencies:
- dependency-name: openssl
  dependency-version: 0.10.76
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: openssl
- dependency-name: openssl-sys
  dependency-version: 0.9.112
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: openssl
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-13 08:53:28 +09:00
Jeong, YunWon
7c05bef5ff Merge pull request #7411 from youknowone/ci-format
Fix pr-format CI to fail on formatting changes
2026-03-13 08:53:01 +09:00
Shahar Naveh
b58a910026 Upgrade libc to 0.2.183 (#7406) 2026-03-13 01:21:18 +09:00
EtherealPsyche
0f61464c54 If the host_env feature is enabled, then enable the _ctypes module on the Android platform. (#7402) 2026-03-13 01:20:32 +09:00
Jeong, YunWon
a14f856af4 fmt 2026-03-13 01:19:10 +09:00
Jeong, YunWon
bdfe2cf923 Fix pr-format CI to fail on formatting changes
Add git diff --exit-code step to fail the check when
formatters produce changes. Previously reviewdog only
posted suggestions without failing the workflow.
2026-03-13 01:19:10 +09:00
김은빈
61b3b4f42b Add strict parameter to map() builtin (#7405)
* Add strict parameter to map() builtin

* Refactor map IterNext to match zip style
2026-03-12 15:02:53 +00:00
Jeong, YunWon
f26752c5ef Merge pull request #7408 from ShaharNaveh/update-test-gen
Update generator related tests from 3.14.3
2026-03-12 23:47:31 +09:00
Jeong, YunWon
04b1febd3b Merge pull request #7404 from moreal/bump-3.14.3-modulefinder
Bump 3.14.3 modulefinder
2026-03-12 23:42:27 +09:00
Shahar Naveh
bb36783206 Newtype oparg align methods (#7403)
* Align methods for newtype opargs
2026-03-12 23:41:21 +09:00
ShaharNaveh
93865e6523 Update test_yield_from.py from 3.14.3 2026-03-12 13:33:04 +01:00
ShaharNaveh
8530439202 Mark failing tests 2026-03-12 13:24:29 +01:00
ShaharNaveh
9a20be7b9e Update test_generators.py from 3.14.3 2026-03-12 13:21:30 +01:00
ShaharNaveh
fcd1bb6e9b Add test_generator_stop.py from 3.14.3 2026-03-12 13:19:19 +01:00
Lee Dogeon
e9ab35fdd7 Mark failing tests for modulefinder
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 20:52:26 +09:00
CPython Developers
ca5a3a7c88 Update modulefinder from v3.14.3 2026-03-12 20:52:24 +09:00
Jeong, YunWon
c578ac0b21 gc: add CollectResult, stats fields, get_referrers, and fix count reset (#7354)
* gc: add CollectResult, stats fields, get_referrers, and fix count reset

- Add CollectResult struct with collected/uncollectable/candidates/duration
- Add candidates and duration fields to GcStats and gc.get_stats()
- Pass CollectResult to gc.callbacks info dict
- Reset generation counts for all collected generations (0..=N)
- Return 0 for third value in gc.get_threshold() (3.13+)
- Implement gc.get_referrers() by scanning all tracked objects
- Add DEBUG_COLLECTABLE output for collectable objects
- Update test_gc.py to expect candidates/duration in stats

* Update test_gc from v3.14.3

* Update test_gc.py from CPython v3.15.0a5

Taken from v3.15 (not v3.14.3) because get_stats() candidates/duration
fields were added in 3.13+ and the corresponding test assertions only
exist in 3.15.

* Fix gc_state build on wasm32: skip Instant timing

* Add candidates/duration to gc callback info, mark v3.15 test failures

* Fix gc.get_referrers to exclude executing frames, fix Future cancelled exc leak

- get_referrers: skip frame objects on the execution stack, since
  they are not GC-tracked in CPython (_PyInterpreterFrame)
- _asyncio Future/Task make_cancelled_error_impl: clear the stored
  cancelled exception after returning it, matching the Python
  _make_cancelled_error behavior

* Fix gc.get_threshold to return actual gen2 threshold value

* Fix inconsistent GC count reset in early-return paths

Use the same reset_end formula in unreachable-empty early returns
as in the main collection path and collecting-empty path.

* Accept keyword arguments in socket.__init__

Use a FromArgs struct instead of a positional-only tuple so that
family, type, proto, and fileno can be passed as keyword arguments.

* Disable comp_inlined in symbol table to match compiler

The compiler does not yet implement PEP 709 inlined comprehensions
(is_inlined_comprehension_context always returns false), but the
symbol table was marking comprehensions as inlined. This mismatch
could cause comprehension-local symbols to be merged into the parent
scope while the compiler still looks them up in a separate scope.

---------

Co-authored-by: CPython Developers <>
2026-03-12 20:48:22 +09:00
CPython Developers
331029e043 Update poplib from v3.14.3 2026-03-12 18:08:56 +09:00
dependabot[bot]
3f20619ee0 Bump socket2 from 0.6.2 to 0.6.3 (#7373)
Bumps [socket2](https://github.com/rust-lang/socket2) from 0.6.2 to 0.6.3.
- [Release notes](https://github.com/rust-lang/socket2/releases)
- [Changelog](https://github.com/rust-lang/socket2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/socket2/compare/v0.6.2...v0.6.3)

---
updated-dependencies:
- dependency-name: socket2
  dependency-version: 0.6.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-12 11:00:24 +09:00
Shahar Naveh
da745ba48e Enable jit on macos (#7401) 2026-03-12 09:20:24 +09:00
Shahar Naveh
5c631e5129 Newtype var_num oparg (#7400) 2026-03-12 09:20:01 +09:00
Shahar Naveh
7e4727001d Use matrix for cargo check (#7388)
* Use matrix for cargo_check

* Tweak `gcc-aarch64-linux-gnu` deps

* Re-add redox comment
2026-03-11 22:21:25 +09:00
Jeong, YunWon
85eca218af Fix atexit unraisable exception message format (#7399)
* Fix atexit unraisable exception message format

Match PyErr_FormatUnraisable behavior: use
"Exception ignored in atexit callback {func!r}" as err_msg
and pass None as object instead of the callback function.

* Fix atexit unregister deadlock with reentrant __eq__

Release the lock during equality comparison in unregister so
that __eq__ can safely call atexit.unregister or atexit._clear.
Store callbacks in LIFO order (insert at front) and use
identity-based search after comparison to handle list mutations,
matching atexitmodule.c behavior.

Also pass None as err_msg when func.repr() fails, matching
CPython's PyErr_FormatUnraisable fallback.
2026-03-11 22:20:37 +09:00
Jeong, YunWon
d248a04cae Refine specialization caches and extend binary-op coverage (#7386)
* Align BINARY_OP_EXTEND with CPython descriptor cache model

* Align type _spec_cache and latin1 singleton string paths

* Add specialization differential harness and align init error text

* Tighten CALL_ALLOC_AND_ENTER_INIT stack-space guard

* Align call-init frame flow and spec cache atomic ordering

* Refine call-init recursion guard and cache swap lifetime handling

* Align spec cache write locking with CPython contract

* Align load attr miss cooldown with CPython

* Align CALL descriptor and class-call specialization with CPython

* Extract datastack_frame_size_bytes_for_code, skip monitoring for init_cleanup frames, guard trace dispatch

- Extract datastack_frame_size_bytes_for_code as free function, use it
  to compute init_cleanup stack bytes instead of hardcoded constant
- Add monitoring_disabled_for_code to skip instrumentation for
  synthetic init_cleanup code object in RESUME and execute_instrumented
- Add is_trace_event guard so profile-only events skip trace_func dispatch
2026-03-10 15:39:55 +09:00
Jeong, YunWon
a854ef2a2b Rename stdlib files to match Python module names (#7397) 2026-03-10 15:29:17 +09:00
Jeong, YunWon
45d93f4b20 Save errno inside allow_threads in semaphore acquire (#7391)
allow_threads may call attach_thread() on return, which
can invoke syscalls that clobber errno. Capture errno
inside the closure before it is lost.
2026-03-10 14:04:28 +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
e645761142 Implement _tokenize and update tokenize from v3.14.3 (#7392)
* Base implementation of _tokenize module

Port from PR #6240 by ShaharNaveh, adapted to current codebase.
Uses ruff_python_parser for tokenization via TokenizerIter.

* Update tokenize from v3.14.3

* Rewrite _tokenize with 2-phase model

Replace per-line reparsing with single-pass tokenization:
- Read all lines via readline, parse once, yield tokens
- Fix token type values (COMMENT=65, NL=66, OP=55)
- Fix NEWLINE/NL end positions and implicit newline handling
- Fix DEDENT positions via look-ahead to next non-DEDENT token
- Handle FSTRING_MIDDLE brace unescaping ({{ → {, }} → })
- Emit implicit NL before ENDMARKER when source lacks trailing newline
- Raise IndentationError from lexer errors
- Remove 13 expectedFailure marks for now-passing tests

---------

Co-authored-by: ShaharNaveh <shaharnaveh@users.noreply.github.com>
Co-authored-by: CPython Developers <>
2026-03-10 12:27:09 +09:00
dependabot[bot]
ae8d8c7926 Bump insta from 1.46.1 to 1.46.3 (#7394)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.46.1 to 1.46.3.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.46.1...1.46.3)

---
updated-dependencies:
- dependency-name: insta
  dependency-version: 1.46.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-10 11:50:31 +09:00
Jeong, YunWon
55737ede63 Rewrite _tokenize with 2-phase model
Replace per-line reparsing with single-pass tokenization:
- Read all lines via readline, parse once, yield tokens
- Fix token type values (COMMENT=65, NL=66, OP=55)
- Fix NEWLINE/NL end positions and implicit newline handling
- Fix DEDENT positions via look-ahead to next non-DEDENT token
- Handle FSTRING_MIDDLE brace unescaping ({{ → {, }} → })
- Emit implicit NL before ENDMARKER when source lacks trailing newline
- Raise IndentationError from lexer errors
- Remove 13 expectedFailure marks for now-passing tests
2026-03-10 11:28:16 +09:00
CPython Developers
bf2b993c93 Update tokenize from v3.14.3 2026-03-10 11:28:16 +09:00
ShaharNaveh
5c5aff8fd9 Base implementation of _tokenize module
Port from PR #6240 by ShaharNaveh, adapted to current codebase.
Uses ruff_python_parser for tokenization via TokenizerIter.
2026-03-10 11:28:16 +09:00
dependabot[bot]
5b0fb03fc4 Bump syn from 2.0.114 to 2.0.117 (#7393)
Bumps [syn](https://github.com/dtolnay/syn) from 2.0.114 to 2.0.117.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/2.0.114...2.0.117)

---
updated-dependencies:
- dependency-name: syn
  dependency-version: 2.0.117
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-10 10:24:58 +09:00
dependabot[bot]
d81db8afc5 Bump actions/checkout from 4 to 6 (#7396)
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Commits](https://github.com/actions/checkout/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-10 00:46:25 +09:00
dependabot[bot]
13a89be61b Bump github/gh-aw from 0.51.5 to 0.56.2 (#7395)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.51.5 to 0.56.2.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](88319be75a...f1073c5498)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.56.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-10 00:46:01 +09:00
Jeong, YunWon
2266ba7f47 Add per-size tuple freelist (20 buckets × 2000 each) (#7361)
* Add per-size tuple freelist (20 buckets × 2000 each)

Implement PyTuple freelist matching tuples[PyTuple_MAXSAVESIZE]:
- TupleFreeList with 20 per-size buckets (sizes 1..=20, 2000 capacity each)
- freelist_push uses pre-clear size hint for correct bucket selection
- freelist_pop takes &Self payload to select bucket by size
- Type guard in new_ref handles structseq types sharing PyTuple vtable
- Add pyinner_layout<T>() helper for custom freelist Drop impls
- Update freelist_pop/push signatures across all freelist types

* freelist: exact type check at pop call-site

Move exact-type filtering from freelist_pop implementations to the
single call-site in new_ref. This prevents structseq and other subtypes
from popping tuple freelist entries entirely, rather than popping and
then deallocating on type mismatch.

Add Context::try_genesis() that returns None during bootstrap to avoid
deadlock when genesis() is called during Context initialization.

* Move exact type check from freelist_push to call-site in default_dealloc

Remove typ parameter from freelist_push trait signature. The exact type
check is now done once at the call-site alongside the heaptype check,
simplifying all freelist_push implementations.

* Remove freelist_hint; call freelist_push before tp_clear

By calling freelist_push before tp_clear, the payload is still intact
and can be read directly (e.g. tuple element count for bucket selection).
This eliminates freelist_hint and the hint parameter entirely.
2026-03-09 22:34:37 +09:00
Jeong, YunWon
6c12152aeb rustfmt (#7390) 2026-03-09 22:31:29 +09:00
Shahar Naveh
82e9b5d9e1 Newtype ConstIdx, Constants (#7358)
* Newtype ConstIdx, Constants

* Set generic
2026-03-09 11:47:24 +09:00
Jiseok CHOI
fa4f84ce3f Introduce TimeoutSeconds utility type for timeout parameters (#7271)
* Introduce TimeoutSeconds utility type for timeout parameters

Follow-up refactoring from #7237.

Python timeout parameters typically accept both float and int. Several
places in the codebase used Either<f64, i64> for this, each repeating
the same match-and-convert boilerplate. This extracts that into a
TimeoutSeconds type in vm::function::number.

Refactored sites:
- _sqlite3::ConnectArgs.timeout
- _thread::AcquireArgs.timeout
- _thread::ThreadHandle::join timeout

Either<f64, i64> in time.rs (6 sites) left unchanged: those are
timestamp values with per-branch logic (floor, range checks, etc).
Either<f64, isize> in select.rs also left unchanged (different type).

* Validate timeout in ThreadHandle::join to prevent panic

* refactor: move TimeoutSeconds from number to time module
2026-03-09 11:36:03 +09:00
Jeong, YunWon
ead2d98557 Separate WeakRefList from ObjExt as independent prefix (#7365)
- Remove weak_list from ObjExt, allocate WeakRefList as its own
  prefix slot before PyInner
- Add MANAGED_WEAKREF flag (1 << 3) to PyTypeFlags
- Normalize MANAGED_WEAKREF from HAS_WEAKREF after flag assembly
- Use Layout::extend offsets in bootstrap allocator
2026-03-09 02:09:26 +09:00
Jeong, YunWon
ce8952b1f5 Use borrowed pointers in TYPE_CACHE instead of strong references (#7384)
The method cache (TYPE_CACHE) was storing strong references (Arc
clones) to cached attribute values, which inflated sys.getrefcount().
This caused intermittent test_memoryview failures where refcount
assertions would fail depending on GC collection timing.

Store borrowed raw pointers instead. Safety is guaranteed because:
- type_cache_clear() nullifies all entries during GC collection,
  before the collector breaks cycles
- type_cache_clear_version() nullifies entries when a type is
  modified, before the source dict entry is removed
- Readers use try_to_owned_from_ptr (safe_inc) to atomically
  validate and increment the refcount on cache hit
2026-03-08 22:55:22 +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
Jeong, YunWon
45d81296e4 More fork safety (#7380)
* apply more allow_threads

* Simplify STW thread state transitions

- Fix park_detached_threads: successful CAS no longer sets
  all_suspended=false, avoiding unnecessary polling rounds
- Replace park_timeout(50µs) with park() in wait_while_suspended
- Remove redundant self-suspension in attach_thread and detach_thread;
  the STW controller handles DETACHED→SUSPENDED via park_detached_threads
- Add double-check under mutex before condvar wait to prevent lost wakes
- Remove dead stats_detach_wait_yields field and add_detach_wait_yields

* Representable for ThreadHandle

* Set ThreadHandle state to Running in parent thread after spawn

Like CPython's ThreadHandle_start, set RUNNING state in the parent
thread immediately after spawn() succeeds, rather than in the child.
This eliminates a race where join() could see Starting state if called
before the child thread executes.

Also reverts the macOS skip for test_start_new_thread_failed since the
root cause is fixed.

* Set ThreadHandle state to Running in parent thread after spawn

* Add debug_assert for thread state in start_the_world

* Unskip now-passing test_get_event_loop_thread and test_start_new_thread_at_finalization

* Wrap IO locks and file ops in allow_threads

Add lock_wrapped to ThreadMutex for detaching thread state
while waiting on contended locks. Use it for buffered and
text IO locks. Wrap FileIO read/write in allow_threads via
crt_fd to prevent STW hangs on blocking file operations.

* Use std::sync for thread start/ready events

Replace parking_lot Mutex/Condvar with std::sync (pthread-based)
for started_event and handle_ready_event. This prevents hangs
in forked children where parking_lot's global HASHTABLE may be
corrupted.
2026-03-08 18:06:23 +09:00
Jeong, YunWon
0046c627f1 Wait for overlapped WriteFile completion in Rust (#7383)
On Windows, SimpleQueue skips write locking because pipe
writes are assumed atomic. Without GIL, PipeConnection.
_send_bytes races on _send_ov when multiple threads call
send_bytes concurrently (e.g. _terminate_pool vs workers).

Wait for pending overlapped writes inside WriteFile before
returning to Python, so ERROR_IO_PENDING is never exposed
and the _send_ov assignment window is negligible.
2026-03-08 18:04:19 +09:00
Shahar Naveh
fbab8fc5be Update ruff to 0.15.5 (#7366) 2026-03-08 10:36:27 +09:00
Shahar Naveh
e669944efe Unified action for installing Linux deps (#7381) 2026-03-08 10:35:24 +09:00
Shahar Naveh
f680f8a181 Unified action for installing macos deps (#7379)
* Add `install-macos-deps` action

* Use new action
2026-03-07 21:13:42 +09:00
dependabot[bot]
abfb51efc9 Bump uuid from 1.21.0 to 1.22.0 (#7372)
Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.21.0 to 1.22.0.
- [Release notes](https://github.com/uuid-rs/uuid/releases)
- [Commits](https://github.com/uuid-rs/uuid/compare/v1.21.0...v1.22.0)

---
updated-dependencies:
- dependency-name: uuid
  dependency-version: 1.22.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-07 20:30:52 +09:00
Shahar Naveh
28bda1d34f Fix error message in ctypes (#7368)
* Remove unnecessary `to_{owned,string}()` calls (#7367)

* Fix error message in ctype
2026-03-07 20:30:09 +09:00
dependabot[bot]
89889acc08 Bump rustls from 0.23.36 to 0.23.37 (#7374)
Bumps [rustls](https://github.com/rustls/rustls) from 0.23.36 to 0.23.37.
- [Release notes](https://github.com/rustls/rustls/releases)
- [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rustls/rustls/compare/v/0.23.36...v/0.23.37)

---
updated-dependencies:
- dependency-name: rustls
  dependency-version: 0.23.37
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-07 20:29:23 +09:00
Shahar Naveh
4aeec7f2dc Remove duplicate cargo check (#7377) 2026-03-07 20:28:58 +09:00
Shahar Naveh
ab32c785ea Restructure CI with matrix approach and multi-feature support (#7376)
* `--features` flag can take multiple values

* Simplify CI job

* Remove bad default

* Enable jit on macOS
2026-03-07 20:28:26 +09:00
Shahar Naveh
d9020c5841 Unpin nightly channel for miri tests (#7378) 2026-03-07 20:22:07 +09:00
Jeong, YunWon
2bb9173caf Suspend Python threads before fork() (#7364)
* Suspend Python threads before fork()

Add stop-the-world thread suspension around fork() to prevent
deadlocks from locks held by dead parent threads in the child.

- Thread states: DETACHED / ATTACHED / SUSPENDED with atomic CAS
  transitions matching _PyThreadState_{Attach,Detach,Suspend}
- stop_the_world / start_the_world: park all non-requester threads
  before fork, resume after (parent) or reset (child)
- allow_threads (Py_BEGIN/END_ALLOW_THREADS): detach around blocking
  syscalls (os.read/write, waitpid, Lock.acquire, time.sleep) so
  stop_the_world can force-park via CAS
- Acquire/release import lock around fork lifecycle
- zero_reinit_after_fork: generic lock reset for parking_lot types
- gc_clear_raw: detach dict instead of clearing entries
- Lock-free double-check for descriptor cache reads (no read-side
  seqlock); write-side seqlock retained for writer serialization
- fork() returns PyResult, checks PythonFinalizationError, calls
  sys.audit
2026-03-07 20:20:16 +09:00
Jeong, YunWon
ed5bffeec6 replace auto commit to format suggestion (#7375) 2026-03-07 14:53:25 +09:00
Shahar Naveh
fc1c27896b Remove unnecessary to_{owned,string}() calls (#7367) 2026-03-07 00:06:18 +09:00
CPython Developers
a27d812286 Update locale from v3.14.3 2026-03-06 06:00:08 +09:00
Jeong, YunWon
04cf5dacca Object header slimming: prefix allocation for ObjExt (#7334)
* Object header slimming: prefix allocation for ObjExt

Extract dict, weak_list, and slots fields from PyInner<T> into a
separate ObjExt struct allocated as a prefix before PyInner using
Layout::extend(). Objects that don't need these fields (int, str,
float, list, tuple, dict, etc.) skip the prefix entirely.

- Add HAS_WEAKREF flag to PyTypeFlags for per-type weakref control
- Add HAS_EXT bit to GcBits indicating prefix presence
- Define ObjExt struct with dict, weak_list, slots
- Shrink PyInner header from ~80-88 bytes to ~32 bytes for lightweight objects
- Update all accessor methods to go through ext_ref()
- Update bootstrap type hierarchy to use prefix allocation
- Add __weakref__ getset descriptor for heap types
- Set HAS_WEAKREF on builtin types that support weak references
- Remove test_weak_keyed_bad_delitem expectedFailure (now passes)

* Add HAS_WEAKREF to _asyncio Future/Task, rename weakref helpers

- Add HAS_WEAKREF flag to PyFuture and PyTask (matches CPython)
- Rename subtype_getweakref/setweakref to subtype_get_weakref/set_weakref
  to fix cspell unknown word lint

* Add HAS_WEAKREF to array, deque, _grouper; remove expectedFailure markers

- Add HAS_WEAKREF to PyArray and PyDeque (matches CPython)
- Add HAS_WEAKREF to PyItertoolsGrouper (internal use by groupby)
- Remove 6 expectedFailure markers from test_dataclasses for weakref/slots
  tests that now pass

* Add HAS_WEAKREF to code, union, partial, lock, IO, mmap, sre, sqlite3, typevar types

Add HAS_WEAKREF flag to built-in types that support weakref:
- PyCode, PyUnion, PyPartial, Lock, RLock
- All IO base/concrete classes (_IOBase, _RawIOBase, _BufferedIOBase,
  _TextIOBase, BufferedReader, BufferedWriter, BufferedRandom,
  BufferedRWPair, TextIOWrapper, StringIO, BytesIO, FileIO,
  WindowsConsoleIO)
- PyMmap, sre Pattern, sqlite3 Connection/Cursor
- TypeVar, ParamSpec, ParamSpecArgs, ParamSpecKwargs, TypeVarTuple

Remove 3 expectedFailure markers from test_descr for now-passing tests.

* Add HAS_DICT to type flags and handle non-METHOD/CLASS in descr_get

- Add HAS_DICT flag to PyType (type metaclass) alongside existing
  HAS_WEAKREF. All type objects are instances of type and need dict
  support, matching CPython's PyType_Type.
- Replace unimplemented!() in PyMethodDescriptor::descr_get with
  fallback to bind obj directly, matching CPython's method_get which
  uses PyCFunction_NewEx for non-METH_METHOD methods.

* Fix ext detection, HeapMethodDef ownership, WASM error

- Remove HAS_EXT gc_bits flag; detect ext from type flags
  using raw pointer reads to avoid Stacked Borrows violations
- Store HeapMethodDef owner in payload instead of dict hack
- Clear dict entries in gc_clear_raw to break cycles
- Add WASM error fallback when exception serialization fails
2026-03-06 01:19:22 +09:00
Jeong, YunWon
3b91466f62 Implement locale-aware 'n' format specifier for int, float, complex (#7350)
* Implement locale-aware 'n' format specifier for int, float, complex

Add LocaleInfo struct and locale-aware formatting methods to FormatSpec.
The 'n' format type now reads thousands_sep, decimal_point, and grouping
from C localeconv() and applies proper locale-based number grouping.
Remove @unittest.skip from test_format.test_locale.

* Fix complex 'n' format and remove locale expectedFailure markers

Rewrite format_complex_locale to reuse format_complex_re_im, matching
formatter_unicode.c: add_parens=0 and skip_re=0 for 'n' type.
Remove @expectedFailure from test_float__format__locale and
test_int__format__locale in test_types.py.

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-06 01:09:43 +09:00
Jeong, YunWon
7620c28482 Tighten specialization guards and add send_none fastpath (#7359)
* vm: align specialization guards with CPython patterns

* vm: tighten call specialization runtime guards

* vm: add send_none fastpath for generator specialization

* vm: restrict method-descriptor specialization to methods

* vm: deopt call specializations on guard misses

* vm: match CPython send/for-iter closed-frame guards

* vm: restrict len/isinstance specialization to builtins

* vm: use exact-type guards for call specializations

* vm: align class-call specialization flow with CPython

* vm: prefer FAST call opcodes for positional builtin calls

* vm: add callable identity guard to CALL_LIST_APPEND

* vm: make CALL_LIST_APPEND runtime guard pointer-based

* vm: align call guard cache and fallback behavior with CPython

* vm: use base vectorcall fallback for EXIT-style call misses

* vm: simplify CALL_LEN/CALL_ISINSTANCE runtime guards

* vm: infer call-convention flags for CPython-style CALL specialization

* vm: check use_tracing in eval_frame_active, add SendGen send_none

- Implement specialization_eval_frame_active to check vm.use_tracing
  so specializations are skipped when tracing/profiling is active
- Add send_none fastpath in SendGen handler for the common None case
2026-03-06 00:59:53 +09:00
dependabot[bot]
9ba155418b Bump aws-lc-fips-sys from 0.13.11 to 0.13.12 (#7338)
Bumps [aws-lc-fips-sys](https://github.com/aws/aws-lc-rs) from 0.13.11 to 0.13.12.
- [Release notes](https://github.com/aws/aws-lc-rs/releases)
- [Commits](https://github.com/aws/aws-lc-rs/commits/aws-lc-fips-sys/v0.13.12)

---
updated-dependencies:
- dependency-name: aws-lc-fips-sys
  dependency-version: 0.13.12
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-06 00:02:14 +09:00
Lee Dogeon
6f07745600 Fold const bool with unary not (#7357)
* Fold const bool with unary not

* Fold unnecessary TO_BOOL
2026-03-05 23:00:47 +09:00
Jeong, YunWon
73941b2255 Extract InterpreterFrame from Frame with Deref wrapper (#7353)
* Remove cells_frees duplicate storage from Frame

Cell/free variable objects were stored in both a separate
`Box<[PyCellRef]>` (cells_frees field) and in the localsplus
fastlocals array. Remove the redundant cells_frees field and
access cell objects directly through localsplus, eliminating
one Box allocation and N clone operations per frame creation.

* Extract InterpreterFrame from Frame with Deref wrapper

Introduce InterpreterFrame struct containing all execution state
fields previously on Frame. Frame now wraps InterpreterFrame via
FrameUnsafeCell and implements Deref for transparent field access.

localsplus and prev_line are plain fields on InterpreterFrame
(no longer individually wrapped in FrameUnsafeCell) since the
entire InterpreterFrame is wrapped at the Frame level.

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-05 23:00:13 +09:00
Jeong, YunWon
375b5472ed Fix thread-safety in GC, type cache, and instruction cache (#7355)
* Fix thread-safety in GC, type cache, and instruction cache

GC / refcount:
- Add safe_inc() check for strong()==0 in RefCount
- Add try_to_owned() to PyObject for atomic refcount acquire
- Replace strong_count()+to_owned() with try_to_owned() in GC
  collection and weakref callback paths to prevent TOCTOU races

Type cache:
- Add proper SeqLock (sequence counter) to TypeCacheEntry
- Readers spin-wait on odd sequence, validate after read
- Writers bracket updates with begin_write/end_write
- Use try_to_owned + pointer revalidation on read path
- Call modified() BEFORE attribute modification in set_attr

Instruction cache:
- Add pointer_cache (AtomicUsize array) to CodeUnits for
  single atomic pointer load/store (prevents torn reads)
- Add try_read_cached_descriptor with try_to_owned + pointer
  and version revalidation after increment
- Add write_cached_descriptor with version-bracketed writes

RLock:
- Fix release() to check is_owned_by_current_thread
- Add _release_save/_acquire_restore methods

* Fix RLock _acquire_restore tuple handling and unxfail threading test

* Align type cache seqlock writer protocol with CPython

* RLock: use single parking_lot level, track recursion manually

Instead of calling lock()/unlock() N times for recursion depth N,
keep parking_lot at 1 level and manage the count ourselves.
This makes acquire/release O(1) and matches CPython's
_PyRecursiveMutex approach (lock once + set level directly).

* Add try_to_owned_from_ptr to avoid &PyObject on stale ptrs

Use addr_of! to access ref_count directly from a raw pointer
without forming &PyObject first. Applied in type cache and
instruction cache hit paths where the pointer may be stale.

* Fix CI: spelling typo and xfail flaky test_thread_safety

- Fix "minimising" -> "minimizing" for cspell
- xfail test_thread_safety: dict iteration races with
  concurrent GC mutations in _finalizer_registry
2026-03-05 20:33:14 +09:00
Jeong, YunWon
86134e1ca1 Add freelists for PyComplex, PyInt, PyRange (#7345)
* Add freelists for PyComplex, PyInt, PyBoundMethod, PyRange

- PyComplex(100), PyInt(100), PyBoundMethod(20), PyRange(6)
- Use try_with instead of with in all freelist push/pop to prevent
  panic on thread-local access during thread teardown

* Use alloc::dealloc in FreeList::Drop to avoid thread-local access panic

During thread teardown, Box::from_raw triggers cascading destructors
that may access already-destroyed thread-local storage (GC state, other
freelists). Use raw dealloc instead to free memory without running
destructors.

* Auto-format: cargo fmt --all

* Fix clippy: use core::alloc::Layout instead of alloc::alloc::Layout

* Address review: PyBoundMethod clear=false, update FreeList doc comment

- Set clear=false on PyBoundMethod (tp_clear=NULL in classobject.c)
- Update FreeList doc comment to match actual Drop behavior (raw dealloc)

* Remove PyBoundMethod freelist to fix refcount/weakref test failures

Non-Option PyObjectRef fields retain references in freelist, causing
weakref and refcount assertions to fail in test_unittest, test_multiprocessing,
and test_socket.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-05 20:09:26 +09:00
CPython Developers
d1c73ac5b8 Update zipapp from v3.14.3 2026-03-05 17:25:59 +09:00
Copilot
5ab631db9d Enable stdio in barebone example so vm.print() works (#7356) 2026-03-05 12:57:56 +09:00
Jeong, YunWon
62766fd4a9 Stop non-main threads during interpreter finalization (#7349)
Raise SystemExit in check_signals() for non-main threads
once the finalizing flag is set. Without GIL, this serves
as the checkpoint where daemon threads detect shutdown,
analogous to CPython's _PyThreadState_MustExit in take_gil.
2026-03-05 10:21:44 +09:00
Jeong, YunWon
9a0511be0b Align specialization guards and caching with CPython (#7341)
* vm: complete specialized opcode dispatch paths

* vm: cache LOAD_GLOBAL with dict entry hints

* vm: align adaptive specialization counters with CPython backoff

* vm: apply cooldown counter on specialization success paths

* vm: retain LOAD_GLOBAL specializations on misses

* vm: keep attr and call specializations on guard misses

* vm: retain store-attr and store-subscr specializations on misses

* vm: retain specialization opcodes on generic fallback paths

* vm: align jump-backward specialization defaults with CPython

* vm: retain exact-args call specializations on misses

* vm: retain SEND_GEN specialization on non-coroutine sends

* vm: specialize list.append calls like CPython CALL_LIST_APPEND

* vm: set cooldown on LOAD_ATTR_CLASS specialization

* vm: specialize bound method object CALL paths

* vm: specialize CALL_KW for bound method objects

* vm: use current-state function version for CALL_KW specialization

* vm: align CALL/CALL_KW pyfunction specialization with CPython

* vm: drop call-site identity caches in generic CALL specializations

* vm: align builtin type call specializations with CPython guards

* vm: align builtin CALL guards with CPython self_or_null semantics

* vm: require exact list in CALL_LIST_APPEND fast path

* vm: align CALL builtin/class specialization flow with CPython

* vm: tighten len/isinstance CALL specializations to builtin guards

* vm: gate CALL_BUILTIN_CLASS on type vectorcall like CPython

* vm: run non-py CALL specializations via direct vectorcall

* vm: align class-call specialization branching with CPython

* Fix CI: disable ForIterGen, tighten CALL guards

- Disable ForIterGen specialization (falls through to generic
  path) because inline generator frame resumption is needed
  for correct debugger StopIteration visibility (test_bdb)
- Use downcast_ref_if_exact for PyNativeFunction in CALL
  specialization guards
- Add can_specialize_call guard for class __init__ specialization
- Remove expectedFailure for test_bad_newobj_args (now passing)
2026-03-05 01:59:44 +09:00
Jeong, YunWon
5c29074596 Replace GC tracking HashSet with intrusive linked list (#7328)
* Replace GC tracking HashSet with intrusive linked list

Replace per-generation HashSet<GcObjectPtr> with intrusive doubly-linked
lists for GC object tracking. Each PyInner now carries gc_pointers
(prev/next) and gc_generation fields, enabling O(1) track/untrack
without hashing.

- Add gc_pointers (Pointers<PyObject>) and gc_generation (u8) to PyInner
- Implement GcLink trait for intrusive list integration
- Replace generation_objects/permanent_objects/tracked_objects/finalized_objects
  HashSets with generation_lists/permanent_list LinkedLists
- Use GcBits::FINALIZED flag instead of finalized_objects HashSet
- Change default_dealloc to untrack directly before memory free
- Hold both src/dst list locks in promote_survivors to prevent race
  conditions with concurrent untrack_object calls
- Add pop_front to LinkedList for freeze/unfreeze operations
Move unreachable_refs creation before drop(gen_locks) so that raw
pointer dereferences and refcount increments happen while generation
list read locks are held. Previously, after dropping read locks, other
threads could untrack and free objects, causing use-after-free when
creating strong references from the raw GcPtr pointers.
2026-03-05 00:42:18 +09:00
Jeong, YunWon
745efbd8e8 Update collections from v3.14.3 (#7344)
* Update collections from v3.14.3

* Restore defaultdict fallback and update test markers

---------

Co-authored-by: CPython Developers <>
2026-03-05 00:32:53 +09:00
Jeong, YunWon
68ad332833 Remove Frame mutex and use DataStack bump allocator for LocalsPlus (#7333)
* Remove PyMutex<FrameState> from Frame, use UnsafeCell fields directly

Move stack, cells_frees, prev_line out of the mutex-protected FrameState
into Frame as FrameUnsafeCell fields. This eliminates mutex lock/unlock
overhead on every frame execution (with_exec).

Safety relies on the same single-threaded execution guarantee that
FastLocals already uses.

* Add thread-local DataStack for bump-allocating frame data

Introduce DataStack with linked chunks (16KB initial, doubling) and
push/pop bump allocation. Add datastack field to VirtualMachine.
Not yet wired to frame creation.

* Unify FastLocals and BoxVec stack into LocalsPlus

Replace separate FastLocals (Box<[Option<PyObjectRef>]>) and
BoxVec<Option<PyStackRef>> with a single LocalsPlus struct that
stores both in a contiguous Box<[usize]> array. The first
nlocalsplus slots are fastlocals and the rest is the evaluation
stack. Typed access is provided through transmute-based methods.

Remove BoxVec import from frame.rs.

* Use DataStack for LocalsPlus in non-generator function calls

Normal function calls now bump-allocate LocalsPlus data from the
per-thread DataStack instead of a separate heap allocation.
Generator/coroutine frames continue using heap allocation since
they outlive the call.

On frame exit, data is copied to the heap (materialize_to_heap)
to preserve locals for tracebacks, then the DataStack is popped.

VirtualMachine.datastack is wrapped in UnsafeCell for interior
mutability (safe because frame allocation is single-threaded LIFO).

* Fix clippy: import Layout from core::alloc instead of alloc::alloc

* Fix vectorcall compatibility with LocalsPlus API

Update vectorcall dispatch functions to use localsplus stack
accessors instead of direct stack field access. Add
stack_truncate method to LocalsPlus. Update vectorcall fast
path in function.rs to use datastack and fastlocals_mut().

* Add datastack, nlocalsplus, ncells, tstate to cspell dictionary

* Fix DataStack pop() for non-monotonic allocation addresses

Check both bounds of the current chunk when determining if a
pop base is in the current chunk. The previous check (base >=
chunk_start) fails on Windows where newer chunks may be
allocated at lower addresses than older ones.

* Fix stale comments: release_datastack -> materialize_localsplus

* Fix non-threading mode for parallel test execution

Two fixes for Cell-based types used in static items under non-threading
mode, which cause data races when Rust test runner uses parallel threads:

1. LazyLock: use std::sync::LazyLock when std is available instead of
   wrapping core::cell::LazyCell with a false `unsafe impl Sync`.
   The LazyCell wrapper is kept only for no-std (truly single-threaded).

2. gc_state: use static_cell! (thread-local in non-threading mode)
   instead of OnceLock, so each thread gets its own GcState with
   Cell-based PyRwLock/PyMutex that are not accessed concurrently.

* Fix CallAllocAndEnterInit to use LocalsPlus stack API

* Use checked arithmetic in LocalsPlus and DataStack allocators

* Address code review: checked arithmetic, threading feature deps, Send gate

- Use checked arithmetic for nlocalsplus in Frame::new
- Add "std" to threading feature dependencies in rustpython-common
- Gate GcState Send impl with #[cfg(feature = "threading")]

* Clean up comments: remove redundant/stale remarks, fix CPython references
2026-03-04 23:27:36 +09:00
Jeong, YunWon
a98c6469d1 freelist optimization (#7337)
* Add object freelist infrastructure and PyFloat freelist

Add freelist_push/freelist_pop hooks to PyPayload trait with default
no-op implementations. Modify default_dealloc to offer dead objects
to the freelist before freeing memory. Modify PyRef::new_ref to try
popping from the freelist before allocating.

Implement thread-local freelist for PyFloat (max 100 entries).
Float objects are ideal candidates: fixed-size payload (f64),
no GC tracking, no instance dict, trivial Drop.

Benchmark improvement on float-heavy workloads:
  float_arith: ~12% faster
  float_list:  ~17% faster

* Add PyList freelist and GC-safe freelist infrastructure

Add HAS_FREELIST const to PyPayload trait. For freelist types, GC
untracking is done immediately (not deferred) during dealloc to
prevent race conditions when the object is reused.

Restructure new_ref so freelist-popped objects also get GC tracked,
enabling freelist support for GC-tracked types like PyList.

Add drop_in_place for old payload before writing new one, required
for types with non-trivial Drop (e.g. PyList's RwLock<Vec>).

Implement thread-local freelist for PyList (max 80 entries).

* Add PyDict freelist and exact-type guard for freelist push

Add thread-local freelist for PyDict (max 80 entries).

Add heaptype check in default_dealloc to prevent subclass instances
from entering the freelist. Subclass objects have a different Python
type than the base type, so reusing them would return objects with
the wrong __class__.

Skip PyTuple freelist: structseq types (stat_result, struct_time)
are static subtypes sharing the same Rust payload, making type-safe
reuse impractical with heaptype check alone.

* Add PySlice freelist (max 1, matching PySlice_MAXFREELIST)

* Add FreeList<T> wrapper to drain cached objects on thread teardown

Replace Cell<Vec<*mut PyObject>> with Cell<FreeList<T>> which implements
Drop to properly deallocate PyInner<T> when threads exit.
Also fix freelist_pop safety doc to match actual contract.

* Add manual Traverse impl for PySlice with clear() and fix comment

* Deduplicate allocation fallback in PyRef::new_ref
2026-03-04 20:00:18 +09:00
Shahar Naveh
798f9e80cd Update libc to 0.2.182 (#7247)
* Update to libc 0.2.182, refactor update script

* Fix typing
2026-03-04 19:57:53 +09:00
Jeong, YunWon
c55a9ff728 Reinit IO buffer locks after fork to prevent deadlocks (#7339)
* Reinit IO buffer locks after fork to prevent deadlocks

BufferedReader/Writer/TextIOWrapper use PyThreadMutex internally.
If a parent thread held one of these locks during fork(), the child
would deadlock on any IO operation.

Add reinit_after_fork() to RawThreadMutex and call it on sys.stdin/
stdout/stderr in the child process fork handler, analogous to
CPython's _PyIO_Reinit().

* Address review: unsafe fn + decoder lock reinit

- Mark reinit_std_streams_after_fork as unsafe fn to encode
  fork-only precondition, update call site in posix.rs
- Reinit IncrementalNewlineDecoder's PyThreadMutex via
  TextIOWrapper's decoder field to prevent child deadlocks

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-04 19:54:10 +09:00
Jeong, YunWon
5a5ddbbed4 Restore defaultdict fallback and update test markers 2026-03-04 18:44:27 +09:00
CPython Developers
624ea3b13d Update collections from v3.14.3 2026-03-04 18:38:36 +09:00
Jeong, YunWon
3504993f28 Apply vectorcall for more places (#7336)
* Add PyType vectorcall and use vectorcall in all specialized call fallbacks

* Add vectorcall slot for PyMethodDescriptor and PyWrapper

* Add FuncArgs::from_vectorcall_owned and simplify vectorcall fallback paths

Remove has_vectorcall checks from execute_call_vectorcall and
execute_call_kw_vectorcall. The invoke_vectorcall fallback now uses
from_vectorcall_owned to move args instead of cloning.
2026-03-04 18:09:44 +09:00
Shahar Naveh
42628a53b9 Set codegen-untis=1 for some crates in release mode (#7332) 2026-03-04 17:59:59 +09:00
Claude
4c5f6332e8 Add SessionStart hook for dev environment setup
Configures automatic development environment setup for Claude Code web
sessions: upgrades python3 to 3.13+ and clones CPython source if missing.

https://claude.ai/code/session_01VPT2fpdf52qFZLMN8EDNgp
2026-03-04 17:53:05 +09:00
ShaharNaveh
ff5411110c Update smtplib.py from 3.14.3 2026-03-04 17:47:40 +09:00
Jeong, YunWon
c058add095 Specialized ops (#7322)
* Add CALL_ALLOC_AND_ENTER_INIT specialization

Optimizes user-defined class instantiation MyClass(args...)
when tp_new == object.__new__ and __init__ is a simple
PyFunction. Allocates the object directly and calls __init__
via invoke_exact_args, bypassing the generic type.__call__
dispatch path.

* Invalidate JIT cache when __code__ is reassigned

Change jitted_code from OnceCell to PyMutex<Option<CompiledCode>> so
it can be cleared on __code__ assignment. The setter now sets the
cached JIT code to None to prevent executing stale machine code.

* Atomic operations for specialization cache

- range iterator: deduplicate fast_next/next_fast
- Replace raw pointer reads/writes in CodeUnits with atomic
  operations (AtomicU8/AtomicU16) for thread safety
- Add read_op (Acquire), read_arg (Relaxed), compare_exchange_op
- Use Release ordering in replace_op to synchronize cache writes
- Dispatch loop reads opcodes atomically via read_op/read_arg
- Fix adaptive counter access: use read/write_adaptive_counter
  instead of read/write_cache_u16 (was reading wrong bytes)
- Add pre-check guards to all specialize_* functions to prevent
  concurrent specialization races
- Move modified() before attribute changes in type.__setattr__
  to prevent use-after-free of cached descriptors
- Use SeqCst ordering in modified() for version invalidation
- Add Release fence after quicken() initialization

* Fix slot wrapper override for inherited attributes

For __getattribute__: only use getattro_wrapper when the type
itself defines the attribute; otherwise inherit native slot from
base class via MRO.

For __setattr__/__delattr__: only store setattro_wrapper when
the type has its own __setattr__ or __delattr__; otherwise keep
the inherited base slot.

* Fix StoreAttrSlot cache overflow corrupting next instruction

write_cache_u32 at cache_base+3 writes 2 code units (positions 3 and 4),
but STORE_ATTR only has 4 cache entries (positions 0-3). This overwrites
the next instruction with the upper 16 bits of the slot offset.

Changed to write_cache_u16/read_cache_u16 since member descriptor offsets
fit within u16 (max 65535 bytes).

* Exclude method_descriptor from has_python_cmp check

has_python_cmp incorrectly treated method_descriptor as Python-level
comparison methods, causing richcompare slot to use wrapper dispatch
instead of inheriting the native slot.

* Fix CompareOpFloat NaN handling

partial_cmp returns None for NaN comparisons. is_some_and incorrectly
returned false for all NaN comparisons, but NaN != x should be true
per IEEE 754 semantics.

* Fix invoke_exact_args borrow in CallAllocAndEnterInit

* Distinguish Python method vs not-found in slot MRO lookup

Change lookup_slot_in_mro to return a 3-state SlotLookupResult
enum (NativeSlot/PythonMethod/NotFound) instead of Option<T>.

Previously, both "found a Python-level method" and "found nothing"
returned None, causing incorrect slot inheritance. For example,
class Test(Mixin, TestCase) would inherit object.slot_init from
Mixin via inherit_from_mro instead of using init_wrapper to
dispatch TestCase.__init__.

Apply this fix consistently to all slot update sites:
update_main_slot!, update_sub_slot!, TpGetattro, TpSetattro,
TpDescrSet, TpHash, TpRichcompare, SqAssItem, MpAssSubscript.

* Extract specialization helper functions to reduce boilerplate

- deoptimize() / deoptimize_at(): replace specialized op with base op
- adaptive(): decrement warmup counter or call specialize function
- commit_specialization(): replace op on success, backoff on failure
- execute_binary_op_int() / execute_binary_op_float(): typed binary ops

Removes 10 duplicate deoptimize_* functions, consolidates 13 adaptive
counter blocks, 6 binary op handlers, and 7 specialize tail patterns.
Also replaces inline deopt blocks in LoadAttr/StoreAttr handlers.

* Improve specialization guards and fix mark_stacks

- CONTAINS_OP_SET: add frozenset support in handler and specialize
- TO_BOOL_ALWAYS_TRUE: cache type version instead of checking slots
- LOAD_GLOBAL_BUILTIN: cache builtins dict version alongside globals
- mark_stacks: deoptimize specialized opcodes for correct reachability

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-04 15:39:48 +09:00
Shahar Naveh
e9001ec3e5 Bytecode enum named oparg (#7294)
* Align real opcodes

* Align pseudoes

* Add `consti` to known words
2026-03-03 21:33:59 +00:00
Shahar Naveh
bc108dfe86 Update trace.py from 3.14.3 (#7327)
* Update `trace.py` from 3.14.3

* Mark failing tests
2026-03-04 05:38:58 +09:00
Jeong, YunWon
1d106c3411 Add monitoring lock reinit and use raw() accessor (#7335)
Add missing reinit_mutex_after_fork for vm.state.monitoring
PyMutex in reinit_locks_after_fork.

Use Mutex::raw() accessor in reinit_parking_lot_mutex instead
of pointer cast from struct start for layout safety.
2026-03-04 04:35:52 +09:00
Jeong, YunWon
2f810ae0f6 Merge pull request #7330 from ShaharNaveh/update-test-frame
Add `test_frame.py` from 3.14.3
2026-03-04 04:30:54 +09:00
Jeong, YunWon
9b9c74973e make_class -> make_static_type (#7331)
* Remove unsafe ctx cast in make_class

Use Context::genesis() directly in make_class to obtain
&'static Context, eliminating the raw pointer cast.

* make_class -> make_static_type
2026-03-04 04:28:42 +09:00
Jeong, YunWon
be0c3ca3ca Add vectorcall (PEP 590) dispatch for function calls (#7329)
* Add vectorcall (PEP 590) dispatch for function calls

Add VectorCallFunc slot to PyTypeSlots and vectorcall dispatch path
in the interpreter loop for Call and CallKw instructions.

Implement vectorcall for PyFunction (with fast path for simple
positional-only calls that fills fastlocals directly), PyBoundMethod
(avoids prepend_arg O(n) shift), and PyNativeFunction.

Add FuncArgs::from_vectorcall helper for fallback conversion.
Vectorcall slot is inherited with call slot and cleared when
__call__ is overridden in Python subclasses.

* Optimize vectorcall: move args instead of clone, use vectorcall in specialized paths

- invoke_exact_args takes Vec by value and uses drain() to move args
  into fastlocals instead of cloning (eliminates refcount overhead)
- CallPyGeneral and CallBoundMethodGeneral now call vectorcall_function
  directly instead of going through FuncArgs + prepend_arg + invoke
- CallKwPy and CallKwBoundMethod use vectorcall_function with kwnames
- vectorcall_bound_method uses insert(0) on existing Vec instead of
  allocating a second Vec

* Auto-format: cargo fmt --all

* Fix vectorcall_native_function kwarg slice out-of-bounds

When needs_self was true and kwargs were present, pos_args only
contained positional args (self + original positionals) but
from_vectorcall expected kwarg values to follow in the slice.

Build the full args array (self + all original args including kwarg
values) before passing to from_vectorcall.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-03 23:51:56 +09:00
Jeong, YunWon
2f2a7da185 Add method cache (MCACHE) for MRO lookups (#7313)
4096-entry direct-mapped cache keyed by (tp_version_tag, interned_name_ptr)
using lock-free SeqLock pattern for concurrent access.

- find_name_in_mro() checks cache before MRO walk
- has_name_in_mro() avoids cloning on cache hit
- Auto-assigns version tags on cache miss
- Invalidation via modified() (tp_version_tag=0) with value drops
- TYPE_CACHE_CLEARING flag suppresses re-population during GC drops
- Clear method cache during GC collection to break reference cycles
2026-03-03 23:32:15 +09:00
ShaharNaveh
98021543d8 Mark failing test 2026-03-03 15:20:36 +01:00
ShaharNaveh
16066cc0fe Mark failing tests 2026-03-03 15:17:10 +01:00
ShaharNaveh
4e8a945277 Update test_frame.py from 3.14.3 2026-03-03 15:17:10 +01:00
Jeong, YunWon
62ca60ad82 Merge pull request #7318 from youknowone/utf8source
Update test_utf8source from v3.14.3 and implement it
2026-03-03 22:29:14 +09:00
ShaharNaveh
3cbd08f63c Update test_tuple.py from 3.14.3 2026-03-03 21:58:46 +09:00
Jeong, YunWon
53ddc7ef48 Remove expectedFailure for encoding tests now passing
Remove @unittest.expectedFailure decorators from:
- test_source_encoding: test_encoding_on_first_line, test_encoding_on_second_line, test_bom_conflict
- test_runpy: test_encoding
2026-03-03 21:27:11 +09:00
Jeong, YunWon
77eade37f1 Fix PEP 263 encoding detection per review
- Validate '#' is preceded only by whitespace/formfeed (PEP 263)
- Normalize UTF-8 encoding aliases (utf-8, utf_8, utf8, etc.)
2026-03-03 21:27:11 +09:00
CPython Developers
33fca0d77b Update test_utf8source from v3.14.3 2026-03-03 21:27:11 +09:00
ShaharNaveh
257b0c08a7 Update pkgutil.py from 3.14.3 2026-03-03 20:00:50 +09:00
ShaharNaveh
2ca3275097 Update test_xml_etree_c.py from 3.14.3 2026-03-03 20:00:30 +09:00
ShaharNaveh
7b33208455 Update test_raise.py from 3.14.3 2026-03-03 19:57:50 +09:00
Jeong, YunWon
25619aad1d Specialized ops (#7301)
* Add debug_assert to invoke_exact_args, lazy func_version reassignment

- Add debug_assert preconditions in invoke_exact_args
- Add get_version_for_current_state() for lazy version reassignment
  after func_version invalidation
- Document NEXT_TYPE_VERSION overflow policy

* working

* Add COMPARE_OP, TO_BOOL, FOR_ITER, LOAD_GLOBAL specialization

- COMPARE_OP: CompareOpInt, CompareOpFloat, CompareOpStr
- TO_BOOL: ToBoolBool, ToBoolInt, ToBoolNone, ToBoolList, ToBoolStr
- FOR_ITER: ForIterRange, ForIterList, ForIterTuple with fast_next()
- LOAD_GLOBAL: LoadGlobalModule, LoadGlobalBuiltin with dict version guard
- Add version counter to Dict for mutation tracking

* Add BINARY_SUBSCR, CONTAINS_OP, UNPACK_SEQUENCE, STORE_ATTR specialization

- BinaryOpSubscrListInt, BinaryOpSubscrTupleInt, BinaryOpSubscrDict
- ContainsOpDict, ContainsOpSet
- UnpackSequenceTwoTuple, UnpackSequenceTuple, UnpackSequenceList
- StoreAttrInstanceValue with type_version guard
- Deoptimize bytecode for marshal serialization (original_bytes)
- Separate co_code (deoptimized) from _co_code_adaptive (quickened)

* Add STORE_SUBSCR, BinaryOpAddUnicode, ToBoolAlwaysTrue, CallLen, CallIsinstance, CallType1 specialization

* Add BinaryOpSubscrStrInt, CallStr1, CallTuple1 specialization

* Add BinaryOpInplaceAddUnicode specialization

* Add LoadAttrModule, CallBuiltinO, CallPyGeneral, CallBoundMethodGeneral, ForIterGen, CallListAppend specialization

* Add LoadAttrNondescriptor*, CallMethodDescriptor* specialization

- LoadAttrNondescriptorNoDict: plain class attr on objects without dict
- LoadAttrNondescriptorWithValues: plain class attr with dict fallback
- LoadAttrClass: handler for type attribute access (not yet routed)
- CallMethodDescriptorNoargs: method descriptor with 0 args
- CallMethodDescriptorO: method descriptor with 1 arg
- CallMethodDescriptorFast: method descriptor with multiple args
- Use HAS_DICT flag instead of obj.dict().is_some() for method/nondescriptor routing

* Add CallBuiltinFast, CallNonPyGeneral specialization

- CallBuiltinFast: native function calls with arbitrary positional args
- CallNonPyGeneral: fallback for unmatched callables (custom __call__, etc.)
- All builtin function calls now specialize (CallBuiltinFast as default)
- specialize_call now always produces a specialized instruction

* Add SendGen specialization for generator/coroutine send

- SendGen: direct coro.send() for generator/coroutine receivers
- Add adaptive counter to Send instruction
- specialize_send checks builtin_coro for PyGenerator/PyCoroutine

* Add LoadAttrSlot, StoreAttrSlot specialization for __slots__ access

- LoadAttrSlot: direct obj.get_slot(offset) bypassing descriptor protocol
- StoreAttrSlot: direct obj.set_slot(offset, value) bypassing descriptor protocol
- Detect PyMemberDescriptor with MemberGetter::Offset in specialize_load_attr/store_attr
- Cache slot offset in cache_base+3

* Add LoadSuperAttrAttr, LoadSuperAttrMethod, CallBuiltinClass, CallBuiltinFastWithKeywords, CallMethodDescriptorFastWithKeywords specialization

* Add LoadAttrProperty specialization for property descriptor access

* Add LoadAttrClass specialization for class attribute access

* Add BinaryOpSubscrListSlice specialization

* Add CallKwPy, CallKwBoundMethod, CallKwNonPy specialization

Fix LoadSuperAttrMethod to push unbound descriptor + self
instead of bound method + self which caused double self binding.
Fix LoadSuperAttrAttr obj_arg condition for classmethod detection.

* Clean up comments in specialization code

Remove unnecessary CPython references, FIXME→TODO,
redundant Note: prefix, and "Same as" cross-references.

* fix check_signals

* fix import
2026-03-03 19:55:35 +09:00
Jeong, YunWon
7727acc6a7 Reduce per-instruction overhead in interpreter loop (#7315)
* Reduce per-instruction overhead in interpreter loop

- Defer prev_line update to when tracing is active
- Inline skip_caches_if_fallthrough, compute cache_entries once per instruction

* Unmark test_pdb_set_trace EXPECTED_FAILURE

prev_line deferral fix corrects pdb line tracking, making
these doctests pass.
2026-03-03 18:01:18 +09:00
Jeong, YunWon
7eb18210ca reinit-after-fork (#7321)
* Use Mutex::raw() accessor in reinit_mutex_after_fork

Use lock_api's Mutex::raw() to access the underlying RawMutex
instead of casting &PyMutex<T> directly. This avoids layout
assumptions about lock_api::Mutex<R, T> field ordering.

* Replace force_unlock with reinit_*_after_fork

Replace all force_unlock() + try_lock() patterns with zero-based
reinit that bypasses parking_lot internals entirely. After fork(),
the child is single-threaded so reinited locks won't contend.

Add reinit_rwlock_after_fork to common::lock alongside the existing
reinit_mutex_after_fork. Replace force_unlock_after_fork methods in
codecs, intern, and gc_state with reinit_after_fork equivalents.

This fixes after_fork_child silently dropping thread handles when
try_lock() failed on per-handle Arc<Mutex> locks.
2026-03-03 11:25:47 +09:00
Jeong, YunWon
1f6e47ce9c extend types and exceptions only for genesis (#7316) 2026-03-03 11:24:58 +09:00
Jeong, YunWon
43e2df31e0 Replace PyFunction.code PyMutex with PyAtomicRef for lock-free reads (#7317)
Change the code field from PyMutex<PyRef<PyCode>> to PyAtomicRef<PyCode>,
eliminating mutex lock/unlock on every function call. The setter uses
swap_to_temporary_refs for safe deferred drop of the old code object.
2026-03-03 09:18:49 +09:00
Jeong, YunWon
5f08a01cf4 Lazy locals dict for NEWLOCALS frames (#7307)
Defer locals dict allocation for function frames until first access.
Most function frames only use fastlocals and never touch the locals
dict, so this skips one dict heap allocation per function call.

Also remove a redundant code.clone() in invoke_with_locals.

Func call ~23% faster, method call ~15% faster in benchmarks.
2026-03-03 09:17:17 +09:00
Shahar Naveh
903a5f28a0 Update test_posix.py from 3.14.3 and adjust android cfg (#7320)
* Update `test_posix.py` from 3.14.3

* patch

* Align availability

* Fix test_fchmod_file
2026-03-03 09:09:47 +09:00
Jeong, YunWon
9a12a8d532 Fix _at_fork_reinit to write INIT directly instead of calling unlock() (#7312)
* Fix _at_fork_reinit to write INIT directly instead of calling unlock()

unlock() goes through unlock_slow() which accesses parking_lot's
global hash table to unpark waiters. After fork(), this hash table
contains stale entries from dead parent threads, making unlock_slow()
unsafe. Writing INIT directly bypasses parking_lot internals entirely.

* Add import lock (IMP_LOCK) reinit after fork

The import lock is a ReentrantMutex that was never reinit'd after
fork(). If a parent thread held it during fork, the child would
deadlock on any import. Only reset if the owner is a dead thread;
if the surviving thread held it, normal unlock still works.
2026-03-03 09:08:12 +09:00
dependabot[bot]
c71f4ada21 Bump github/gh-aw from 0.51.4 to 0.51.5 (#7319)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.51.4 to 0.51.5.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](e422993ded...88319be75a)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.51.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-03 09:04:30 +09:00
Lee Dogeon
0a6a6f8ddb Prevent shell injection (#7310) 2026-03-02 19:45:58 +09:00
Jeong, YunWon
3865fdbf5b Revert class lookup (#7306)
* Revert __class__ lookup skip in object_isinstance

The optimization to skip __class__ lookup based on getattro check
was incorrect: a class can override __class__ as a property while
still using standard __getattribute__. Revert to always performing
the lookup, matching CPython's object_isinstance behavior.

* Collapse nested if in object_isinstance for clippy
2026-03-02 19:41:43 +09:00
Jeong, YunWon
baba1f9447 Fix symbol table sub_table desync for non-simple annotation targets (#7300)
* Fix symbol table sub_table desync for non-simple annotation targets

Non-simple annotations (subscript/attribute/parenthesized targets like
`a[0]: expr`) were scanned in the annotation scope during symbol table
analysis, creating sub_tables for any comprehensions. But codegen only
compiles simple name annotations into __annotate__, so those sub_tables
were never consumed. This caused subsequent simple annotations'
comprehension sub_tables to get the wrong index, resulting in
"the symbol 'X' must be present in the symbol table" errors.

Fix: skip entering annotation scope for non-simple annotations since
they are never compiled into __annotate__.

* Validate forbidden expressions in non-simple annotation targets

Fix cspell "desynchronize" warning and validate yield/await/named/async
comprehension expressions in non-simple annotations without creating
annotation scopes.

* Restore in_annotation flag before propagating error
2026-03-02 16:47:16 +09:00
Jeong, YunWon
c315033091 Implement LOAD_ATTR inline caching with adaptive specialization (#7292)
* Implement LOAD_ATTR inline caching with adaptive specialization

Add type version counter (tp_version_tag) to PyType with subclass
invalidation cascade. Add cache read/write methods (u16/u32/u64)
to CodeUnits. Implement adaptive specialization in load_attr that
replaces the opcode with specialized variants on first execution:

- LoadAttrMethodNoDict: cached method lookup for slotted types
- LoadAttrMethodWithValues: cached method with dict shadow check
- LoadAttrInstanceValue: direct dict lookup skipping descriptors

Specialized opcodes guard on type_version_tag and deoptimize back
to generic LOAD_ATTR with backoff counter on cache miss.

* Add BINARY_OP and CALL adaptive specialization

BINARY_OP: Specialize int add/subtract/multiply and float
add/subtract/multiply with type guards and deoptimization.

CALL: Add func_version to PyFunction, specialize simple
function calls (CallPyExactArgs, CallBoundMethodExactArgs)
with invoke_exact_args fast path that skips FuncArgs
allocation and fill_locals_from_args.

* Lazy quickening for adaptive specialization counters

Move counter initialization from compile-time to RESUME execution,
matching CPython's _PyCode_Quicken pattern. Store counter in CACHE
entry's arg byte to preserve op=Instruction::Cache for dis/JIT.
Add PyCode.quickened flag for one-time initialization.

* Add Instruction::deoptimize() and CodeUnits::original_bytes()

- deoptimize() maps specialized opcodes back to their base adaptive variant
- original_bytes() produces deoptimized bytecode with zeroed CACHE entries
- co_code now returns deoptimized bytes, _co_code_adaptive returns current bytes
- Marshal serialization uses original_bytes() instead of raw transmute

* Fix monitoring and specialization interaction

- cache_entries() returns correct count for instrumented opcodes
- deoptimize() maps instrumented opcodes back to base
- quicken() skips adaptive counter for instrumented opcodes
- instrument_code Phase 3 deoptimizes specialized opcodes and
  clears CACHE entries to prevent stale pointer dereferences

* Address review: bounds checks, UB fix, version overflow, error handling

- Add bounds checks to read_cache_u16/u32/u64
- Fix quicken() aliasing UB by using &mut directly
- Add JumpBackwardJit/JumpBackwardNoJit to deoptimize()
- Guard can_specialize_call with NEWLOCALS flag check
- Use compare_exchange_weak for version tag to prevent wraparound
- Propagate dict lookup errors in LoadAttrMethodWithValues
- Apply adaptive backoff on version tag assignment failure
- Remove duplicate imports in frame.rs
2026-03-02 16:36:57 +09:00
Jeong, YunWon
b1cddc4e0c Merge pull request #7296 from youknowone/sysconfig
Update sysconfig from v3.14.3 and also fix _sysconfig
2026-03-02 13:13:20 +09:00
Jeong, YunWon
3a81f94aa8 Optimize unpack, str.__add__ and fastlocals (#7293)
* Remove intermediate Vec allocation in unpack_sequence fast path

Push elements directly from tuple/list slice in reverse order
instead of cloning into a temporary Vec first.

* Use read-only atomic load before swap in check_signals

Add Relaxed load guard before the Acquire swap to avoid cache-line
invalidation on every instruction dispatch when no signal is pending.

* Cache builtins downcast in ExecutingFrame for LOAD_GLOBAL

Pre-compute builtins.downcast_ref::<PyDict>() at frame entry and reuse
the cached reference in load_global_or_builtin and LoadBuildClass.
Also add get_chain_exact to skip redundant exact_dict type checks.

* Add number Add slot to PyStr for direct str+str dispatch

binary_op1 can now resolve str+str addition directly via the number
slot instead of falling through to the sequence concat path.

* Guard FastLocals access in locals() with try_lock on state mutex

Address CodeRabbit review: f_locals() could access fastlocals without
synchronization when called from another thread. Use try_lock on the
state mutex so concurrent access is properly serialized.

* Use exact type check for builtins_dict cache

downcast_ref::<PyDict>() matches dict subclasses, causing
get_chain_exact to bypass custom __getitem__ overrides.
Use downcast_ref_if_exact to only fast-path exact dict types.

* Consolidate with_recursion in _cmp to single guard

Move the recursion depth check to wrap the entire _cmp body
instead of each individual call_cmp direction, reducing Cell
read/write pairs and scopeguard overhead per comparison.

* Add opcode-level fast paths for FOR_ITER, COMPARE_OP, BINARY_OP

- FOR_ITER: detect PyRangeIterator and bypass generic iterator
  protocol (atomic slot load + indirect call)
- COMPARE_OP: inline int/float comparison for exact types,
  skip rich_compare dispatch and with_recursion overhead
- BINARY_OP: inline int add/sub with i64 checked arithmetic
  to avoid BigInt heap allocation and binary_op1 dispatch

* Also check globals is exact dict for LOAD_GLOBAL fast path

get_chain_exact bypasses __missing__ on dict subclasses.
Move get_chain_exact to PyExact<PyDict> impl with debug_assert,
and have get_chain delegate to it. Store builtins_dict as
Option<&PyExact<PyDict>> to enforce exact type at compile time.

Use PyRangeIterator::next_fast() instead of pub(crate) fields.
Fix comment style issues.
2026-03-02 12:37:43 +09:00
dependabot[bot]
7b89d8252e Bump github/gh-aw from 0.51.2 to 0.51.4 (#7305)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.51.2 to 0.51.4.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](cccf96100f...e422993ded)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.51.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-02 11:08:22 +09:00
Jeong, YunWon
888e0eeccb Add str(int) and repr(int) fast path using i64 conversion (#7302)
* Add str(int) and repr(int) fast path using i64 conversion

- Skip __str__ method resolution for exact PyInt in PyObject::str()
- Use i64::to_string() for small integers, BigInt::to_string() for large ones
- ~36% improvement in str(int) benchmarks

* Extract PyInt::to_str_radix_10() to deduplicate i64 fast path logic
2026-03-02 11:02:49 +09:00
Jeong, YunWon
69fc75b22d Skip __class__ lookup in object_isinstance for standard getattro (#7303)
In object_isinstance(), when is_subtype() returns false, the __class__
attribute lookup via get_attribute_opt is redundant for objects using
standard __getattribute__, since __class__ is a data descriptor on
object that always returns obj.class().
2026-03-02 10:18:45 +09:00
fanninpm
f443226e46 Add crypto group to dependabot config (#7304) 2026-03-02 10:18:01 +09:00
CPython Developers
5a11f33751 Update sysconfig from v3.14.3 2026-03-02 01:24:15 +09:00
Jeong, YunWon
d0b5a5af50 [update_lib] fast date lookup for todo (#7299)
* [update_lib] fast date lookup for todo

* add deps

* Auto-format: ruff format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-02 01:23:52 +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
dependabot[bot]
a6b3a5b6bc Bump github/gh-aw from 0.50.7 to 0.51.2 (#7295)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.50.7 to 0.51.2.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](9cbca3cd9b...cccf96100f)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.51.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-01 23:39:56 +09:00
Jeong, YunWon
5eadae8c2e Implement PyStackRef borrowed stack references for LOAD_FAST_BORROW (#7290)
* Implement PyStackRef borrowed stack references for LOAD_FAST_BORROW

* Fix PyStackRef: use NonZeroUsize for niche optimization, revert borrowed refs

- Change PyStackRef.bits from usize to NonZeroUsize so Option<PyStackRef>
  has the same size as Option<PyObjectRef> via niche optimization
- Revert LoadFastBorrow to use clone instead of actual borrowed refs
  to avoid borrowed refs remaining on stack at yield points
- Add static size assertions for Option<PyStackRef>
- Add stackref, fastlocal to cspell dictionary
- Remove debug eprintln statements
- Fix clippy warning for unused push_borrowed

* Add borrowed ref debug_assert to InstrumentedYieldValue, clean up comments
2026-03-01 23:32:56 +09:00
dependabot[bot]
58a0f74c76 Bump aws-lc-rs from 1.15.4 to 1.16.0 (#7298)
Bumps [aws-lc-rs](https://github.com/aws/aws-lc-rs) from 1.15.4 to 1.16.0.
- [Release notes](https://github.com/aws/aws-lc-rs/releases)
- [Commits](https://github.com/aws/aws-lc-rs/compare/v1.15.4...v1.16.0)

---
updated-dependencies:
- dependency-name: aws-lc-rs
  dependency-version: 1.16.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-01 23:27:40 +09:00
Shahar Naveh
707135f851 Add npm to dependabot (#7291) 2026-03-01 21:55:34 +09:00
Jeong, YunWon
d23eb4af6c Add sysconfig build vars and fix value types
- Add prefix, exec_prefix, BINDIR to sysconfigdata build_time_vars
- Add Py_DEBUG and ABIFLAGS to sysconfigdata
- Fix Py_GIL_DISABLED/Py_DEBUG to use int (1/0) instead of bool
- Gitignore generated _sysconfig_vars*.json
2026-03-01 21:53:42 +09:00
Jeong, YunWon
2b084457ef Optimize fast_locals and atomic ordering (#7289)
* Relax RefCount atomic ordering from SeqCst to Arc pattern

- inc/inc_by/get: SeqCst → Relaxed
- safe_inc CAS: SeqCst → Relaxed + compare_exchange_weak
- dec: SeqCst → Release + Acquire fence when count drops to 0
- leak CAS: SeqCst → AcqRel/Relaxed + compare_exchange_weak

* Reuse existing Vec via prepend_arg in execute_call

Replace vec![self_val] + extend(args.args) with
FuncArgs::prepend_arg() to avoid a second heap allocation
on every method call.

* Skip downcast_ref checks in invoke when tracing is disabled

Early return in PyCallable::invoke() when use_tracing is false,
avoiding two downcast_ref type checks on every function call.

* Replace fastlocals PyMutex with UnsafeCell-based FastLocals

Eliminate per-instruction mutex lock/unlock overhead for local
variable access. FastLocals uses UnsafeCell with safety guaranteed
by the frame's state mutex and sequential same-thread execution.

Affects 14+ lock() call sites in hot instruction paths (LoadFast,
StoreFast, DeleteFast, and their paired variants).

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-01 20:53:12 +09:00
CPython Developers
333ce69374 Update zoneinfo from v3.14.3 2026-03-01 20:51:10 +09:00
CPython Developers
e68fac8655 Update tempfile from v3.14.3 2026-03-01 20:50:21 +09:00
ShaharNaveh
367aff93f0 Update test_dynamicclassattribute.py from 3.14.3 2026-03-01 19:27:33 +09:00
Jeong, YunWon
ae8c0b3a93 skip flaky weakref test (#7286) 2026-03-01 15:28:23 +09:00
Jeong, YunWon
ccd377cc47 instruction CACHE (#7251)
* Emit CACHE code units in bytecode to match CPython 3.14

- Add cache_entries() method to Instruction enum
- Emit CACHE code units after opcodes in finalize_code
- Handle NO_LOCATION (line=-1) in linetable for CACHE entries
- Account for CACHE entries in exception table generation
- Skip CACHE entries in VM execution loop (with jump detection)
- Handle CACHE in InstrumentedLine/InstrumentedInstruction/InstrumentedForIter/InstrumentedNotTaken
- Skip CACHE in monitoring instrumentation phases
- Update co_branches() for cache-adjusted offsets
- Restore _cache_format in Lib/opcode.py
- Remove expectedFailure from test_c_call, test_start_offset

* Use relative jump offsets and fix bytecode layout

- Convert jump arguments from absolute to relative offsets
  in frame.rs, monitoring.rs, and stack_analysis
- Add jump_relative_forward/backward helpers to ExecutingFrame
- Resolve pseudo jump instructions before offset fixpoint loop
- Emit NOP for break, continue, pass to match line-tracing
- Fix async for: emit EndAsyncFor with correct target, add NotTaken
- Fix comprehension if-cleanup to use separate block
- Fix super() source range for multi-line calls
- Fix NOP removal to preserve line-marker NOPs
- Fix InstrumentedLine cache skipping after re-dispatch
- Match InstrumentedResume/YieldValue in yield_from_target
- Remove CALL_FUNCTION_EX cache entry from opcode.py
- Remove resolved expectedFailure markers

* Align CPython 3.14 LOAD_GLOBAL null-bit and RERAISE semantics

* Remove redundant CPython-referencing comments

Clean up comments that unnecessarily mention CPython per project
convention. Replace with concise descriptions of the behavior itself.
2026-03-01 14:51:54 +09:00
Jeong, YunWon
e4938cf61e Merge pull request #7283 from youknowone/ssl
Update ssl from v3.14.3 and add _ssl.HAS_PHA
2026-03-01 14:49:08 +09:00
Jeong, YunWon
130c771538 Update random from v3.14.3 and fix getrandbits (#7270)
* Update random from v3.14.3

* getrandbits and itertools.repeat now accept __index__ protocol.

---------

Co-authored-by: CPython Developers <>
2026-03-01 13:20:32 +09:00
Jeong, YunWon
dd6cf74fd7 Implement trace/profile events and opcode tracing for generators (#7268)
- Add TraceEvent::Exception and Opcode variants with profile filtering
- Extract dispatch_traced_frame helper for Call/Return trace events
- Fire exception trace on new raises, SEND StopIteration, FOR_ITER StopIteration
- Fire opcode trace events gated by f_trace_opcodes
- Move prev_line to FrameState for persistence across generator suspend/resume
- Reset prev_line in gen_throw for correct LINE monitoring after yield
- Add per-code event mask (events_for_code) to prevent unrelated code instrumentation
- Remove expectedFailure markers from test_bdb (5) and test_sys_setprofile (14)
2026-03-01 13:18:37 +09:00
github-actions[bot]
3e3165bc42 Auto-format: cargo fmt --all 2026-03-01 02:38:15 +00:00
Jeong, YunWon
c29b96d09e Fix ssl options setter to raise ValueError for negative values and mark still-failing tests 2026-03-01 11:37:19 +09:00
CPython Developers
4d0f52adc9 Update ssl from v3.14.3 2026-03-01 11:36:46 +09:00
fanninpm
919a14623d Remove test_importlib from polluters (#7279) 2026-03-01 10:58:47 +09:00
Shahar Naveh
5a56a76fad Update test_set.py from 3.14.3 (#7282)
* Update `test_set.py` from 3.14.3

* Cleanup code a bit

* Mark failing tests
2026-03-01 10:58:23 +09:00
Jeong, YunWon
28299e3136 Add missing HAS_PHA constant to _ssl module 2026-03-01 10:57:44 +09:00
Jiseok CHOI
be29462087 Fix _hashlib.compare_digest to reject non-ASCII strings (#7280)
Add non-ASCII string check to _hashlib.compare_digest, matching the
behavior of _operator._compare_digest. When both arguments are strings,
non-ASCII characters now correctly raise TypeError.

Also replace the non-constant-time == comparison with constant_time_eq
for proper timing-attack resistance, and return PyResult<bool> instead
of PyResult<PyObjectRef>.
2026-03-01 10:51:39 +09:00
Jiseok CHOI
7b7c7a1b6e sqlite3: add Cursor.row_factory pygetset and fix Connection.cursor() propagation (#7278)
Add #[pygetset] getter/setter for Cursor.row_factory so that Python-level
attribute access reads/writes the Rust struct field instead of the
instance dict.

Fix Connection.cursor() to only propagate the connection's row_factory
to the cursor when the connection's row_factory is not None, matching
CPython behavior. Previously it unconditionally overwrote the cursor's
row_factory, discarding any factory set by a cursor subclass __init__.
2026-03-01 10:44:50 +09:00
Jiseok CHOI
be39a67f27 Handle reentrant detach in TextIOWrapper.close() (#7277)
When a custom `closed` property on the underlying buffer calls
`detach()` during the `file_closed()` check in `close()`, the
wrapper's internal buffer becomes None. Subsequent flush/close
operations then fail with AttributeError on NoneType.

Add a guard after the `file_closed()` check to detect if the buffer
was detached reentrantly, and return early in that case (detach has
already flushed the stream).

This mirrors the fix applied in CPython
(https://github.com/python/cpython/issues/142594\).
2026-03-01 10:44:13 +09:00
Shahar Naveh
bef46f17d5 Fix list.__repr__ deadlock (#7275)
* Fix list repr deadlock

* Unmark apssing test
2026-03-01 10:43:23 +09:00
ShaharNaveh
11ddf6e065 Mark failing tests 2026-03-01 10:42:37 +09:00
ShaharNaveh
9fad2c0b1d Update test_format.py from 3.14.3 2026-03-01 10:42:37 +09:00
ShaharNaveh
48d574f90f Update test_strtod.py 2026-03-01 10:42:37 +09:00
ShaharNaveh
3b0be19b10 Update test_string_literals.py from 3.14.3 2026-03-01 10:42:37 +09:00
ShaharNaveh
1731984393 Update test_str.py to 3.14.3 2026-03-01 10:42:37 +09:00
ShaharNaveh
d6adfb0b59 Update test_dynamic.py to 3.14.3 2026-03-01 10:39:06 +09:00
Shahar Naveh
b05e74b78e Don't return frozenset for modules (#7276) 2026-03-01 09:43:34 +09:00
Jiseok CHOI
2833cd8896 add isatty() method in BytesIO (#7243) 2026-02-28 15:55:12 +00:00
dependabot[bot]
a4a9b29687 Bump env_logger from 0.11.8 to 0.11.9 (#7267)
Bumps [env_logger](https://github.com/rust-cli/env_logger) from 0.11.8 to 0.11.9.
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.11.8...v0.11.9)

---
updated-dependencies:
- dependency-name: env_logger
  dependency-version: 0.11.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-01 00:36:06 +09:00
dependabot[bot]
cc5f9edd43 Bump junction from 1.4.1 to 1.4.2 (#7266)
Bumps [junction](https://github.com/tesuji/junction) from 1.4.1 to 1.4.2.
- [Release notes](https://github.com/tesuji/junction/releases)
- [Changelog](https://github.com/tesuji/junction/blob/main/CHANGELOG.md)
- [Commits](https://github.com/tesuji/junction/compare/v1.4.1...v1.4.2)

---
updated-dependencies:
- dependency-name: junction
  dependency-version: 1.4.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-01 00:35:48 +09:00
dependabot[bot]
85d4c42a6b Bump actions/upload-artifact from 6.0.0 to 7.0.0 (#7264)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6.0.0 to 7.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 23:18:04 +09:00
dependabot[bot]
dd84a19b5b Bump github/gh-aw from 0.49.4 to 0.50.7 (#7262)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.49.4 to 0.50.7.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](bf34f99475...9cbca3cd9b)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.50.7
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 23:17:53 +09:00
dependabot[bot]
5861393ad8 Bump actions/download-artifact from 7.0.0 to 8.0.0 (#7263)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 7.0.0 to 8.0.0.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v7...v8)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 8.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 23:17:38 +09:00
Jeong, YunWon
8676ba9128 getrandbits and itertools.repeat now accept __index__ protocol. 2026-02-28 22:58:56 +09:00
CPython Developers
c4de2a7239 Update random from v3.14.3 2026-02-28 22:50:51 +09:00
Jeong, YunWon
cc4a7bbbe5 Merge pull request #7255 from youknowone/bdb
Update bdb from v3.14.3 and fix trace_event
2026-02-28 22:35:36 +09:00
Shahar Naveh
f3cf86c8c2 More accurate test dependencies (#7261) 2026-02-28 22:11:07 +09:00
dependabot[bot]
cdc7842bc4 Bump uuid from 1.20.0 to 1.21.0 (#7258)
Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.20.0 to 1.21.0.
- [Release notes](https://github.com/uuid-rs/uuid/releases)
- [Commits](https://github.com/uuid-rs/uuid/compare/v1.20.0...v1.21.0)

---
updated-dependencies:
- dependency-name: uuid
  dependency-version: 1.21.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 22:07:49 +09:00
fanninpm
f5a071d52d Edit dependency groups (#7257)
* Add random dependency group

See #7064 for why.

* Fold cranelift group into wasmtime group
2026-02-28 22:07:29 +09:00
dependabot[bot]
5c726e1c55 Bump chrono from 0.4.43 to 0.4.44 (#7256)
Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.43 to 0.4.44.
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.43...v0.4.44)

---
updated-dependencies:
- dependency-name: chrono
  dependency-version: 0.4.44
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 03:34:08 +00:00
dependabot[bot]
32684f9d45 Bump the cranelift group with 3 updates (#7252)
Bumps the cranelift group with 3 updates: [cranelift](https://github.com/bytecodealliance/wasmtime), [cranelift-jit](https://github.com/bytecodealliance/wasmtime) and [cranelift-module](https://github.com/bytecodealliance/wasmtime).


Updates `cranelift` from 0.128.3 to 0.129.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-jit` from 0.128.3 to 0.129.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

Updates `cranelift-module` from 0.128.3 to 0.129.1
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.129.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cranelift
- dependency-name: cranelift-jit
  dependency-version: 0.129.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cranelift
- dependency-name: cranelift-module
  dependency-version: 0.129.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cranelift
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-28 03:27:28 +00:00
Jeong, YunWon
754fc85fb8 Fix trace_event to return trace function result
- Return trace function's return value from trace_event()
  to support per-frame f_trace assignment
- Match CPython's trace_trampoline: set f_trace from call
  event return value, clear on error
- Fire return event only when frame is traced or profiled
- Remove expectedFailure from passing bdb/settrace tests
2026-02-28 12:09:59 +09:00
CPython Developers
78c5a2ec28 Update bdb from v3.14.3 2026-02-28 12:09:59 +09:00
Jiseok CHOI
81acb9b7c1 sqlite3: handle int type in Connection.timeout parameter (#7237) 2026-02-28 10:38:30 +09:00
Jiseok CHOI
5a1b3355c2 fix: add readinto and write methods to RawIOBase (#7234) 2026-02-28 10:37:26 +09:00
Shahar Naveh
e0eb6d5e8e Reapply "ast.NodeVisitor for import tracking" (#7241)
* Reapply "`ast.NodeVisitor` for import tracking (#7229)" (#7230)

This reverts commit a47572c89e.
2026-02-28 10:37:00 +09:00
Shahar Naveh
4092346f95 Update subprocess.py to 3.14.3 (#7244) 2026-02-28 10:36:09 +09:00
Jeong, YunWon
0e48ca95f2 extend timeout 2026-02-28 10:35:38 +09:00
Jeong, YunWon
211823e498 Fix dict race condition 2026-02-28 10:35:38 +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
2447d99b12 Specify minor version for pyo3 (#7248)
* Specify minor version for pyo3

* Auto-format: ruff format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-28 10:34:04 +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
Shahar Naveh
4f577e5f99 Update ruff to 0.15.4 (#7246)
* Update ruff to 0.15.4

* Unmark passing test
2026-02-27 22:59:41 +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
c5472e2a4e sqlite3: reject negative fetchmany values (#7240) 2026-02-27 21:03:40 +09:00
Jiseok CHOI
f7fe9c53cb sqlite3: reject negative arraysize values (#7238) 2026-02-27 20:59:15 +09:00
Jiseok CHOI
f8d8e25de4 Fix IOBase.fileno() incorrect error message (#7232)
fileno() was calling _unsupported with "truncate" instead of "fileno",
causing UnsupportedOperation('truncate') to be raised instead of
UnsupportedOperation('fileno').

CPython 3.14 reference: Modules/_io/iobase.c calls iobase_unsupported(state, "fileno")
Fixes: ever0de/RustPython#1
2026-02-27 20:46:42 +09:00
Jeong, YunWon
89fb3494f4 Merge pull request #7223 from youknowone/tarfile
Update tarfile from v3.14.3 and fix bugs
2026-02-27 20:44:16 +09:00
Shahar Naveh
8b27eaf8f1 Update test_atexit.py to 3.14.3 (#7217) 2026-02-27 19:29:59 +09:00
Jeong, YunWon
f1511c4be0 Merge pull request #7242 from ShaharNaveh/update-xml
Update `xml` to 3.14.3
2026-02-27 19:25:25 +09:00
ShaharNaveh
eed53cbe9d Patch test_sax.py 2026-02-27 10:05:21 +01:00
ShaharNaveh
fa68faa2e5 Mark failing tests at test_pyexpat.py 2026-02-27 09:58:46 +01:00
ShaharNaveh
b7589a752b Mark failing tests on test_minidom.py 2026-02-27 09:55:31 +01:00
ShaharNaveh
c6562efce5 Patch test_xml_etree.py 2026-02-27 09:49:35 +01:00
ShaharNaveh
fd5e91dbff Update xml to 3.14.3 2026-02-27 09:44:41 +01:00
Jeong, YunWon
36cffabeda xz2->liblzma and remove liblzma-sys 2026-02-27 17:39:12 +09:00
Jeong, YunWon
ff02c266ac Unmark test_lzma 2026-02-27 16:53:55 +09:00
Jeong, YunWon
3be78c6545 new_lzma_error 2026-02-27 16:53:55 +09:00
CPython Developers
df9fb69de5 Update tarfile from v3.14.3 2026-02-27 16:53:55 +09:00
Jiseok CHOI
09cf49204b fix: add flush method to BytesIO (#7235) 2026-02-27 16:53:17 +09:00
Shahar Naveh
4c2537010d Update http from 3.14.3 (#7137)
* Update `http` from 3.14.3

* Reapply patch

* Update `test/certdata` from 3.14.3

* Revert "Update `test/certdata` from 3.14.3"

This reverts commit fa8fb388b3.

* Update `test_httpservers.py`

* Reapply long test patch

* Mark failing tests

* Skip flaky test

* Allow password to be None

* Unmark passing test

* Fix error message

* Clippy

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2026-02-27 05:44:37 +00:00
Jeong, YunWon
684001ffa2 Instrumented instruction (#7212)
* Update test_monitoring from CPython 3.14.3

* patch test_monitoring not to entirely skipped

* impl sys.monitoring

* Update test_compile from v3.14.3

* instrumented instructions

* Implement side-table instrumented opcode execution

Add CoMonitoringData with line_opcodes and per_instruction_opcodes
side-tables. INSTRUMENTED_LINE and INSTRUMENTED_INSTRUCTION read
original opcodes from side-tables and re-dispatch after firing events.

- Add decode_exception_table() and CodeUnits::replace_op()
- Add Instruction::to_instrumented/to_base/is_instrumented mappings
- Three-phase instrument_code: de-instrument, re-instrument regular,
  then layer INSTRUCTION and LINE with side-table storage
- Mark exception handler targets as line starts in LINE placement
- InstrumentedLine resolves side-table chain atomically when wrapping
  InstrumentedInstruction
- InstrumentedForIter fires both BRANCH_LEFT and BRANCH_RIGHT
- Remove callback on DISABLE return for non-local events

* mark failing tests

* set_f_lineno, set_f_lasti, PyAtomic refactor

- Implement set_f_lineno with stack analysis and deferred unwinding
- Add Frame::set_lasti() for trace callback line jumps
- Implement co_branches() on code objects
- Clear _cache_format in opcode.py (no inline caches)
- Fix getattro slot inheritance: preserve native slot from inherit_slots
- Fix BRANCH_RIGHT src_offset in InstrumentedPopJumpIf*
- Move lasti increment before line event for correct f_lineno
- Skip RESUME instruction from generating line events
- Defer stack pops via pending_stack_pops/pending_unwind_from_stack
  to avoid deadlock with state mutex
- Fix ForIter exhaust target in mark_stacks to skip END_FOR
- Prevent exception handler paths from overwriting normal-flow stacks
- Replace #[cfg(feature = "threading")] duplication with PyAtomic<T>
  from rustpython_common::atomic (Radium-based unified API)
- Remove expectedFailure from 31 now-passing jump tests

* Unmark successful tests

test_peepholer
test_bdb

---------

Co-authored-by: CPython Developers <>
2026-02-27 13:23:33 +09:00
Jeong, YunWon
1fdd4fd35c Fix dict concurrency stability (#7231) 2026-02-27 13:23:12 +09:00
Jeong, YunWon
4567c689ce Unmark successful tests
test_peepholer
test_bdb
2026-02-27 09:07:23 +09:00
Jeong, YunWon
20a93c54c4 set_f_lineno, set_f_lasti, PyAtomic refactor
- Implement set_f_lineno with stack analysis and deferred unwinding
- Add Frame::set_lasti() for trace callback line jumps
- Implement co_branches() on code objects
- Clear _cache_format in opcode.py (no inline caches)
- Fix getattro slot inheritance: preserve native slot from inherit_slots
- Fix BRANCH_RIGHT src_offset in InstrumentedPopJumpIf*
- Move lasti increment before line event for correct f_lineno
- Skip RESUME instruction from generating line events
- Defer stack pops via pending_stack_pops/pending_unwind_from_stack
  to avoid deadlock with state mutex
- Fix ForIter exhaust target in mark_stacks to skip END_FOR
- Prevent exception handler paths from overwriting normal-flow stacks
- Replace #[cfg(feature = "threading")] duplication with PyAtomic<T>
  from rustpython_common::atomic (Radium-based unified API)
- Remove expectedFailure from 31 now-passing jump tests
2026-02-27 09:07:23 +09:00
Jeong, YunWon
fa1e75a809 mark failing tests 2026-02-27 09:07:23 +09:00
Jeong, YunWon
9c329bd62f Implement side-table instrumented opcode execution
Add CoMonitoringData with line_opcodes and per_instruction_opcodes
side-tables. INSTRUMENTED_LINE and INSTRUMENTED_INSTRUCTION read
original opcodes from side-tables and re-dispatch after firing events.

- Add decode_exception_table() and CodeUnits::replace_op()
- Add Instruction::to_instrumented/to_base/is_instrumented mappings
- Three-phase instrument_code: de-instrument, re-instrument regular,
  then layer INSTRUCTION and LINE with side-table storage
- Mark exception handler targets as line starts in LINE placement
- InstrumentedLine resolves side-table chain atomically when wrapping
  InstrumentedInstruction
- InstrumentedForIter fires both BRANCH_LEFT and BRANCH_RIGHT
- Remove callback on DISABLE return for non-local events
2026-02-27 09:07:22 +09:00
Jeong, YunWon
4ef1b48155 instrumented instructions 2026-02-27 09:06:56 +09:00
CPython Developers
3c7b25d0fa Update test_compile from v3.14.3 2026-02-27 09:06:56 +09:00
Jeong, YunWon
739f92e872 impl sys.monitoring 2026-02-27 09:06:55 +09:00
Jeong, YunWon
f35d0fde0b patch test_monitoring not to entirely skipped 2026-02-27 04:36:46 +09:00
CPython Developers
abc7d6dfe6 Update test_monitoring from CPython 3.14.3 2026-02-27 04:36:46 +09:00
Jeong, YunWon
93099e35e7 Remove PyStr::as_str, use as_wtf8/PyUtf8Str instead (#7218)
- Remove as_str() from PyStr/Py<PyStr> (was panicking on surrogates)
- Add Wtf8Concat trait and concat! macro for WTF-8 formatting
- Add impl From<&str> for &Wtf8 conversion
- Add AsPyStr/DictKey impls for PyUtf8Str types
- Migrate all call sites to as_wtf8(), to_str(), or PyUtf8Str
- Fix exception message APIs to accept Wtf8Buf
- Deduplicate inner-scope imports across modules
2026-02-27 04:20:11 +09:00
Jeong, YunWon
a47572c89e Revert "ast.NodeVisitor for import tracking (#7229)" (#7230)
This reverts commit 804a7e42fc.
2026-02-27 03:55:13 +09:00
Shahar Naveh
804a7e42fc ast.NodeVisitor for import tracking (#7229) 2026-02-27 03:07:57 +09:00
Jeong, YunWon
c98215ab3a Clear frame locals and stack on generator close + Add dir_fd support for rmdir, remove/unlink, scandir (#7222)
* Clear frame locals and stack on generator close

Add Frame::clear_locals_and_stack() to release references held by
closed generators/coroutines, matching _PyFrame_ClearLocals behavior.
Call it from Coro::close() after marking the coroutine as closed.

Update test_generators.py expectedFailure markers accordingly.

* Add dir_fd support for rmdir, remove/unlink, scandir

- rmdir: use unlinkat(fd, path, AT_REMOVEDIR) when dir_fd given
- remove/unlink: use unlinkat(fd, path, 0) when dir_fd given
- scandir: accept fd via fdopendir, add ScandirIteratorFd
- listdir: rewrite fd path to use raw readdir instead of nix::dir::Dir
- DirEntry: add d_type and dir_fd fields for fd-based scandir
- Update supports_fd/supports_dir_fd entries accordingly

* cells_free
2026-02-27 01:58:33 +09:00
Shahar Naveh
457d328294 update_lib test format fix + deps for atexit & eintr (#7227)
* update_lib deps for atexit & eintr

* Fix test format
2026-02-26 12:03:47 +09:00
Shahar Naveh
8cf8cb561a Update compileall.py to 3.14.3 (#7225) 2026-02-25 21:15:55 +09:00
Shahar Naveh
56de2cd76c Don't skip test_glob on windows (#7224) 2026-02-25 21:01:51 +09:00
Copilot
9f250a0f6e Fix upgrade-pylib workflow to use Python 3.14 (#7216) 2026-02-24 16:22:44 +09:00
CPython Developers
1df878e5d3 Update annotationlib from v3.14.3 2026-02-24 16:22:44 +09:00
CPython Developers
000025e09c Update zipfile from v3.14.3 2026-02-24 14:23:19 +09:00
Jeong, YunWon
3ec7b5c375 Implement Windows SemLock in _multiprocessing module (#7199)
* Implement Windows SemLock in _multiprocessing module

Add SemLock class using Windows semaphore APIs (CreateSemaphoreW,
WaitForSingleObjectEx, ReleaseSemaphore) so test_multiprocessing
suites are no longer skipped with "lacks a functioning sem_open".
Also add sem_unlink as no-op and flags dict for Windows.

* Fix _multiprocessing recv to return bytes and improve SemLock reliability

- recv() now returns bytes instead of int (matching CPython)
- Remove spurious GetLastError() check after CreateSemaphoreW
- Add signal checking during blocking SemLock acquire

* Include winerror in OSError.__reduce__ on Windows

* Remove expectedFailure for tests now passing with Windows SemLock

* Fix OSError.__reduce__ to preserve winerror when filename is None

When filename is None, __reduce__ was reconstructing a 2-element
(errno, msg) tuple, dropping the winerror at position 3 in the
original args. Use the original args tuple instead, matching CPython.

* Validate maxvalue > 0 in SemLock and document winerror __reduce__ divergence

* Reject embedded null characters in mmap tagname and _winapi file mapping names
2026-02-24 10:12:29 +09:00
Shahar Naveh
f784a562f8 Update datetime to 3.14.3 (#7084) 2026-02-24 01:07:30 +00:00
Jeong, YunWon
dc7cd26c3c cold block reordering and jump normalization (#7210)
* cold block reordering and jump normalization

Add mark_cold, push_cold_blocks_to_end, and normalize_jumps
passes to the codegen CFG pipeline. Use JumpNoInterrupt for
exception handler exit paths in try-except-finally compilation.

* mark test_peepholer
2026-02-24 08:53:07 +09:00
Jeong, YunWon
0244657770 [workflow] fix upgrade-pylib (#7211) 2026-02-24 00:15:55 +09:00
dependabot[bot]
f478ace1a4 Bump github/gh-aw from 0.45.0 to 0.49.4 (#7209)
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.45.0 to 0.49.4.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](58d1d157fb...bf34f99475)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.49.4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-23 23:36:55 +09:00
Jeong, YunWon
490a17f641 Implement Windows named mmap via CreateFileMappingW (#7207)
Use Win32 CreateFileMappingW + MapViewOfFile when tagname is
provided, enabling inter-process shared memory for
multiprocessing.heap.Arena. Anonymous mmaps without tagname
still use memmap2.

Remove expectedFailure from test_tagname in test_mmap.py.
2026-02-23 23:32:52 +09:00
Jeong, YunWon
39a5d39c7c Merge pull request #7203 from youknowone/pymodule
#[pymodule] submodule support and implicit module_name inheritance
2026-02-23 22:17:06 +09:00
Jeong, YunWon
649a2bf4de implicit module_name under #[pymodule] 2026-02-23 22:16:44 +09:00
Jeong, YunWon
eb07113d91 support sub-module from #[pymodule] 2026-02-23 22:16:40 +09:00
Jeong, YunWon
7dc76c8df1 skip flaky test (#7208) 2026-02-23 22:08:50 +09:00
Jeong, YunWon
f096bb7dd0 Fix deadlock after fork (#7205)ㅐ 2026-02-23 16:22:26 +09:00
Jeong, YunWon
a67079909e Fix EINTR handling (#7204) 2026-02-23 16:13:24 +09:00
CPython Developers
ccfa938f67 Update test_gc from v3.14.3 2026-02-23 08:48:18 +09:00
Jeong, YunWon
b48f72d0ad Fix Overlapped I/O by boxing OVERLAPPED struct and accept overlapped arg positionally (#7198)
Two fixes in _winapi:

1. Box the OVERLAPPED struct in OverlappedInner to ensure it stays at
   a stable heap address. Previously, into_pyobject() moved the struct
   after ReadFile/WriteFile had given the OS a pointer to it, causing
   GetOverlappedResult to read stale data (returning err=0 instead of
   ERROR_MORE_DATA for zero-byte reads on message pipes).

2. Change ReadFile, WriteFile, ConnectNamedPipe overlapped parameter
   from #[pyarg(named)] to #[pyarg(any)] so it can be passed both
   positionally and as keyword argument.
2026-02-22 22:14:06 +09:00
Jeong, YunWon
6950baf687 more algorithm-independent GC infra (#7194)
* mark poluting tests

* GC-infra independent to EBR

* trashcan

* add overflow guard to inc(), #[must_use] on dec()/safe_inc(), trashcan debug_assert, weakref generic re-check
2026-02-22 21:31:42 +09:00
Jeong, YunWon
f9ca638936 Remove recreate:true from lib-deps-check (#7201) 2026-02-22 20:27:14 +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
Jeong, YunWon
2981010a90 Merge pull request #7195 from youknowone/sys
StatelessIncrementalEncoder, sys attributes
2026-02-22 00:30:56 +09:00
Jeong, YunWon
d19d523c8d Move sys.flags thread_inherit_context/context_aware_warnings to getset 2026-02-21 22:58:12 +09:00
Jeong, YunWon
ea8e25cee5 Register latin-1 codec and fix stdio bootstrap 2026-02-21 22:58:12 +09:00
Jeong, YunWon
6a02392b57 Fix WindowsVersionData n_sequence_fields 2026-02-21 22:58:12 +09:00
Jeong, YunWon
f5eadae767 Merge pull request #7075 from youknowone/sys
Update test_sys from v3.14.3 and impl more sys module
2026-02-21 19:26:58 +09:00
Jeong, YunWon
5cc589980c Infer struct sequence module name from __module__ attribute in repr
slot_repr now checks the __module__ attribute set by #[pymodule]
at runtime, so explicit module = "..." in #[pystruct_sequence] is
no longer needed for types defined inside a #[pymodule].
2026-02-21 14:23:49 +09:00
Jeong, YunWon
add253912e Implement sys.call_tracing, sys._current_exceptions
- Add sys.call_tracing as func(*args) dispatch
- Add sys._current_exceptions with per-thread exception tracking
  via thread_exceptions registry synced on push/pop/set_exception
- Fix f_back to use previous_frame pointer and cross-thread lookup
- Add module="sys" to float_info struct sequence
- Fix sys.exit to unpack tuple args
- Set default stdio_errors to surrogateescape
- Remove noisy __del__ warning in object core
2026-02-21 14:12:18 +09:00
CPython Developers
edca2dddf1 Update test_sys from v3.14.3 2026-02-21 14:12:18 +09:00
dependabot[bot]
9611b88788 Bump keccak from 0.1.5 to 0.1.6 (#7192)
Bumps [keccak](https://github.com/RustCrypto/sponges) from 0.1.5 to 0.1.6.
- [Commits](https://github.com/RustCrypto/sponges/compare/keccak-v0.1.5...keccak-v0.1.6)

---
updated-dependencies:
- dependency-name: keccak
  dependency-version: 0.1.6
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-20 23:14:21 +09:00
Jeong, YunWon
6ced4409ac force_unlock_after_fork (#7186) 2026-02-20 09:53:01 +09:00
wvmscs
dfc5de701b Fix re.fullmatch POSSESSIVE_REPEAT (#7187) 2026-02-20 09:51:34 +09:00
Shahar Naveh
eddb8f271a Newtype oparg for StoreFastLoadFast (#7191) 2026-02-20 08:19:12 +09:00
Lee Dogeon
41ea698f6a Update test_collections from v3.14.3 (#7189) 2026-02-19 08:48:33 +09:00
Jeong, YunWon
80d7850866 Merge pull request #7188 from moreal/update-3.14.3-types
Update types from v3.14.3
2026-02-18 21:49:19 +09:00
Lee Dogeon
3d33bea285 Remove expectedFailure from test_types_coroutine_wrapper_state
The types.py upgrade added gi_suspended to _GeneratorWrapper,
fixing this test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 18:39:56 +09:00
Lee Dogeon
24e51ee98c Mark failing tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 18:38:44 +09:00
CPython Developers
8cbf870238 Update types from v3.14.3 2026-02-18 17:19:49 +09:00
Jeong, YunWon
8e70048891 Merge pull request #7165 from youknowone/ctypes
Update ctypes from v3.14.3 and make _ctypes compatible
2026-02-18 08:21:27 +09:00
github-actions[bot]
8b50737914 Auto-format: cargo fmt --all 2026-02-17 18:11:21 +00:00
Jeong, YunWon
38d54fa0cd impl more ctypes
- Add __pointer_type__ getter/setter and StgInfo cache
- Add kept_refs (HashMap-keyed) for c_char_p lifetime
- Simplify ensure_z_null_terminated to 2-value return
- Add RawMemoryBuffer for zero-copy memoryview_at_addr
- Add bitfield support in PyCField with validation
- Add CArgObject offset handling in extract_ptr_from_arg
- Add deprecation warning for _pack_ without _layout_
- Fix comparison TypeError message format
- Fix unsupported binop error message format
- Mark failing CI tests as expectedFailure/skip
2026-02-18 03:10:40 +09:00
Jeong, YunWon
36a53ddf66 fix buffer whitespace skip 2026-02-18 03:10:14 +09:00
CPython Developers
4b7f1f8751 Update ctypes from v3.14.3 2026-02-18 03:09:55 +09:00
Jeong, YunWon
e81a0fc765 Use try_lock in py_os_after_fork_child (#7178)
after_forkers_child.lock() can deadlock in the forked child
if another thread held the mutex at the time of fork.
Use try_lock and skip at-fork callbacks when the lock is
unavailable, matching the pattern used in after_fork_child
for thread_handles.
2026-02-18 02:24:06 +09:00
Jeong, YunWon
b5785e2777 Use _print_exception_bltin in excepthook, register source in linecache (#7177)
- excepthook: call traceback._print_exception_bltin instead of
  traceback.print_exception to match PyErr_Display behavior
- run_string: register compiled code in linecache._interactive_cache
  so traceback can display source lines and caret indicators
- Remove test_sys_tracebacklimit expectedFailure
2026-02-18 01:50:27 +09:00
Jeong, YunWon
ccccaaf06f Merge pull request #7184 from youknowone/winsound
Update test_winsound from v3.14.3
2026-02-18 00:47:16 +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
Shahar Naveh
f0f3c9c8cf Update csv.py from 3.14.3 (#7181)
* Update `csv.py` from 3.14.3

* Don't hardcode error message for `int` class
2026-02-18 00:43:49 +09:00
Jeong, YunWon
d4d010ec21 Fix unpack_sequence to match CPython behavior (#7175)
Add fast path for exact tuple/list (direct length check without
iterator). General path now iterates only size+1 elements,
fixing hang on infinite sequences like __getitem__ without
raising IndexError.

Error messages now include "got N" for tuple, list, and dict.
Remove 7 expectedFailure/skip markers from test_unpack.
2026-02-18 00:41:53 +09:00
Jeong, YunWon
8fa0c66bc4 Optimize coroutine exception handling and fix gen_throw traceback (#7166)
- Replace ExceptionStack linked list with Vec for O(1) push/pop
- Introduce FramePtr (NonNull<Py<Frame>>) to avoid Arc clone in frame stack
- Use FramePtr in ThreadSlot for lock-protected cross-thread frame access
- Add resume_gen_frame for lightweight generator/coroutine resume
- Replace Coro.exception PyMutex with PyAtomicRef for lock-free swap
- Add with_frame_exc to support initial exception state for generators
- Use scopeguard for panic-safe cleanup in with_frame_exc/resume_gen_frame
- Add traceback entries in gen_throw delegate/close error paths
- Treat EndAsyncFor and CleanupThrow as reraise in handle_exception
- Update current_frame()/current_globals() to return owned values
- Add ThreadSlot with atomic exception field for sys._current_exceptions()
- Push/pop thread frames in resume_gen_frame for sys._current_frames()
2026-02-17 21:35:05 +09:00
Jeong, YunWon
705dd7dddd Implement winsound module
Add PlaySound, Beep, MessageBeep functions and all SND_*/MB_*
constants. Uses Windows APIs via winmm.dll, kernel32, user32.
2026-02-17 21:34:27 +09:00
CPython Developers
b7643c08cf Update test_winsound from v3.14.3 2026-02-17 21:33:54 +09:00
Jeong, YunWon
6b4605280e cap mt19937 version (#7182) 2026-02-17 20:02:28 +09:00
Jeong, YunWon
b87386f4fc Update test_fstring from v3.14.3 and impl more (#7164)
* Update test_fstring from v3.14.3

* Fix 6 test_fstring expectedFailure tests

- Add Unknown(char) variant to FormatType for proper error messages
  on unrecognized format codes (test_errors)
- Strip comments from f-string debug text in compile.rs
  (test_debug_conversion)
- Map ruff SyntaxError messages to match CPython in vm_new.rs:
  InvalidDeleteTarget, LineContinuationError, UnclosedStringError,
  OtherError(bytes mixing), OtherError(keyword identifier),
  FStringError(UnterminatedString/UnterminatedTripleQuotedString),
  and backtick-to-quote replacement for FStringError messages

* Fix clippy::sliced_string_as_bytes warning

---------

Co-authored-by: CPython Developers <>
2026-02-17 16:49:59 +09:00
dependabot[bot]
e3c533a53c Bump github/gh-aw from 0.43.22 to 0.45.0
Bumps [github/gh-aw](https://github.com/github/gh-aw) from 0.43.22 to 0.45.0.
- [Release notes](https://github.com/github/gh-aw/releases)
- [Changelog](https://github.com/github/gh-aw/blob/main/CHANGELOG.md)
- [Commits](fe858c3e14...58d1d157fb)

---
updated-dependencies:
- dependency-name: github/gh-aw
  dependency-version: 0.45.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-17 10:31:13 +09:00
dependabot[bot]
ee6ff22947 Bump actions/setup-python from 5.6.0 to 6.2.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5.6.0 to 6.2.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v5.6.0...v6.2.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: 6.2.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-17 09:44:06 +09:00
dependabot[bot]
5ca3c2894b Bump actions/download-artifact from 6.0.0 to 7.0.0
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 6.0.0 to 7.0.0.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-17 09:43:43 +09:00
dependabot[bot]
3d9480acf9 Bump actions/cache from 4.3.0 to 5.0.3
Bumps [actions/cache](https://github.com/actions/cache) from 4.3.0 to 5.0.3.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](0057852bfa...cdf6c1fa76)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-version: 5.0.3
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-17 09:43:25 +09:00
dependabot[bot]
530e4db6ec Bump bitflags from 2.10.0 to 2.11.0
Bumps [bitflags](https://github.com/bitflags/bitflags) from 2.10.0 to 2.11.0.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/2.10.0...2.11.0)

---
updated-dependencies:
- dependency-name: bitflags
  dependency-version: 2.11.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-17 09:42:42 +09:00
dependabot[bot]
1f338ce201 Bump pyo3 from 0.28.0 to 0.28.1 in the pyo3 group
Bumps the pyo3 group with 1 update: [pyo3](https://github.com/pyo3/pyo3).


Updates `pyo3` from 0.28.0 to 0.28.1
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pyo3/pyo3/compare/v0.28.0...v0.28.1)

---
updated-dependencies:
- dependency-name: pyo3
  dependency-version: 0.28.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: pyo3
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-17 09:42:28 +09:00
ShaharNaveh
d71ffa6c47 Use shared doctest checker 2026-02-17 01:31:29 +09:00
ShaharNaveh
0832828953 Update test_unpack.py from 3.14.3 2026-02-16 23:34:17 +09:00
Jeong, YunWon
79453c3e6d Merge pull request #7141 from youknowone/execve
Accept any mapping for os.execve env argument
2026-02-16 03:22:51 +09:00
Jeong, YunWon
243beb692b Merge pull request #7151 from youknowone/winconsoleio
_WindowsConsoleIO
2026-02-16 01:51:24 +09:00
ShaharNaveh
c76fb0145b Update test_richcmp.py from 3.14.3 2026-02-16 01:19:57 +09:00
Jeong, YunWon
72b4ef31a2 Accept any mapping for os.execve env argument
Change env parameter from PyDictRef to ArgMapping so that
EnvironmentVarGuard and other mapping types are accepted.
2026-02-16 01:03:18 +09:00
Jeong, YunWon
7b1db4868a Merge pull request #7162 from youknowone/wmi
impl _wmi module
2026-02-16 00:52:05 +09:00
CPython Developers
8552e42d94 Update test_winconsoleio from v3.14.3 2026-02-16 00:31:57 +09:00
Jeong, YunWon
8e06707fc6 Implement _WindowsConsoleIO and _testconsole module
Add _WindowsConsoleIO class to _io module with ReadConsoleW/WriteConsoleW support.
Add _testconsole stdlib module with write_input for console input simulation.
Integrate console detection in io_open to use _WindowsConsoleIO for console handles.
2026-02-16 00:28:51 +09:00
Jeong, YunWon
4897e0322d Add _wmi module
Implement _wmi.exec_query via COM/WMI using pipe+thread
pattern matching _wmimodule.cpp. Uses raw COM vtable calls
for IWbemLocator, IWbemServices, IEnumWbemClassObject, and
IWbemClassObject interfaces.
2026-02-15 23:44:23 +09:00
CPython Developers
09b528168e Update test_wmi from v3.14.3 2026-02-15 23:44:23 +09:00
Jeong, YunWon
4f366d7937 Skip flaky test_main_thread_after_fork_from_nonmain_thread 2026-02-15 23:42:09 +09:00
ShaharNaveh
3047a63941 Update test_scope.py from 3.14.3 2026-02-15 23:40:14 +09:00
Jeong, YunWon
b4edd547dc Merge pull request #7159 from youknowone/hashlib
_hashlib.HMAC and Update hmac from v3.14.3
2026-02-15 23:38:55 +09:00
Shahar Naveh
e1db19c892 Update test_with.py from 3.14.3 (#7158) 2026-02-15 23:38:22 +09:00
Jeong, YunWon
5530855436 Make __hello_only__ a frozen-only alias of __hello__ (#7160)
Remove __hello_only__.py source file and its symlink. Register
__hello_only__ as a frozen module alias reusing __hello__ bytecode,
matching the behavior where origname is None (no source file).
2026-02-15 22:25:28 +09:00
Jeong, YunWon
f805fa7c8b Fix winreg and Update test_launcher from v3.14.3 (#7155)
* Fix winreg SetValueEx and OSError winerror attribute

- SetValueEx: accept None for value_name (default registry value)
- os_error_from_windows_code: use std::io::Error to properly
  set winerror attribute on OSError
- EnumKey: use os_error_from_windows_code for proper error

* Update test_launcher from v3.14.3

* Update test_winreg from v3.14.3

* Update crates/vm/src/stdlib/winreg.rs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: CPython Developers <>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-02-15 22:11:48 +09:00
Jeong, YunWon
10c393f063 _hashlib.HMAC 2026-02-15 22:09:29 +09:00
CPython Developers
2a611c992d Update hmac from v3.14.3 2026-02-15 21:04:32 +09:00
Shahar Naveh
64088bb624 Add CI step for checking redundant test patches (#7126) 2026-02-15 20:39:57 +09:00
Lee Dogeon
2567355a99 Emit deprecation warning for array typecode u (#7157) 2026-02-15 20:34:19 +09:00
Lee Dogeon
914634e4df Align lzma and os exports for test_all expected failure (#7156) 2026-02-15 20:33:58 +09:00
Shahar Naveh
fbbd020e07 Update test_ast.py from 3.14.3 (#7147) 2026-02-15 20:29:05 +09:00
Jeong, YunWon
1ead81f11e Remove Windows skip markers from test_urllib2_localnet (#7154)
The "illegal environment variable name" issue has been resolved.
All 21 tests now pass on Windows.
2026-02-15 16:30:58 +09:00
Jeong, YunWon
5610a7c2f4 Merge pull request #7153 from youknowone/unskip1
Remove Windows skip from test_configparser test_parse_errors
2026-02-15 16:09:33 +09:00
Jeong, YunWon
9afd031e1d Merge pull request #7152 from moreal/codecs-related-tests-3.14.3
Add untracked tests related codecs from v3.14.3
2026-02-15 16:07:02 +09:00
Jeong, YunWon
563abea251 Require exact n_sequence_fields length in TryFromObject (#7150)
Unmark test_asctime expectedFailure for Windows.
2026-02-15 14:37:48 +09:00
Lee Dogeon
4e801b6ff8 Use @unittest.skip instead of @unittest.expectedFailure for codec encoding tests
The encoding errors occur in setUp() which causes ERRORs, not FAILUREs.
@unittest.expectedFailure only catches test failures, not setUp errors.
Using class-level @unittest.skip properly handles this case.
2026-02-15 14:37:06 +09:00
Lee Dogeon
6115ec703d Mark failing tests for test_codecmaps_tw 2026-02-15 14:33:37 +09:00
CPython Developers
89b31f72d6 Update test_codecmaps_tw from v3.14.3 2026-02-15 14:33:31 +09:00
Lee Dogeon
d75ae19888 Mark failing tests for test_codecmaps_kr 2026-02-15 14:33:26 +09:00
CPython Developers
4c9ef79fa5 Update test_codecmaps_kr from v3.14.3 2026-02-15 14:33:20 +09:00
Lee Dogeon
d504b28389 Mark failing tests for test_codecmaps_jp 2026-02-15 14:33:16 +09:00
CPython Developers
5138581e12 Update test_codecmaps_jp from v3.14.3 2026-02-15 14:33:09 +09:00
Lee Dogeon
5caa9009b7 Mark failing tests for test_codecmaps_hk 2026-02-15 14:33:05 +09:00
CPython Developers
20737e3bde Update test_codecmaps_hk from v3.14.3 2026-02-15 14:32:58 +09:00
Lee Dogeon
61825382ed Mark failing tests for test_codecmaps_cn 2026-02-15 14:32:53 +09:00
CPython Developers
2a29fa6e8f Update test_codecmaps_cn from v3.14.3 2026-02-15 14:32:31 +09:00
Lee Dogeon
04f12d2fc9 Mark failing tests for test_codecencodings_tw 2026-02-15 14:32:10 +09:00
CPython Developers
b500957da1 Update test_codecencodings_tw from v3.14.3 2026-02-15 14:32:03 +09:00
Lee Dogeon
2d7c54796f Mark failing tests for test_codecencodings_kr 2026-02-15 14:31:59 +09:00
CPython Developers
ccf6395c51 Update test_codecencodings_kr from v3.14.3 2026-02-15 14:31:51 +09:00
Lee Dogeon
5ea5d7864e Mark failing tests for test_codecencodings_jp 2026-02-15 14:31:45 +09:00
CPython Developers
68256fb877 Update test_codecencodings_jp from v3.14.3 2026-02-15 14:31:36 +09:00
Lee Dogeon
f8be47d758 Mark failing tests for test_codecencodings_iso2022 2026-02-15 14:31:31 +09:00
CPython Developers
a1b34eda22 Update test_codecencodings_iso2022 from v3.14.3 2026-02-15 14:31:22 +09:00
Lee Dogeon
7918d42815 Mark failing tests for test_codecencodings_hk 2026-02-15 14:31:18 +09:00
CPython Developers
fb6a5bbce2 Update test_codecencodings_hk from v3.14.3 2026-02-15 14:31:11 +09:00
Lee Dogeon
d2be8c0f79 Mark failing tests for test_codecencodings_cn 2026-02-15 14:31:06 +09:00
CPython Developers
5c280d070d Update test_codecencodings_cn from v3.14.3 2026-02-15 14:30:45 +09:00
Lee Dogeon
cf21e2da10 Include SHAKE algorithm names in HASHXOF repr (#7132) 2026-02-15 09:05:42 +09:00
Shahar Naveh
c1a327d38b Update test_descrtut.py from 3.14.3 (#7149)
Co-authored-by: CPython Developers <>
2026-02-15 09:03:56 +09:00
Jeong, YunWon
1adf9258fc Merge pull request #7148 from ShaharNaveh/update-libs-1
Update some libs & tests to 3.14.3
2026-02-15 09:03:00 +09:00
CPython Developers
8578114a5e Update shutil from v3.14.3 2026-02-15 09:02:24 +09:00
github-actions[bot]
15555d42e7 Auto-format: cargo fmt --all 2026-02-14 16:32:00 +00:00
ShaharNaveh
5dfeee25bb Update test_binascii.py 2026-02-14 18:27:31 +02:00
ShaharNaveh
11a8655d0d Update mailbox.py 2026-02-14 18:19:57 +02:00
ShaharNaveh
9a40f9adec Update xmlrpc 2026-02-14 18:18:53 +02:00
ShaharNaveh
b722ece6af Update test_pyclbr.py from 3.14.3 2026-02-14 18:16:15 +02:00
CPython Developers
f7d8a554cf Update enum from v3.14.3 2026-02-15 00:38:01 +09:00
Shahar Naveh
c30deb21f7 Update _markupbase.py from 3.14.3 (#7129) 2026-02-15 00:37:14 +09:00
Lee Dogeon
e8698aa19f Match SymbolTable repr with CPython format (#7139) 2026-02-14 22:59:42 +09:00
Jeong, YunWon
93d83c1ce9 Merge pull request #7114 from youknowone/unicode
Update test_unicodedata from v3.14.2 and implement more
2026-02-14 22:39:05 +09:00
ShaharNaveh
516ced9a57 Mark failing tests 2026-02-14 22:02:24 +09:00
ShaharNaveh
e94459d194 Update test_struct.py from 3.14.3 2026-02-14 22:02:24 +09:00
Jeong, YunWon
ec0f3b4da8 Merge pull request #7120 from youknowone/hashlib
Update hashlib from v3.14.3 and align _hashlib to CPython
2026-02-14 21:40:27 +09:00
Jeong, YunWon
12db02eaf0 Fix _hashlib 2026-02-14 21:40:04 +09:00
CPython Developers
1f290dccfe Update hashlib from v3.14.3 2026-02-14 21:40:04 +09:00
Lee Dogeon
16c7439c35 Add SHA3 private attribute parity to hashlib hash objects (#7134) 2026-02-14 21:36:57 +09:00
Jeong, YunWon
9e61458772 Merge pull request #7136 from RustPython/agent-wf
upgrade python workflow fix again
2026-02-14 21:36:24 +09:00
github-actions[bot]
16bb1040b4 Update collections from v3.14.3 (#7135)
- Updated Lib/collections from CPython v3.14.3
- Preserved RustPython's fallback implementation for defaultdict
- Added test for update_reentrant_add_clears_counter
- Minor formatting fixes in test file

Co-authored-by: CPython Developers <>
2026-02-14 21:35:25 +09:00
Lee Dogeon
2a2086014c Make HASH/HASHXOF types immutable (#7131) 2026-02-14 20:37:47 +09:00
Jeong, YunWon
4a897e57df copilot fix again 2026-02-14 20:10:39 +09:00
Shahar Naveh
e3edba398e Update test_itertools.py from 3.14.3 (#7130) 2026-02-14 20:00:17 +09:00
Shahar Naveh
29e7f97ef9 Remove redundant patches from test_pickle.py (#7128) 2026-02-14 19:59:47 +09:00
Shahar Naveh
36df9eb288 Remove redundant patches from test_codecs.py (#7127) 2026-02-14 19:58:02 +09:00
Lee Dogeon
799ce31270 Fix SHAKE digest length overflow in hashlib (#7125) 2026-02-14 19:57:27 +09:00
Lee Dogeon
adf9aea274 Fix object.__init__ excess-arg checks for heap types (#7116) 2026-02-14 19:56:49 +09:00
Jeong, YunWon
fe39ec184a Fix module selection (#7123) 2026-02-14 14:56:55 +09:00
Jeong, YunWon
dd422a8c26 Fix copilot upgrade pylib (#7121)
* Use copilot for upgrade workflow

* cache
2026-02-14 13:47:41 +09:00
Jeong, YunWon
f960a0fbad Add gh-aw agentic workflow for upgrading Python libraries (#7117)
* Add gh-aw agentic workflow for upgrading Python libraries

- upgrade-pylib.md: Claude-based workflow triggered via workflow_dispatch
- Runs `scripts/update_lib quick <name>` to sync a library from CPython
- Creates a PR with the result, referencing issue #6839
2026-02-14 11:26:03 +09:00
github-actions[bot]
2e4517971f Auto-format: cargo fmt --all 2026-02-14 00:33:13 +00:00
Jeong, YunWon
334936045d Implement missing unicodedata functions and fix lookup error type
Add combining, decomposition, digit, decimal, numeric methods to Ucd.
Change lookup() to raise KeyError instead of LookupError.
Remove expectedFailure markers from 9 passing tests.
Add unicodedata.is_normalized() method.
Rename decomp_chars to chars to fix spell check.
Remove expectedFailure from test_named_unicode_escapes and
test_urlsplit_normalization.
2026-02-14 09:32:17 +09:00
CPython Developers
9ec6d6c261 Update test_unicodedata from v3.14.2 2026-02-14 09:32:04 +09:00
ShaharNaveh
b9f693004a Update stat.py from 3.14.3 2026-02-14 09:18:09 +09:00
Lee Dogeon
abfa19fc42 Fix inspect.signature introspection for attrgetter/itemgetter/methodcaller (#7111)
* Fix attrgetter signature introspection in operator

* Fix itemgetter signature introspection in operator

* Fix methodcaller signature introspection in operator
2026-02-14 09:17:41 +09:00
Jeong, YunWon
38283becaa Fix typing, typevar, genericalias, and symboltable (#7091)
- TypeVar/ParamSpec repr: use infer_variance flag
- ParamSpec: add type_check on bound argument
- ParamSpecArgs/Kwargs: use equality instead of identity
- NoDefault: change to IMMUTABLETYPE flag
- subscript_generic: wrap TypeVarTuple in Unpack
- symboltable: selective name mangling in type param scopes
- symboltable: fix double default scanning for non-generic fns
- Unmark 4 passing tests in test_type_params
2026-02-14 09:15:57 +09:00
Jeong, YunWon
ad29b43ca6 Use CRT functions for time module on Windows (#7090)
- Replace chrono with CRT functions (wcsftime, _gmtime64_s,
  _localtime64_s, _mktime64) on Windows for correct behavior
- Fix timezone name corruption: use take_while instead of filter
  for null-terminated wide strings in TIME_ZONE_INFORMATION
- Fix wcsftime symbol name (_wcsftime -> wcsftime)
- Fix CString import cfg to unix-only
- Remove 13 expectedFailure markers from test_time for Windows
2026-02-14 09:13:06 +09:00
Jeong, YunWon
a5309f636e Merge pull request #7113 from ShaharNaveh/update-tests-2
Update some tests from 3.14.3
2026-02-13 22:16:18 +09:00
ShaharNaveh
0c85306068 Update test_abc.py from 3.14.3 2026-02-13 22:15:52 +09:00
ShaharNaveh
e9582d1c4e Update pathlib, glob, fnmatch from 3.14.3 2026-02-13 22:15:19 +09:00
Lee Dogeon
4b1ff4b003 Add float.from_number classmethod (#7107) 2026-02-13 11:47:12 +00:00
ShaharNaveh
23a26d2d13 Update test_print 2026-02-13 13:36:33 +02:00
ShaharNaveh
1499607df3 Add test_flufl.py 2026-02-13 13:36:33 +02:00
ShaharNaveh
0dd14d0bdf Update test_dictcomps, test_userdict 2026-02-13 13:36:33 +02:00
ShaharNaveh
a9687f01ee Update test_buffer.py 2026-02-13 13:36:33 +02:00
ShaharNaveh
8b99358339 Update test_bool.py from 3.14.3 2026-02-13 13:36:33 +02:00
ShaharNaveh
9c72e32874 Update posixpath.py from 3.14.3 2026-02-13 20:24:57 +09:00
Jeong, YunWon
578bc625fc Merge pull request #7106 from moreal/test_float
Update test_float from v3.14.3
2026-02-13 19:35:28 +09:00
Shahar Naveh
a058c4f73d Update ruff to 0.15.1 (#7105) 2026-02-13 19:34:49 +09:00
Shahar Naveh
d50cc5e842 Update pydoc.py from 3.14.3 (#7104) 2026-02-13 18:07:25 +09:00
ShaharNaveh
5124f8aca7 Mark failing test 2026-02-13 18:06:47 +09:00
ShaharNaveh
9d7387798c Update test_defaultdict.py from 3.14.3 2026-02-13 18:06:47 +09:00
Lee Dogeon
fb1514b6e8 Mark failing tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:05:39 +09:00
CPython Developers
18a264882b Update test_float from v3.14.3 2026-02-13 18:03:21 +09:00
Jeong, YunWon
743780f868 Merge pull request #7089 from youknowone/io
Update io from v3.14.3 and fix
2026-02-13 15:20:32 +09:00
Jeong, YunWon
718e74d5d4 Update scripts/update_lib/cmd_quick.py 2026-02-13 15:20:19 +09:00
Jeong, YunWon
8f0c6e9508 mark typing 2026-02-13 14:13:30 +09:00
Jeong, YunWon
18114a8b6e Fix BytesIO and add bytearray.resize
- Add bytearray.resize() method
- BytesIO: support keyword arg for initial_bytes
- BytesIO.seek: clamp negative positions to 0
- BytesIO.close: raise BufferError on active exports
- BytesIO.getbuffer: check closed state
- Set UnsupportedOperation.__module__ to "io"
2026-02-13 14:13:30 +09:00
CPython Developers
9924e2978a Update io from v3.14.3 2026-02-13 14:13:30 +09:00
Jeong, YunWon
190cecd7c8 [update_lib] _pyio deps 2026-02-13 14:00:00 +09:00
ShaharNaveh
96a78a9f43 Update test_long.py from 3.14.3 2026-02-13 13:55:05 +09:00
ShaharNaveh
e02e813bf8 Update _pylong.py from 3.14.3 2026-02-13 13:55:05 +09:00
ShaharNaveh
979b22f8d9 Update urllib from 3.14.3 2026-02-13 13:44:28 +09:00
ShaharNaveh
29133131fb Update test_functools.py from 3.14.3 2026-02-13 13:44:08 +09:00
ShaharNaveh
33921c2ac0 Update test_deque.py from 3.14.3 2026-02-13 13:43:46 +09:00
ShaharNaveh
8939cb059f Update test_future_stmt from 3.14.3 2026-02-13 13:43:29 +09:00
ShaharNaveh
44e1b22f4d Update test_positional_only_arg.py from 3.14.3 2026-02-13 13:43:18 +09:00
ShaharNaveh
87cf6848a5 Update test_funcattrs.py from 3.14.3 2026-02-13 13:43:04 +09:00
ShaharNaveh
4ab7c38c90 Update test_property.py from 3.14.3 2026-02-13 13:42:52 +09:00
ShaharNaveh
be43458579 Update test_sundry.py from 3.14.3 2026-02-13 13:42:38 +09:00
ShaharNaveh
d96c1f0a22 Update wave.py from 3.14.3 2026-02-13 13:42:22 +09:00
Jeong, YunWon
7f64acdd59 Merge pull request #7085 from youknowone/extcall
Fix dict unpacking order and improve error messages
2026-02-13 00:19:33 +09:00
Shahar Naveh
8459e9b053 fix miri ci (#7093) 2026-02-13 00:17:53 +09:00
Jeong, YunWon
8303c7a48b Add non-iterability guard, deduplicate dict flush and missing args format 2026-02-12 14:14:38 +09:00
Jeong, YunWon
cc8d9a2c53 Remove expectedFailure from test_bad_newobj_ex_args 2026-02-12 01:49:31 +09:00
Jeong, YunWon
542055580b fix 2026-02-12 01:01:35 +09:00
CPython Developers
b6d08fe371 Update test_unpack_ex from v3.14.2 2026-02-12 01:01:35 +09:00
CPython Developers
a144882948 Update test_extcall from v3.14.2 2026-02-12 01:01:35 +09:00
Jeong, YunWon
6e41e97468 Fix dict unpacking order and improve error messages
- Rewrite compile_dict to preserve insertion order with ** unpacking
- Fix function call error messages to include function name and
keyword-only argument counts
- Fix missing keyword-only argument error to list all missing args
- Fix starred expression error messages to match CPython
- Fix "cannot unpack non-iterable" error message
- Remove resolved expected failure markers in test_extcall and
test_unpack_ex
2026-02-12 01:01:35 +09:00
Jeong, YunWon
426019efc4 Fix annotation scope, deadlock, MRO, and HEAPTYPE issues (#7087)
* Fix annotation scope, deadlock, MRO, and HEAPTYPE issues

Annotation scope:
- Remove module-level annotation re-scan that created phantom
  sub_tables, breaking annotation closure for comprehensions
- Add async comprehension check in symbol table with
  is_in_async_context(); annotation/type-params scopes are
  always non-async
- Save/restore CompileContext in enter/exit_annotation_scope
  to reset in_async_scope

Deadlock prevention:
- Fix TypeVar/ParamSpec/TypeVarTuple __default__ and
  evaluate_default by cloning lock contents before acquiring
  a second lock or calling Python

Other fixes:
- Add HEAPTYPE flag to Generic for correct pickle behavior
- Guard heaptype_ext access in name_inner/set___name__/
  set___qualname__ with safe checks instead of unwrap
- Fix MRO error message to include base class names
- Add "format" to varnames in TypeAlias annotation scopes
- Fix single-element tuple repr to include trailing comma

* Unmark failing markers
2026-02-12 00:30:18 +09:00
Shahar Naveh
151a11ec36 Update ruff to 0.15.0 (#7086) 2026-02-12 00:11:11 +09:00
Jeong, YunWon
ba6d7b5404 Unmark failing markers 2026-02-11 18:38:10 +09:00
Jeong, YunWon
34180d8248 Fix annotation scope, deadlock, MRO, and HEAPTYPE issues
Annotation scope:
- Remove module-level annotation re-scan that created phantom
  sub_tables, breaking annotation closure for comprehensions
- Add async comprehension check in symbol table with
  is_in_async_context(); annotation/type-params scopes are
  always non-async
- Save/restore CompileContext in enter/exit_annotation_scope
  to reset in_async_scope

Deadlock prevention:
- Fix TypeVar/ParamSpec/TypeVarTuple __default__ and
  evaluate_default by cloning lock contents before acquiring
  a second lock or calling Python

Other fixes:
- Add HEAPTYPE flag to Generic for correct pickle behavior
- Guard heaptype_ext access in name_inner/set___name__/
  set___qualname__ with safe checks instead of unwrap
- Fix MRO error message to include base class names
- Add "format" to varnames in TypeAlias annotation scopes
- Fix single-element tuple repr to include trailing comma
2026-02-11 18:37:42 +09:00
Jeong, YunWon
0d1115464a Merge pull request #7078 from youknowone/typing
Implement more typing
2026-02-11 18:33:26 +09:00
Jeong, YunWon
bc35aa8f01 Merge pull request #7073 from youknowone/time
update test_time and implement more time module
2026-02-11 18:29:35 +09:00
ShaharNaveh
a9c98d2666 Update statistics.py from 3.14.3 2026-02-11 18:01:41 +09:00
Jeong, YunWon
fa59402def Merge pull request #7067 from youknowone/doctest
Update doctest,test_generators from v3.14.2 and fix generator bugs
2026-02-11 17:49:59 +09:00
Copilot
a9995a7d61 Sync test_abstract_numbers with CPython v3.14.3 (#7080) 2026-02-11 17:42:16 +09:00
Shahar Naveh
c904a91bef Update test_tabnanny.py from 3.14.3 (#7083) 2026-02-11 17:41:57 +09:00
Jeong, YunWon
5242dd42e1 Rename constevaluator_alloc to const_evaluator_alloc, add to cspell dict 2026-02-11 17:00:30 +09:00
Jeong, YunWon
6a6e3755c7 Propagate can_see_class_scope to annotation scopes in type param blocks
Annotation scopes now inherit can_see_class_scope from parent scopes
(not just direct Class parents), allowing annotations in generic
methods inside classes to access class variables via __classdict__.

Remove 3 expectedFailure markers from test_type_params.
2026-02-11 17:00:30 +09:00
Jeong, YunWon
c91f27c2fa Fix nonlocal type param check, __class_getitem__, __set_name__ note, sre module names
- Reject nonlocal binding for type parameters in symboltable
- Enable __class_getitem__ on memoryview, Template, Interpolation
- Fix __set_name__ error note to quote attribute name
- Set re.Match and re.Pattern module to "re" instead of "_sre"
- Migrate parking_lot::Mutex to PyMutex in typevar.rs
- Collapse nested if-let chains in typing_type_repr (clippy)
- Remove 5 expectedFailure markers from test files
2026-02-11 17:00:29 +09:00
Jeong, YunWon
d1e81225bc Add _ConstEvaluator, evaluate_* getters, format validation
- Implement _ConstEvaluator type in _typing module with STRING
  format support via typing_type_repr (port of _Py_typing_type_repr)
- Add evaluate_bound, evaluate_constraints, evaluate_default
  pygetset properties to TypeVar, ParamSpec, TypeVarTuple
- Emit format validation in evaluator scopes
  (compile_type_param_bound_or_default, TypeAlias value scopes)
  so evaluators raise NotImplementedError for unsupported formats
- Add non-default-after-default SyntaxError in scan_type_params
- Fix ParamSpec default_value to use Mutex for proper caching
- Fix TypeVar constructor: evaluate_constraints set to None
  instead of constraints tuple for eager-constructed TypeVars
- Pass format=1 (FORMAT_VALUE) to all lazy evaluator calls
- Remove 6 expectedFailure markers from test_type_params
2026-02-11 16:59:33 +09:00
CPython Developers
c4f23295bf Update test_time from v3.14.3 2026-02-11 16:57:51 +09:00
Shahar Naveh
a41d4c5029 Updated libs status show datetime utc (#7082) 2026-02-11 16:57:36 +09:00
Jeong, YunWon
d55a2261fa Use libc time functions on unix for time module
- Replace chrono-based gmtime/localtime/mktime/strftime/asctime/ctime
  with direct libc calls (gmtime_r, localtime_r, mktime, strftime)
  on unix, keeping chrono as fallback for non-unix platforms
- Add checked_tm_from_struct_time for struct_time field validation
- Accept None in gmtime/localtime/ctime (OptionalArg<Option<>>)
- Fix StructTimeData field order: tm_zone before tm_gmtoff
- Fix PyStructTime slot_new to accept optional dict argument
2026-02-11 16:54:13 +09:00
Jeong, YunWon
ad6e965ad3 apply tests 2026-02-11 16:50:23 +09:00
CPython Developers
cafde31502 Update test_generators from v3.14.2 2026-02-11 16:47:11 +09:00
CPython Developers
e616f250af Update doctest from v3.14.2 2026-02-11 16:47:03 +09:00
Jeong, YunWon
5c341efdf0 Implement generator/coroutine lifecycle, tracing, and error handling
- Add interactive REPL mode: auto-print expression results in single mode
- Implement Destructor for PyGenerator and PyCoroutine
- Add locals_dirty tracking and locals_to_fast() for frame sync
- Add per-line tracing with prev_line tracking in execution loop
- Fix gen_throw to close sub-iterator on GeneratorExit (gen_close_iter)
- Pass callable object as arg in c_call/c_return/c_exception trace events
- Distinguish [Errno] vs [WinError] for CRT vs Win32 API errors
- Fix tee thread safety with AtomicBool running flag
- Fix division error messages to match expected format
2026-02-11 16:46:36 +09:00
Jeong, YunWon
ccd3d4f964 Replace std::sync::LazyLock with common::lock::LazyLock (#7079) 2026-02-11 16:09:42 +09:00
Jeong, YunWon
c06cf56c60 Replace once_cell with std::sync::OnceLock/core::cell::OnceCell (#7077)
* Replace `once_cell` with `std::sync::OnceLock`/`core::cell::OnceCell`

- Replace `once_cell::sync::{Lazy, OnceCell}` with
  `std::sync::{LazyLock, OnceLock}`
- Replace `once_cell::unsync::{Lazy, OnceCell}` with
  `core::cell::{LazyCell, OnceCell}`
- Inline `get_or_try_init` at call sites (unstable in std as of 1.93)
- Replace `OnceCell::with_value()` with `OnceCell::from()` in codecs.rs
- Remove `once_cell` direct dependency from common and vm crates

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-11 11:08:16 +09:00
Jeong, YunWon
36ff461d65 Add import_ensure_initialized to import_module_level (#7076)
Wait for module initialization to complete when a module is
already in sys.modules but still being initialized by another
thread. Check __spec__._initializing and call
_lock_unlock_module to block until the import finishes.
2026-02-11 10:57:10 +09:00
Jeong, YunWon
6bfdfb1bea Upgrade typing from 3.14.2 and more impl (#7057)
* Implement TypeAliasType, type annotations, and genericalias fixes

- TypeAliasType: lazy value evaluation via closures, __module__,
  __parameters__, __iter__, evaluate_value, check_type_params,
  IMMUTABLETYPE flag, Hashable/AsMapping/Iterable traits
- TypeAliasType constructor: positional-or-keyword arg validation,
  duplicate/unexpected kwarg rejection
- type.__annotations__ setter: distinguish None assignment from deletion
- Annotation scope: name as __annotate__, format as positional-only,
  __conditional_annotations__ uses Cell for both load and store
- Compiler: proper TypeParams/TypeAlias scope with closures,
  find_ann covers match/try-except handlers
- symboltable: deduplicate TypeAlias value scope code
- GenericAlias repr: handle list args, avoid deadlock in repr_arg
  by cloning items before calling repr
- AST types: remove IMMUTABLETYPE (heap types, mutable)
- pymodule macro: preserve existing __module__ getset descriptors

* Update typing from v3.14.3

* Implement TypeAliasType, type annotations, and genericalias fixes

- TypeAliasType: lazy value evaluation via closures, __module__,
  __parameters__, __iter__, evaluate_value, check_type_params,
  IMMUTABLETYPE flag, Hashable/AsMapping/Iterable traits
- TypeAliasType constructor: positional-or-keyword arg validation,
  duplicate/unexpected kwarg rejection
- type.__annotations__ setter: distinguish None assignment from deletion
- Annotation scope: name as __annotate__, format as positional-only,
  __conditional_annotations__ uses Cell for both load and store
- Compiler: proper TypeParams/TypeAlias scope with closures,
  find_ann covers match/try-except handlers
- symboltable: deduplicate TypeAlias value scope code
- GenericAlias: implement gaiterobject (generic_alias_iterator),
  starred equality comparison, starred pickle via iterator reduce,
  split attr_exceptions/attr_blocked for correct __dir__,
  make_parameters/subs_parameters handle list/tuple args recursively,
  repr_arg indexed access for mutation safety
- AST types: remove IMMUTABLETYPE (heap types, mutable)
- pymodule macro: preserve existing __module__ getset descriptors

---------

Co-authored-by: CPython Developers <>
2026-02-11 09:39:04 +09:00
Shahar Naveh
2edab987fd Auto update lib status (#7074) 2026-02-11 01:48:50 +09:00
Jeong, YunWon
f594b0a400 Replace unsafe pointer cast with AtomicPtr in PyCode (#7063)
Add `source_path: AtomicPtr<PyStrInterned>` field to `PyCode`
for interior mutability, replacing the UB-inducing
`#[allow(invalid_reference_casting)]` + `write_volatile` pattern
in `update_code_filenames`. Use atomic load/store instead of a
mutex since the operation is a simple pointer swap on a 'static
reference. Update all read sites to use `source_path()` accessor.
2026-02-11 01:28:17 +09:00
Jeong, YunWon
65d54e8d51 Merge pull request #7071 from youknowone/memoryview
Update test_memoryview from v3.14.3 and impl count/index
2026-02-11 00:13:48 +09:00
Elmir
fde808e663 handle type annotations in nested functions correctly (#7072)
For example in the following code:

    def foo(x: int, y: float):
        def bar(q: int):
            return q
        pass

Make sure that `foo` type annotations are correctly propogated to
it's `__annotate__` and `__annotations__` attributes.

With this chage, we'll get:

    >>>>> foo.__annotations__
    {'x': <class 'int'>, 'y': <class 'float'>}

Previously annotations where 'lost', and we would get:

    >>>>> foo.__annotations__
    {}
2026-02-11 00:08:57 +09:00
Jeong, YunWon
b521f76ca4 impl more memory 2026-02-10 22:27:46 +09:00
CPython Developers
91b128a466 Update test_memoryview from v3.14.3 2026-02-10 22:27:46 +09:00
dependabot[bot]
23cf16a283 Bump psm from 0.1.29 to 0.1.30
Bumps [psm](https://github.com/rust-lang/stacker) from 0.1.29 to 0.1.30.
- [Commits](https://github.com/rust-lang/stacker/commits)

---
updated-dependencies:
- dependency-name: psm
  dependency-version: 0.1.30
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-10 22:25:09 +09:00
dependabot[bot]
ac5f77a9a8 Bump memchr from 2.7.6 to 2.8.0
Bumps [memchr](https://github.com/BurntSushi/memchr) from 2.7.6 to 2.8.0.
- [Commits](https://github.com/BurntSushi/memchr/compare/2.7.6...2.8.0)

---
updated-dependencies:
- dependency-name: memchr
  dependency-version: 2.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-10 22:23:59 +09:00
Jeong, YunWon
d79b41ba28 Merge pull request #7070 from ShaharNaveh/update-array
Update `test_array.py` from 3.14.3
2026-02-10 21:08:55 +09:00
ShaharNaveh
f73df6a102 Update test_json from 3.14.3 2026-02-10 21:00:40 +09:00
Jeong, YunWon
3bd061ef5a Merge pull request #7068 from ShaharNaveh/update-support-init
Update `support.__init__.py` from 3.14.3
2026-02-10 20:59:55 +09:00
ShaharNaveh
28ed23f7ca Update test_array.py from 3.14.3 2026-02-10 13:16:46 +02:00
ShaharNaveh
b6ebbfd365 impl array.clear 2026-02-10 12:58:29 +02:00
ShaharNaveh
4babbf3f97 Update test_support.py from 3.14.3 2026-02-10 11:45:49 +02:00
ShaharNaveh
c4e3a804cc Update test_descr.py from 3.14.3 2026-02-10 11:44:47 +02:00
ShaharNaveh
bb39d2e1ce Update support.__init__.py from 3.14.3 2026-02-10 11:40:38 +02:00
Jeong, YunWon
1a54267aa7 Merge pull request #7060 from youknowone/test_iter
Update test_errno,test_iter from v3.14.3
2026-02-10 00:50:54 +09:00
Jeong, YunWon
6f1edf3b26 Remove static cache for builtins iter/reversed reduce
- Replace static_cell! cached builtins_iter/builtins_reversed with
  per-call vm.builtins.get_attr lookups to support runtime builtins
  mutation (CPython issue #101765)
- Refactor PositionIterInternal::reduce to take func, active, and
  empty callbacks; resolve builtins outside the lock to prevent
  deadlock from reentrant iterator access
- Add __reduce__ and fix reentrant next() in PyCallableIterator
- Remove expectedFailure from test_reverse_iterator_picking and
  test_reduce_mutating_builtins_iter
2026-02-10 00:49:12 +09:00
CPython Developers
177837de6b Update test_iter from v3.14.3 2026-02-10 00:48:22 +09:00
CPython Developers
48d63a6dae Update test_errno from v3.14.3 2026-02-10 00:48:22 +09:00
Jeong, YunWon
c16f6f8b68 Fix signal handler after fork (#7012)
* temp regrtest save_env patch

* Refactor signal_handlers from Option to OnceCell

- Change `signal_handlers` type from `Option<Box<...>>` to
  `OnceCell<Box<...>>` so fork children can lazily initialize it
- Add `VirtualMachine::is_main_thread()` using runtime thread ID
  comparison instead of structural `signal_handlers.is_none()` check
- Initialize signal handlers in `py_os_after_fork_child()` via
  `get_or_init()` for workers that fork
- Use `get_or_init()` in `signal()` and `getsignal()` functions
- Remove `set_wakeup_fd(-1)` special-case workaround (d6d0303)
- Extract `signal::new_signal_handlers()` to deduplicate init expr
- Allow `getsignal()` from any thread (matches CPython behavior)
- Fix `set_wakeup_fd` error message to name the correct function
2026-02-10 00:38:46 +09:00
Copilot
20ad988585 Update copy module and test_copy from CPython v3.14.3 (#7062) 2026-02-10 00:05:15 +09:00
Jeong, YunWon
570d50c67f no_std for common, pylib, codegen (#7056)
* `std` feature for common

- Gate OS-dependent modules behind `#[cfg(feature = "std")]`
- Replace `std::f64` with `core::f64` in float_ops
- Replace `std::process::abort` with panic in refcount
- Remove `thread_local` from levenshtein (stack buffer)
- Split static_cell into threading/non_threading/no_std

* `std` for codegen

* `no_std` for pylib
2026-02-09 23:28:20 +09:00
Jeong, YunWon
c974b77127 [update_lib] fix hard_deps resolution and fix commit not to miss test data (#7058)
* [update_lib] fix hard_dep not to unclude other tests

* [update_lib] commit test data
2026-02-09 14:41:15 +09:00
Jeong, YunWon
dc2d235e59 Replace unsafe pointer cast with PyMutex in PyCode (#7055)
Add `source_path: PyMutex<&'static PyStrInterned>` field to
`PyCode` for interior mutability, replacing the UB-inducing
`#[allow(invalid_reference_casting)]` + `write_volatile` pattern
in `update_code_filenames`. Update all read sites across the
codebase to use the new `source_path()` accessor method.
2026-02-09 14:01:39 +09:00
CPython Developers
d1c19bef38 Update linecache from v3.14.3 2026-02-09 12:56:53 +09:00
Jeong, YunWon
d2a9937ad6 [update_lib] todo shows last updated date (#7053) 2026-02-09 09:39:01 +09:00
Jeong, YunWon
4daac232a4 no_std for doc, replace HashSet in codegen (#7054) 2026-02-09 08:14:53 +09:00
Jeong, YunWon
470bd5990b Fix test_import: import machinery, circular imports, and script shadowing (#7034)
* Fix test_import: import machinery and errors

- Emit IMPORT_FROM instead of LOAD_ATTR for `import a.b.c as m`
- Add "partially initialized module" error for circular imports
- Add "cannot access submodule" error for initializing submodules
- Implement script shadowing detection with "consider renaming" hint
  - Detect user scripts shadowing stdlib/third-party modules
  - Compute original sys.path[0] from sys.argv[0]
  - Check sys.stdlib_module_names for stdlib detection
  - Respect safe_path setting
- Implement _imp._fix_co_filename for code source_path rewriting
- Add data parameter to _imp.get_frozen_object with marshal deser
- Fix import_from: check __spec__.has_location before using origin
- Set ImportError.path attribute on import failures
- Fix import_star error messages for non-str __all__/__dict__ items
- Always call builtins.__import__ in import_inner

* Propagate __bool__ errors from fromlist in import

Previously, try_to_bool errors were silently swallowed via .ok(),
causing fromlist with broken __bool__ to default to false.
2026-02-09 01:40:26 +09:00
Jeong, YunWon
cf83008d33 no_std for wtf8, sre_engine, compiler-core, literal (#7051)
* `no_std` for wtf8

* `no_std` for sre_engine, compiler-core, literal
2026-02-09 01:04:54 +09:00
Shahar Naveh
ea352ccdae Make inner oparg values private (#7050) 2026-02-08 14:56:56 +00: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
5dabad6702 reason inside #[allow] (#7049) 2026-02-08 13:11:50 +00:00
Shahar Naveh
23a89663e0 Update tomllib from 3.14.3 (#7048) 2026-02-08 12:51:38 +00:00
Shahar Naveh
c8b4d6308f Newtype for LoadAttr oparg (#7047) 2026-02-08 11:47:14 +00:00
ShaharNaveh
d54cf8f12e Update difflib.py from 3.14.3 2026-02-08 20:36:35 +09:00
ShaharNaveh
32b57785c3 Update dataclasses.py from 3.14.3 2026-02-08 19:38:26 +09:00
Jeong, YunWon
d2d8eeea2f Add _types module (#6807)
* _types

* builtin_function_or_method

* PyCapsule

* function_or_method

* Remove expectedFailure for test_builtin_function and test_join_nondaemon_on_shutdown
2026-02-08 19:17:03 +09:00
Jeong, YunWon
07fc6ee3c7 no_std clippy (#7043) 2026-02-08 16:49:18 +09:00
ShaharNaveh
c29d2d9a1c Update get{opt,pass}.py from 3.14.3 2026-02-08 16:35:56 +09:00
Shahar Naveh
bbe5412aea Update test_{binop,contains}.py from 3.14.3 (#7038) 2026-02-08 10:00:50 +09:00
Shahar Naveh
87289fd904 Update tests with deprecated get_c_recursion_limit (#7039) 2026-02-08 09:59:14 +09:00
ShaharNaveh
bff70f957f Remove redundunt test_pickle tests 2026-02-08 08:54:38 +09:00
ShaharNaveh
c00ccf7a6c Update test_sort.py from 3.14.3 2026-02-08 08:33:45 +09:00
dependabot[bot]
ae260c13fa Bump webpack from 5.94.0 to 5.104.1 in /wasm/example (#7036)
Bumps [webpack](https://github.com/webpack/webpack) from 5.94.0 to 5.104.1.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Changelog](https://github.com/webpack/webpack/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack/compare/v5.94.0...v5.104.1)

---
updated-dependencies:
- dependency-name: webpack
  dependency-version: 5.104.1
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-08 00:10:53 +09:00
Shahar Naveh
47f54f19c5 test__all__.py (#7037) 2026-02-07 22:42:10 +09:00
Shahar Naveh
f817ab8d07 Bytecode oparg optimization (#7032)
* Generate optimized oparg enums

* No need to match on 255

* Remove `num_enum` crate from `compiler-core`

* Update `Cargo.lock`

* macro fmt

* Rename macro vars

* Match without `,`

* Support alternative values

* Fix alternatives

* Improve docs

* Add const assert

* Don't use `as u32`

* Make only ComparisonOperator unoptimized

* Fix test

* cleanup

* All opargs are optimized

* Remove comment
2026-02-07 19:15:16 +09:00
Shahar Naveh
3d283bb91f Update some libs&tests to 3.14.3 (#7006)
* Update some libs&tests to 3.14.3

* Update argparse from 3.14.3

* Update inspect

* Update `configparser.py` from 3.14.3
2026-02-07 19:09:42 +09:00
CPython Developers
75137f7cdd Update test_import from v3.14.3 2026-02-07 15:13:43 +09:00
Jeong, YunWon
6b870d62ad Fix traceback, syntax errors, and exception handling (#7015)
* Update codeop from v3.14.3

* Fix traceback, syntax errors, and exception handling

- Improve unclosed bracket detection with "'(' was never closed" message
- Fix IndentationError location to point to end of line
- Implement frame.clear() with proper checks for executing/suspended frames
- Fix exception context chaining for propagated exceptions
- Add traceback.__dir__() and prevent tb_next deletion
- Fix subscript operation source range restoration in compiler
- Change "duplicate parameter" to "duplicate argument" error message
- Refactor duplicate code in asyncgenerator.rs and frame.rs

---------

Co-authored-by: CPython Developers <>
2026-02-07 13:41:45 +09:00
Jeong, YunWon
234bdda40d Refactor warn.rs and _warnings module (#7023)
- Add already_warned() with filter version tracking
- Add type validation for _defaultaction and _onceregistry
- Use direct function names for _warnings pyattr/pyfunction
- Route stdlib::warnings::warn through warn::warn
- Remove spurious EncodingWarning from TextIOWrapper
- Clean up comments and simplify check_matched error handling
- Remove expectedFailure from 3 passing test_warnings tests
2026-02-06 20:46:51 +09:00
Jeong, YunWon
8127000080 Impl more codecs and _codecs._unregister_error (#7025)
- Rewrite _pycodecs.py: escape_decode, charmap_decode,
  unicode_escape_decode/encode, raw_unicode_escape_decode/encode
- Add _codecs._unregister_error with built-in handler protection
  and null byte/surrogate validation
- Normalize encoding name in register_manual
- Add codec error notes via add_note
- Fix cp65001 encoding constant in StandardEncoding::parse
- Remove 35 expectedFailure markers from test_codecs,
  test_pickle, test_datetime, pickletools
2026-02-06 20:37:18 +09:00
dependabot[bot]
ea6ab124f4 Bump x509-parser from 0.18.0 to 0.18.1 (#7029)
Bumps [x509-parser](https://github.com/rusticata/x509-parser) from 0.18.0 to 0.18.1.
- [Changelog](https://github.com/rusticata/x509-parser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rusticata/x509-parser/commits)

---
updated-dependencies:
- dependency-name: x509-parser
  dependency-version: 0.18.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-06 18:34:59 +09:00
Jeong, YunWon
6d29b7f684 Refactor _ast module for clarity (#7031)
- Extract singleton_node_to_object() helper for operator/context nodes
- Rename PY_COMPILE_FLAG_AST_ONLY to PY_CF_ONLY_AST
- Rename populate_match_args_and_attributes to populate_repr
- Set _attributes in impl_base_node! no-args variant
- Simplify ast_reduce with .is_some() instead of drop(value)
- Remove _ prefix from used parameters across ast/ files
- Fix slot_new comment to explain why slot_init is called
2026-02-06 17:45:11 +09:00
dependabot[bot]
9596ae3b76 Bump webpki-roots from 1.0.5 to 1.0.6 in the webpki-root group
Bumps the webpki-root group with 1 update: [webpki-roots](https://github.com/rustls/webpki-roots).


Updates `webpki-roots` from 1.0.5 to 1.0.6
- [Release notes](https://github.com/rustls/webpki-roots/releases)
- [Commits](https://github.com/rustls/webpki-roots/compare/v/1.0.5...v/1.0.6)

---
updated-dependencies:
- dependency-name: webpki-roots
  dependency-version: 1.0.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: webpki-root
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-06 17:31:46 +09:00
dependabot[bot]
1d5857bf5a Bump criterion from 0.8.1 to 0.8.2 in the criterion group
Bumps the criterion group with 1 update: [criterion](https://github.com/criterion-rs/criterion.rs).


Updates `criterion` from 0.8.1 to 0.8.2
- [Release notes](https://github.com/criterion-rs/criterion.rs/releases)
- [Changelog](https://github.com/criterion-rs/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/criterion-rs/criterion.rs/compare/criterion-v0.8.1...criterion-v0.8.2)

---
updated-dependencies:
- dependency-name: criterion
  dependency-version: 0.8.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: criterion
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-06 17:31:33 +09:00
Jeong, YunWon
4f14738a74 [AGENTS] guideline for comments 2026-02-06 14:30:15 +09:00
Padraic Fanning
f9686296a9 Add dependency groups to dependabot.yml 2026-02-06 14:20:31 +09:00
dependabot[bot]
40d418e2fc Bump webpack from 5.98.0 to 5.105.0 in /wasm/demo
Bumps [webpack](https://github.com/webpack/webpack) from 5.98.0 to 5.105.0.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Changelog](https://github.com/webpack/webpack/blob/main/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack/compare/v5.98.0...v5.105.0)

---
updated-dependencies:
- dependency-name: webpack
  dependency-version: 5.105.0
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-06 12:08:41 +09:00
github-actions[bot]
008ec892c8 Update doc DB for CPython 3.14.3 2026-02-06 12:08:22 +09:00
CPython Developers
951a97e32d Update encodings from v3.14.3 2026-02-06 12:05:17 +09:00
Jeong, YunWon
a49ab1911c [doc] fix workflow (#7021) 2026-02-06 11:41:08 +09:00
dependabot[bot]
b993312365 Bump cranelift-module from 0.128.1 to 0.128.2 (#6992)
* Bump cranelift-module from 0.128.1 to 0.128.2

Bumps [cranelift-module](https://github.com/bytecodealliance/wasmtime) from 0.128.1 to 0.128.2.
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift-module
  dependency-version: 0.128.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Upgrade all cranelift-* packages to 0.128.3 in Cargo.toml (#7017)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2026-02-06 11:39:50 +09:00
Jeong, YunWon
ba462e1223 [AGNETS.md] guide control flow (#7018) 2026-02-06 09:31:55 +09:00
Jeong, YunWon
1e1b423fc0 Merge pull request #6997 from youknowone/test_io
Better codecs and fix lots of test_io and other expectedFailures
2026-02-06 09:04:47 +09:00
dependabot[bot]
ef077319c8 Bump time from 0.3.46 to 0.3.47 (#7014)
Bumps [time](https://github.com/time-rs/time) from 0.3.46 to 0.3.47.
- [Release notes](https://github.com/time-rs/time/releases)
- [Changelog](https://github.com/time-rs/time/blob/main/CHANGELOG.md)
- [Commits](https://github.com/time-rs/time/compare/v0.3.46...v0.3.47)

---
updated-dependencies:
- dependency-name: time
  dependency-version: 0.3.47
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-06 09:00:59 +09:00
Shahar Naveh
956f471013 Use num_enum crate for oparg types (#6980)
* Use `num_enum` crate for oparg types

* Fix doctest

* Make opargs `#[repr(u8)]`

* BuildSliceArgCount optimized
2026-02-06 09:00:38 +09:00
Jeong, YunWon
19db8d0b9f Merge pull request #7008 from youknowone/warnings 2026-02-06 07:45:48 +09:00
CPython Developers
7ccab4a4c8 Update traceback from v3.14.3 2026-02-06 07:45:17 +09:00
ShaharNaveh
c3212e7cd0 Update pprint.py from 3.14.3 2026-02-06 01:14:55 +09:00
CPython Developers
cc23a67493 Update test_dict from v3.14.3 2026-02-06 00:35:00 +09:00
Jeong, YunWon
b880c33a8b Move pickletester.py to the correct place (#7003)
* Move `pickletester.py` to the correct place

* Mark failing tests

* Update `test_pickle.py` from 3.14.3
2026-02-06 00:21:15 +09:00
Jeong, YunWon
6e09d1b123 win codecs 2026-02-06 00:15:18 +09:00
Jeong, YunWon
258ac74384 fix io 2026-02-06 00:15:18 +09:00
CPython Developers
e948314a3e Update test_io from v3.14.3 2026-02-06 00:15:18 +09:00
Jeong, YunWon
afea16569b Fix test_io expectedFailures 2026-02-06 00:15:18 +09:00
Jeong, YunWon
2e62cac72b Implement more warnings 2026-02-05 23:50:08 +09:00
Jeong, YunWon
c0af6eb5c0 skip flaky test_threaded_weak_key_dict_copy (#7010) 2026-02-05 23:47:09 +09:00
fanninpm
2da6c34547 RustPython version to 3.14.3 (#6999)
* RustPython version to 3.14.3

* Refactor version number to variable

* Fix CPython clone version statement

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-02-05 23:42:33 +09:00
Jeong, YunWon
6de6a92717 Merge pull request #7001 from youknowone/annotationlib
Add test_annotationlib to v3.14.2 and fix related bugs
2026-02-05 23:39:47 +09:00
Jeong, YunWon
cdb7b0d5ca align overlapped to CPython 3.14.2 (#7005) 2026-02-05 23:38:35 +09:00
ShaharNaveh
906113f499 Merge remote-tracking branch 'upstream/main' into move-pickletester 2026-02-05 15:52:30 +02:00
ShaharNaveh
d4c268c834 Update test_pickle.py from 3.14.3 2026-02-05 15:52:00 +02:00
Jeong, YunWon
535638e1e7 Fix annotationlib parsing 2026-02-05 22:46:23 +09:00
CPython Developers
2fac506b35 Update warnings from v3.14.2 2026-02-05 21:54:56 +09:00
ShaharNaveh
00ea4636a1 Mark failing tests 2026-02-05 14:19:41 +02:00
Shahar Naveh
5b7db1d2d2 Newtype LoadSuperAttr oparg (#7002) 2026-02-05 21:14:38 +09:00
ShaharNaveh
0258e8d10a Move pickletester.py to the correct place 2026-02-05 13:32:40 +02:00
Jeong, YunWon
d7c259c8c9 Update list-related CPython tests to v3.14.2 (#7000) 2026-02-05 20:30:17 +09:00
CPython Developers
144dc7e5e2 Update annotationlib from v3.14.2 2026-02-05 19:31:58 +09:00
Shahar Naveh
e2ee2067f8 Update pickle.py from 3.14.2 (#6982)
* Update `_compat_pickle.py` from 3.14.2

* Update `pickle.py` from 3.14.2

* Update pickletools and tests

* Update all other pickle related files

* Make `test_extcall` to use modified doctest checker
2026-02-05 19:27:10 +09:00
Jeong, YunWon
684e880689 Implement more ast features (#6986) 2026-02-05 16:20:22 +09:00
Jeong, YunWon
0919b2cb3d command /apple-container (#6998) 2026-02-05 10:20:48 +09:00
Jeong, YunWon
f260677dbd Merge pull request #6996 from youknowone/import
Update importlib from 3.14.2
2026-02-05 08:12:43 +09:00
Jeong, YunWon
bcc5cf30ac impl more importlib 2026-02-05 00:21:34 +09:00
CPython Developers
afdf8cefe8 Update importlib from v3.14.2 2026-02-05 00:21:34 +09:00
Jeong, YunWon
648223ade2 non-code migration 2026-02-05 00:21:34 +09:00
Elmir
ffc4622896 support | operation between typing.Union and strings (#6983)
* remove duplicated _call_typing_func_object() functions

Move _call_typing_func_object() code to
stdlib::typing::call_typing_func_object().
Use that function everywhere.

* support | operation between typing.Union and strings

Adds support for performing '|' operation between Union objects and
strings, e.g. forward type references.

For example following code:

    from typing import Union

    U1 = Union[int, str]
    U1 | "float"

The result of the operation above becomes:

   int | str | ForwardRef('float')
2026-02-04 23:49:36 +09:00
ShaharNaveh
a037bda44b Update queue from 3.14.2 2026-02-04 18:32:45 +09:00
Jeong, YunWon
0dcc975304 Add GC infrastructure: object tracking, tp_clear, and helper methods (#6994) 2026-02-04 18:29:09 +09:00
Jeong, YunWon
5662fa0751 Align winapi with CPython behavior (#6988) 2026-02-04 15:02:21 +09:00
dependabot[bot]
f709386ead Bump flate2 from 1.1.8 to 1.1.9 (#6991)
* Bump flate2 from 1.1.8 to 1.1.9

Bumps [flate2](https://github.com/rust-lang/flate2-rs) from 1.1.8 to 1.1.9.
- [Release notes](https://github.com/rust-lang/flate2-rs/releases)
- [Commits](https://github.com/rust-lang/flate2-rs/compare/1.1.8...1.1.9)

---
updated-dependencies:
- dependency-name: flate2
  dependency-version: 1.1.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...
2026-02-04 14:30:59 +09:00
Jeong, YunWon
e9c6617687 Merge pull request #6985 from youknowone/subprocess
Update subprocess from v3.14.2
2026-02-04 13:17:14 +09:00
dependabot[bot]
5e0fb7a6ee Bump bytes from 1.11.0 to 1.11.1 (#6987)
* Bump bytes from 1.11.0 to 1.11.1

Bumps [bytes](https://github.com/tokio-rs/bytes) from 1.11.0 to 1.11.1.
- [Release notes](https://github.com/tokio-rs/bytes/releases)
- [Changelog](https://github.com/tokio-rs/bytes/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tokio-rs/bytes/compare/v1.11.0...v1.11.1)

---
updated-dependencies:
- dependency-name: bytes
  dependency-version: 1.11.1
  dependency-type: indirect
...
2026-02-04 13:07:51 +09:00
Jeong, YunWon
2c417d5bb1 Fix Context.new_bytes (#6989) 2026-02-04 13:07:16 +09:00
CPython Developers
79c428e465 Update subprocess from v3.14.2 2026-02-04 11:16:15 +09:00
Jeong, YunWon
e56705455a Remove _use_vfork 2026-02-04 11:15:58 +09:00
Jeong, YunWon
c045593e4e impl more nt (#6984)
* mpl new features

* windows encodings

* impl nt functions

* revert

* codecs

* fix codecs
2026-02-04 09:53:02 +09:00
Jeong, YunWon
9f0cd323b6 Merge pull request #6958 from youknowone/os-posix
Update os from v3.14.2 and fix nt,posix,_os
2026-02-03 23:00:25 +09:00
Jeong, YunWon
674d7dbb3a rework SchedParam 2026-02-03 22:10:31 +09:00
Jeong, YunWon
c0f3a09c2b more windows impl 2026-02-03 22:10:31 +09:00
Jeong, YunWon
cb2be65a8b fix timeout 2026-02-03 22:10:31 +09:00
Jeong, YunWon
9c29b0c411 Fix windows link 2026-02-03 22:10:31 +09:00
CPython Developers
dd6e947122 Update os from v3.14.2 2026-02-03 22:10:31 +09:00
CPython Developers
ac1dcf7d4b Update test_posix from v3.14.2 2026-02-03 22:10:31 +09:00
Jeong, YunWon
f939a06aa9 fix durartion to round 2026-02-03 22:10:31 +09:00
Jeong, YunWon
8d07c45483 Populate _field_types with real type objects (#6981)
- Add FieldType enum and FIELD_TYPES static table mapping all
  AST node classes to their ASDL field types
- Resolve markers to real Python type objects (GenericAlias,
  Union, plain types) at module init in populate_field_types()
- Set class-level None defaults for optional fields
- Replace hardcoded LIST_FIELDS and class-name checks in
  slot_init with _field_types-based lookup
- Add expr_context default to Load(), fix ImportFrom.level
  default (now None instead of 0)
- Fix __class_getitem__ None check, compile() formatting
- Remove 14 @expectedFailure decorators from test_ast
2026-02-03 22:05:05 +09:00
Shahar Naveh
27d70fd58e Update test_builtin.py from 3.14.2 (#6979)
* Update `test_builtin.py` from 3.14.2

* Mark haning/segfault tests

* Patch failing tests
2026-02-03 21:55:55 +09:00
Jeong, YunWon
f71fe9bf3a Add GC infrastructure: tracking bits, tp_clear (#6977)
GC bit operations (_PyObject_GC_TRACK/UNTRACK equivalent):
- Add set_gc_bit() helper for atomic GC bit manipulation
- Add set_gc_tracked() / clear_gc_tracked() methods
- Update is_gc_tracked() to use GcBits::TRACKED flag
- Call set_gc_tracked() in track_object()
- Call clear_gc_tracked() for static types (they are immortal)

tp_clear infrastructure (for breaking reference cycles):
- Add try_clear_obj() function to call payload's try_clear
- Add clear field to PyObjVTable
- Add clear() method to PyType's Traverse impl
2026-02-03 20:00:34 +09:00
Jeong, YunWon
023b3b261d Add __replace__ and fix __reduce__ for structseq (#6978)
* Add __replace__ and fix __reduce__ for structseq

- Add __replace__ method to PyStructSequence trait
- Move __reduce__ from #[pymethod] to extend_pyclass with
  contains_key guard, allowing per-type overrides
- Fix repr: remove trailing comma for single-field sequences

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-03 19:09:47 +09:00
Jeong, YunWon
477e20a7a9 Support #[cfg] in with (#6975) 2026-02-03 18:55:59 +09:00
Jeong, YunWon
d6aab01424 Improve object traversal for heap types and mro (#6976)
- Fix heap type instance traversal to include type reference
  (enables correct cycle detection for instance ↔ type references)
- Enable mro traversal in PyType (was previously disabled)
2026-02-03 17:54:11 +09:00
Jeong, YunWon
182157291a Merge pull request #6961 from youknowone/unparse
Update _ast_unparse and fix unparse, type_comments
2026-02-03 15:41:01 +09:00
github-actions[bot]
9e7faba7f3 Auto-format: cargo fmt --all 2026-02-03 05:59:58 +00:00
Jeong, YunWon
00cdb307e3 Fix AST field defaults and compile() type check
- Extract empty_arguments_object helper from expression.rs
- Fix LIST_FIELDS ambiguity: "args" and "body" have different
  ASDL types per node (e.g. Lambda.args is `arguments`, not
  `expr*`; Lambda.body is `expr`, not `stmt*`)
- Replace class name string comparison in compile() with
  fast_isinstance to accept AST subclasses
2026-02-03 14:58:43 +09:00
Jeong, YunWon
ff49bfe3a7 mark ast & test_genericalias 2026-02-03 14:16:10 +09:00
CPython Developers
69c19f7cd1 Update _ast_unparse from v3.14.2 2026-02-03 14:16:10 +09:00
Jeong, YunWon
63bbb3c804 fix ast fields including type_comments 2026-02-03 14:16:10 +09:00
Jeong, YunWon
1876ac88e0 Fix compiler panics 2026-02-03 14:16:10 +09:00
Jeong, YunWon
0da5931353 fix unparse 2026-02-03 14:16:10 +09:00
Jeong, YunWon
400696c0fd --exclude rustpython-venvlauncher 2026-02-03 14:16:10 +09:00
Noa
5bf13e8642 Switch to Cell::update, slice::{split_first_chunk,split_off}, where appropriate (#6974)
* Use Cell::update, slice::{split_first_chunk,split_off}

* Use more array -> slice methods
2026-02-03 13:45:03 +09:00
Jeong, YunWon
ec34befc3c Merge pull request #6949 from youknowone/faulthandler
Update faulthandler to 3.14.2
2026-02-03 13:43:25 +09:00
Jeong, YunWon
cdadde55ef Update faulthandler to match CPython 3.14.2
- Rewrite faulthandler with live frame walking via
  Frame.previous AtomicPtr chain and thread-local
  CURRENT_FRAME (AtomicPtr) instead of frame snapshots
- Add signal-safe traceback dumping (dump_live_frames,
  dump_frame_from_raw) walking the Frame.previous chain
- Add safe_truncate/dump_ascii for UTF-8 safe string
  truncation in signal handlers
- Refactor write_thread_id to accept thread_id parameter
- Add SA_RESTART for user signal registration, SA_NODEFER
  only when chaining
- Save/restore errno in faulthandler_user_signal
- Add signal re-entrancy guard in trigger_signals to
  prevent recursive handler invocation
- Add thread frame tracking (push/pop/cleanup/reinit)
  with force_unlock fallback for post-fork recovery
- Remove expectedFailure markers for now-passing tests
2026-02-03 13:41:58 +09:00
CPython Developers
b90530cb87 Update test_faulthandler from v3.14.2 2026-02-03 13:41:15 +09:00
dependabot[bot]
169a422ade Bump pyo3 from 0.27.2 to 0.28.0 (#6966)
* Bump pyo3 from 0.27.2 to 0.28.0

Bumps [pyo3](https://github.com/pyo3/pyo3) from 0.27.2 to 0.28.0.
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pyo3/pyo3/compare/v0.27.2...v0.28.0)

---
updated-dependencies:
- dependency-name: pyo3
  dependency-version: 0.28.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...
2026-02-03 13:33:25 +09:00
dependabot[bot]
fda12b2fce Bump malachite-base from 0.9.0 to 0.9.1 (#6965)
* Bump malachite-base from 0.9.0 to 0.9.1

Bumps [malachite-base](https://github.com/mhogrefe/malachite) from 0.9.0 to 0.9.1.
- [Release notes](https://github.com/mhogrefe/malachite/releases)
- [Commits](https://github.com/mhogrefe/malachite/compare/v0.9.0...v0.9.1)

---
updated-dependencies:
- dependency-name: malachite-base
  dependency-version: 0.9.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Align all malachite dependencies to version 0.9.1 (#6970)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2026-02-03 09:42:26 +09:00
dependabot[bot]
20a58cbe3e Bump astral-sh/ruff-action from 3.5.1 to 3.6.1 (#6969)
Bumps [astral-sh/ruff-action](https://github.com/astral-sh/ruff-action) from 3.5.1 to 3.6.1.
- [Release notes](https://github.com/astral-sh/ruff-action/releases)
- [Commits](57714a7c8a...4919ec5cf1)

---
updated-dependencies:
- dependency-name: astral-sh/ruff-action
  dependency-version: 3.6.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-03 08:17:01 +09:00
Jeong, YunWon
0a39c66817 skip fork test (#6964) 2026-02-02 17:26:31 +09:00
Jeong, YunWon
2f034130b7 [update_lib] auto-mark original contents recovery (#6960) 2026-02-02 16:03:26 +09:00
Jeong, YunWon
f7b2660882 Fix test_asyncio for windows (#6959) 2026-02-02 15:58:16 +09:00
Jeong, YunWon
c6499797ea AGENTS.md 2026-02-02 15:57:36 +09:00
CPython Developers
15efc4a808 Update uuid from v3.14.2-288-g06f9c8ca1c 2026-02-02 14:01:59 +09:00
Jeong, YunWon
babc3c634f Make auto-mark output deterministic and fix blank line leak (#6957)
* Make auto-mark output deterministic and fix blank line leak

Sort set iteration in build_patches and dict iteration in
_iter_patch_lines Phase 2 so expectedFailure markers are
always added in alphabetical order.

Include preceding blank line in _method_removal_range so
removing a super-call override doesn't leave behind the
blank line that was added with the method.

* deps code

* auto-mark handles crash better

* Auto-format: ruff format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-02 13:53:01 +09:00
Jeong, YunWon
100b870175 Implement UTF-32 encode/decode and fix UTF-16 empty encode
- Add UTF-32, UTF-32-LE, UTF-32-BE encode/decode in _pycodecs.py
- Register utf_32 codec functions in codecs.rs via delegate_pycodecs
- Fix PyUnicode_EncodeUTF16 returning "" instead of [] for empty input
- Remove resolved expectedFailure decorators in test_codecs.py
- Add failure reasons to remaining expectedFailure comments
2026-02-02 12:50:34 +09:00
CPython Developers
db347b344d Update tabnanny from v3.14.2-288-g06f9c8ca1c 2026-02-02 11:51:53 +09:00
Jeong, YunWon
95624ce818 Merge pull request #6956 from fanninpm/3.14-socket
Update `socket` from v3.14.2
2026-02-02 11:32:39 +09:00
Jeong, YunWon
4541cbab72 Merge pull request #6954 from fanninpm/3.14-imaplib 2026-02-02 11:31:03 +09:00
CPython Developers
453ff6dc98 Update test_runpy from v3.14.2-288-g06f9c8ca1c 2026-02-02 10:45:01 +09:00
Padraic Fanning
92a5cf0ac8 Mark erroring tests 2026-02-01 20:27:22 -05:00
CPython Developers
02537b56fd Update socket from v3.14.2-288-g06f9c8ca1c 2026-02-01 20:23:50 -05:00
Jeong, YunWon
7004502951 dealloc and finalize_modules (#6934)
* rewrite finalize_modules with phased algorithm

Replace the absence of module finalization during interpreter shutdown
with a 5-phase algorithm matching pylifecycle.c finalize_modules():

1. Set special sys attributes to None, restore stdio
2. Set all sys.modules values to None, collect module dicts
3. Clear sys.modules dict
4. Clear module dicts in reverse import order (2-pass _PyModule_ClearDict)
5. Clear sys and builtins dicts last

This ensures __del__ methods are called during shutdown and modules are
cleaned up in reverse import order without hardcoded module names.

* dealloc the rigth way

* fix finalize_modules: only clear __main__ dict, mark daemon thread tests as expected failure

Without GC, clearing all module dicts during finalization causes __del__
handlers to fail (globals are None). Restrict Phase 4 to only clear
__main__ dict — other modules' globals stay intact for their __del__
handlers.

Mark test_daemon_threads_shutdown_{stdout,stderr}_deadlock as expected
failures — without GC+GIL, finalize_modules clears __main__ globals
while daemon threads are still running.

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

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-02 10:10:58 +09:00
CPython Developers
52d23158ed Update test_asyncgen from v3.14.2 2026-02-02 10:03:42 +09:00
Jeong, YunWon
7f46112984 Merge pull request #6951 from fanninpm/3.14-code
Update `code` from v3.14.2
2026-02-02 09:58:38 +09:00
Padraic Fanning
359920f749 Mark erroring test(s) 2026-02-01 19:45:06 -05:00
CPython Developers
a8e93bd8b1 Update imaplib from v3.14.2-288-g06f9c8ca1c 2026-02-01 19:40:43 -05:00
CPython Developers
1079161270 Update test_signal from v3.14.2-288-g06f9c8ca1c 2026-02-02 09:09:35 +09:00
CPython Developers
7ec1f33b60 Update ftplib from v3.14.2-288-g06f9c8ca1c 2026-02-02 09:09:19 +09:00
Padraic Fanning
26a8ef9370 Mark failing tests 2026-02-01 18:57:43 -05:00
CPython Developers
1022eeebdd Update test_code_module from v3.14.2-288-g06f9c8ca1c 2026-02-01 18:55:40 -05:00
CPython Developers
f26ec68657 Update code from v3.14.2-288-g06f9c8ca1c 2026-02-01 18:55:19 -05:00
Jeong, YunWon
ab6114d5a2 Merge pull request #6942 from youknowone/os-fix
posix.link, termios.error, warn() error, closefd=False for std in/out
2026-02-02 08:11:46 +09:00
Jeong, YunWon
019e754055 Fix __set_name__ error handling to match Python 3.12+ (#6937)
Changed type.rs to add notes to original exceptions instead of
wrapping them in RuntimeError, following PEP 678 (gh-77757).

This allows enum.py's exception handling to work correctly when
super().__new__() is misused in Enum subclasses, enabling the
proper TypeError to propagate instead of being hidden behind
a RuntimeError wrapper.

Fixes test_bad_new_super test case.
2026-02-02 08:11:26 +09:00
CPython Developers
d767b5fce6 Update shlex from v3.14.2-288-g06f9c8ca1c 2026-02-02 08:10:15 +09:00
Jeong, YunWon
89dbd42da2 Merge pull request #6946 from fanninpm/3.14-test_tstring
Update `test_tstring` from v3.14.2
2026-02-02 08:09:48 +09:00
Jeong, YunWon
d46a3b4ca9 Merge pull request #6945 from fanninpm/3.14-test_unpack_ex
Update `test_unpack_ex` from v3.14.2
2026-02-02 08:09:11 +09:00
CPython Developers
4ef6120c01 Update test_threadsignals from v3.14.2-288-g06f9c8ca1c 2026-02-02 08:08:29 +09:00
Jeong, YunWon
d1b55f584e Merge pull request #6902 from youknowone/asyncio
Update asyncio to 3.14.2
2026-02-02 08:04:52 +09:00
Padraic Fanning
491d230dec Make test_tstring platform-independent 2026-02-01 15:08:10 -05:00
Padraic Fanning
946075fe12 Mark failing tests 2026-02-01 15:06:33 -05:00
CPython Developers
10d7498c14 Update test_tstring from v3.14.2-288-g06f9c8ca1c 2026-02-01 15:03:06 -05:00
Padraic Fanning
b805008510 Make test_unpack_ex platform-independent 2026-02-01 14:38:26 -05:00
Padraic Fanning
784e203b93 Mark failing examples
This caused me to revise the custom output checker so it can handle
other option flags.
2026-02-01 14:35:48 -05:00
CPython Developers
6f490d2481 Update test_unpack_ex from v3.14.2-288-g06f9c8ca1c 2026-02-01 14:21:52 -05:00
Jeong, YunWon
d8e582ef6e _locale.localeconv (#6941) 2026-02-02 02:02:12 +09:00
Jeong, YunWon
1132f66325 Set closefd=false for stdio file objects in VM init
- Prevent closing underlying fd when stdio wrappers are dropped
- Remove expectedFailure from test_fdopen in test_os.py
2026-02-02 01:57:03 +09:00
Jeong, YunWon
fce2d7824f Propagate errors from warnings.warn() calls 2026-02-02 01:55:22 +09:00
Jeong, YunWon
188d438e00 Use new_os_subtype_error for termios error construction
- Replace manual exception creation with new_os_subtype_error in termios
- Remove redundant .to_owned() calls in os.link() error messages
2026-02-02 01:54:58 +09:00
Jeong, YunWon
24b6f48841 Add follow_symlinks support to os.link()
- Use linkat() with AT_SYMLINK_FOLLOW on Unix
- Raise NotImplementedError on non-Unix when follow_symlinks=False
- Register link in supports_follow_symlinks
2026-02-02 01:53:46 +09:00
Jeong, YunWon
5e732c5e2a Fix wasip2 build (#6935) 2026-02-02 01:26:17 +09:00
CPython Developers
5997507216 Update ast from v3.14.2 2026-02-02 01:20:23 +09:00
Jeong, YunWon
68ebb61f7b fix: Include hard_deps in git commit (#6940)
Bug: update_lib quick ast was not committing _ast_unparse.py
because git_commit() only added lib_path and test_paths,
but not hard_deps.

Fixed by:
- Add hard_deps parameter to git_commit()
- Collect hard_deps from DEPENDENCIES in main()
- Add hard_deps to paths_to_add in git_commit()
2026-02-02 00:47:29 +09:00
Jeong, YunWon
7258a4ae92 generator is borrowed 2026-02-02 00:43:07 +09:00
Jeong, YunWon
80929f44d4 PyAtomicBorrow 2026-02-02 00:43:07 +09:00
Jeong, YunWon
abd1daac83 Fix asyncgen close 2026-02-02 00:43:07 +09:00
Jeong, YunWon
9a9426ee73 mark test failures 2026-02-02 00:43:07 +09:00
Jeong, YunWon
963261c40f mark failures 2026-02-02 00:43:07 +09:00
Jeong, YunWon
085f517a3f keycert3 2026-02-02 00:43:07 +09:00
CPython Developers
b83d155235 Update asyncio from v3.14.2 2026-02-02 00:43:07 +09:00
Jeong, YunWon
fe40dd37c0 impl more _asyncio 2026-02-02 00:43:07 +09:00
Jeong, YunWon
d90792258d import .gitattributes from CPython (#6939) 2026-02-02 00:27:21 +09:00
Jeong, YunWon
153b0da60d automark add reasons to reason-less expectedFailures and handles parent better (#6936) 2026-02-01 22:58:07 +09:00
Jeong, YunWon
dd09f41dcc clear_after_fork (#6933) 2026-02-01 19:42:30 +09:00
Jeong, YunWon
0b9c90fcc4 Update enum from v3.14.2 (#6932)
---------

Co-authored-by: CPython Developers <>
2026-02-01 19:14:55 +09:00
Jeong, YunWon
97861c6809 Rework exception compiler to use CFG-based handler analysis (#6909)
Move exception handler tracking from compile-time fblock metadata to
a post-codegen CFG analysis pass, matching flowgraph.c's pipeline.

Compiler changes (compile.rs):
- Remove fb_handler, fb_stack_depth, fb_preserve_lasti from FBlockInfo
- Remove handler_stack_depth() and current_except_handler() helpers
- Emit SetupFinally/SetupCleanup/SetupWith/PopBlock pseudo instructions
  instead of manually tracking handlers in fblocks
- Add dead blocks after raise/break/continue/return to prevent
  dead code from corrupting the except stack
- Add missing PopTop after CallIntrinsic1 ImportStar
- Fix async comprehension SetupFinally/GetANext emission order
- Fix try-except* handler: move BUILD_LIST/COPY before handler loop
- Rework unwind_fblock for HandlerCleanup, TryExcept, FinallyTry,
  FinallyEnd, and With/AsyncWith to emit proper PopBlock sequences

New CFG analysis passes (ir.rs):
- mark_except_handlers(): mark blocks targeted by SETUP_* instructions
- label_exception_targets(): walk CFG with except stack to set
  per-instruction handler info and convert POP_BLOCK to NOP
- convert_pseudo_ops(): lower remaining pseudo ops after analysis
- Compute handler entry depth from SETUP_* type in max_stackdepth()
  (SETUP_CLEANUP=+2, SETUP_FINALLY/SETUP_WITH=+1)
- Fix SEND jump_effect from -1 to 0 (receiver stays until END_SEND)
- Add underflow guard for handler stack_depth calculation

Instruction metadata (instruction.rs):
- SetupCleanup/SetupFinally/SetupWith now carry target: Arg<Label>
- Add is_block_push()/is_pop_block() to PseudoInstruction/AnyInstruction
- Fix LoadSpecial stack_effect from (2,2) to (1,1)
- Set Setup* stack_effect_info to (0,0) for fall-through consistency

Fixes 3 test_coroutines expectedFailures:
- test_with_8, test_for_assign_raising_stop_async_iteration{,_2}
2026-02-01 17:53:57 +09:00
Jeong, YunWon
25bf682006 Fix number __format__ (#6930) 2026-02-01 17:17:09 +09:00
Jeong, YunWon
0546bb0410 more deps grouping (#6931) 2026-02-01 17:01:56 +09:00
Lee Dogeon
c6f7c6e273 Remove RustPython-specific workaround in timeit module (#6923) 2026-02-01 14:52:36 +09:00
Jeong, YunWon
5e4c3b07fb gc is vm/stdlib (#6929) 2026-02-01 13:21:24 +09:00
Jeong, YunWon
fdf93c5a19 Merge pull request #6928 from fanninpm/3.14-test-pep646-syntax
Update `test_pep646_syntax` from v3.14.2
2026-02-01 13:18:29 +09:00
Jeong, YunWon
380500c92d Merge pull request #6927 from fanninpm/3.14-test-termios
Update `test_termios` from v3.14.2
2026-02-01 13:18:04 +09:00
Jeong, YunWon
db4a2d5a9f Merge pull request #6921 from fanninpm/3.14-test-frozen
Update `test_frozen` from v3.14.2
2026-02-01 13:17:39 +09:00
Jeong, YunWon
294eb2c904 Merge pull request #6926 from fanninpm/3.14-test-string
Update `test_string` from v3.14.2
2026-02-01 13:16:57 +09:00
Jeong, YunWon
80e9172de0 Merge pull request #6922 from fanninpm/3.14-test-osx-env
Update `test_osx_env` from v3.14.2
2026-02-01 12:13:05 +09:00
Jeong, YunWon
60bec8a561 rework weakref (#6916)
* Replace WeakListInner with inline atomic weakref list and stripe locks

Remove heap-allocated WeakListInner (OncePtr<PyMutex<WeakListInner>>).
WeakRefList now holds two inline atomic pointers (head, generic).
PyWeak.parent replaced with wr_object pointing directly to referent.
Add weakref_lock module with AtomicU8 spinlock array for thread safety.
Rewrite upgrade/clear/drop_inner/count/get_weak_references with stripe lock.
Make Pointers methods public in linked_list.rs.
Remove expectedFailure from test_subclass_refs_dont_replace_standard_refs.

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-01 12:12:33 +09:00
Jeong, YunWon
3e629287da Merge pull request #6925 from fanninpm/3.14-test-select
Update `test_select` from v3.14.2
2026-02-01 12:10:39 +09:00
Padraic Fanning
f6d1fe4aa1 Add test_pep646_syntax to platform-independent tests 2026-01-31 21:48:51 -05:00
Padraic Fanning
deb517d346 Mark failing tests 2026-01-31 21:34:47 -05:00
CPython Developers
17e810e6ed Update test_frozen from v3.14.2-288-g06f9c8ca1c 2026-01-31 21:34:47 -05:00
Padraic Fanning
2bb027ac6a Mark failing tests 2026-01-31 21:23:23 -05:00
CPython Developers
553be2af33 Update test_pep646_syntax from v3.14.2-288-g06f9c8ca1c 2026-01-31 21:18:15 -05:00
Padraic Fanning
331c0bd613 Mark failing and erroring tests 2026-01-31 21:12:03 -05:00
Padraic Fanning
539f79b0b7 Skip crashing tests 2026-01-31 21:11:46 -05:00
CPython Developers
b220bddd06 Update test_termios from v3.14.2-288-g06f9c8ca1c 2026-01-31 21:05:57 -05:00
CPython Developers
771d563171 Update test_string from v3.14.2-288-g06f9c8ca1c 2026-01-31 21:00:06 -05:00
Padraic Fanning
04ee6b8adc Mark failing tests 2026-01-31 20:51:53 -05:00
Padraic Fanning
023f5efc43 Skip test that took too long 2026-01-31 20:51:34 -05:00
CPython Developers
fe3d273bfd Update test_select from v3.14.2-288-g06f9c8ca1c 2026-01-31 20:48:48 -05:00
CPython Developers
bb8f759725 Update test_osx_env from v3.14.2-288-g06f9c8ca1c 2026-01-31 19:56:55 -05:00
Jeong, YunWon
1a437fc818 Merge pull request #6920 from fanninpm/3.14-test-fork1
Update `test_fork1` from v3.14.2
2026-02-01 09:42:04 +09:00
Jeong, YunWon
111ced08e4 Fix member_descriptor to match CPython behavior (#6915)
descriptor.rs:
- Add __objclass__, __name__ (pymember) and __reduce__ (pymethod)
- Add type check (descr_check) in descr_get; simplify None branch
- Remove incorrect BASETYPE flag
- Add MemberKind::Object (_Py_T_OBJECT = 6)
- Prevent Bool slot deletion (TypeError)
- Raise AttributeError on ObjectEx deletion when already None

pyclass.rs (derive-impl):
- Remove duplicate MemberKind enum; use MemberKindStr (Option<String>)
- Simplify MemberNursery map key from (String, MemberKind) to String
- Support #[pymember(type="object")] for _Py_T_OBJECT semantics

test_inspect.py:
- Remove expectedFailure from test_getdoc (now passing)
2026-02-01 09:41:38 +09:00
Jeong, YunWon
714d1ce58b gc module internal structure and API (#6910)
* gc module internal structure and API

Add gc_state module with GcState, GcGeneration, GcDebugFlags, GcStats.
Replace gc module stubs with working API backed by gc_state.
Add gc_callbacks and gc_garbage to Context.
Add is_gc_tracked, gc_finalized, gc_get_referents to PyObject.
Collection is stubbed (returns 0) — actual algorithm to follow.

* fix dict/weakref/generators

* unmark test_asyncio

* apply review
2026-02-01 08:51:39 +09:00
Shahar Naveh
988b8b865e Make to_oparg to return a Result<Self, MarshalError> (#6914) 2026-02-01 08:50:16 +09:00
Jeong, YunWon
7ea22806d4 Merge pull request #6912 from fanninpm/3.14-test-_locale
Update `test__locale` from v3.14.2
2026-02-01 08:49:12 +09:00
ShaharNaveh
07ba834381 Update os constant to libc 0.2.180 & target cpython 3.14 2026-02-01 08:48:20 +09:00
Padraic Fanning
d04a50e835 Mark expected failures 2026-02-01 08:47:12 +09:00
CPython Developers
379e285e03 Update test_extcall from v3.14.2-288-g06f9c8ca1c 2026-02-01 08:47:12 +09:00
fanninpm
c6307d3a52 Update test_coroutines from v3.14.2 (#6918)
* Update test_coroutines from v3.14.2-288-g06f9c8ca1c

* Mark expected failures on Linux

---------

Co-authored-by: CPython Developers <>
2026-02-01 08:46:00 +09:00
Padraic Fanning
6f9320bb11 Mark failing test 2026-01-31 15:21:00 -05:00
CPython Developers
a8b0ffbfcb Update test_fork1 from v3.14.2-288-g06f9c8ca1c 2026-01-31 15:17:44 -05:00
Padraic Fanning
4d537c7b09 Skip tests that panic on macOS (and windows) 2026-01-31 15:13:23 -05:00
CPython Developers
7675e10236 Update test__locale from v3.14.2-288-g06f9c8ca1c 2026-01-31 15:13:23 -05:00
Shahar Naveh
c771427c38 Use stack_effect_info for getting pop&push count (#6913) 2026-01-31 23:45:46 +09:00
Jeong, YunWon
ba8749b792 Align del behavior (#6772)
* slot_del

* refcount inc_by for atomicity

* temp patch multithreading

* apply review
2026-01-31 23:09:10 +09:00
Copilot
cdd47b6a59 Upgrade hmac to Python 3.14.2 (#6863)
---------

Co-authored-by: moreal <26626194+moreal@users.noreply.github.com>
2026-01-31 18:40:34 +09:00
fanninpm
10cbfa9361 Add f_trace_opcodes (#6911)
* Add f_trace_opcodes

Needed for bdb, and, by extension, pdb, to work.

* Fix compile error
2026-01-31 17:03:17 +09:00
Shahar Naveh
743d6b83d3 Split stack_effect into pushed & popped (#6893) 2026-01-31 16:58:14 +09:00
Lee Dogeon
b1f158e5a8 Mark tests failing only in Windows 2026-01-31 10:11:58 +09:00
CPython Developers
31ee8b593f Update codecs from v3.14.2 2026-01-31 10:11:58 +09:00
Lee Dogeon
0c174624b4 Introduce /upgrade-pylib-next (#6827)
* Simplify upgrade-pylib.md by removing manual copy steps handled by quick command

* Let upgrade-pylib run auto-mark instead marking manually

* Let upgrade-pylib a separate commit from updating module

* Correct commands' permissions

* Add open PR check to upgrade-pylib-next command

* Fix dependency pattern example in upgrade-pylib-next command

* Let upgrade-pylib command to invetigate failing tests

* Add pre-commit review to invetigate-test-failure command

* Use deps command to get dependent tests in upgrade-pylib workflow
2026-01-31 07:40:39 +09:00
CPython Developers
f6d562e2ee Update test_baseexception from v3.14.2 2026-01-31 07:14:37 +09:00
Jeong, YunWon
050faa312a Fix _overlapped segfault and missing _winapi constants
- Fix from_windows_err using new_exception_empty on OSError subclasses
  (ConnectionRefusedError, ConnectionAbortedError), which caused segfault
  in release builds due to debug_assert on type size mismatch
- Move ConnectPipe from instance method to module-level function
- Add Destructor for Overlapped to cancel pending I/O on object cleanup
- Add NMPWAIT_NOWAIT, NMPWAIT_USE_DEFAULT_WAIT, NMPWAIT_WAIT_FOREVER
  constants to _winapi
2026-01-31 06:39:32 +09:00
Jeong, YunWon
adb7a91ec6 Merge pull request #6906 from ShaharNaveh/update-symtable
Update `symtable` from 3.14.2
2026-01-31 06:34:44 +09:00
Jeong, YunWon
5df67028ff Update test_exceptions from v3.14.2 (#6904)
* [update_lib] fix async detection

* Update test_exceptions from v3.14.2

* Update test_except_star from v3.14.2

* Update test_exception_hierarchy from v3.14.2

* Update test_exception_variations from v3.14.2

* Auto-format: ruff format

---------

Co-authored-by: CPython Developers <>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-31 06:30:06 +09:00
github-actions[bot]
9338509a71 Auto-format: ruff format 2026-01-30 20:50:37 +00:00
CPython Developers
980e76ea1f Update test_exception_variations from v3.14.2 2026-01-31 05:49:16 +09:00
CPython Developers
cb138c8f37 Update test_exception_hierarchy from v3.14.2 2026-01-31 05:49:16 +09:00
CPython Developers
7cd55802f6 Update test_except_star from v3.14.2 2026-01-31 05:49:16 +09:00
ShaharNaveh
ec906679b9 Update symtable from 3.14.2 2026-01-30 19:13:59 +02:00
CPython Developers
8265279411 Update test_exceptions from v3.14.2 2026-01-31 00:59:29 +09:00
Jeong, YunWon
922b644116 [update_lib] fix async detection 2026-01-31 00:59:29 +09:00
Jeong, YunWon
528d6573e0 [update_lib] Fix async func auto-mark (#6903) 2026-01-31 00:00:41 +09:00
Jeong, YunWon
bb0a201502 Merge pull request #6901 from ShaharNaveh/update-decimal
Update `decimal` from 3.14.2
2026-01-30 23:41:34 +09:00
ShaharNaveh
6af0af2b3c Unmark passing test 2026-01-30 16:39:33 +02:00
ShaharNaveh
a1b41ad2ad Update decimal from 3.14.2 2026-01-30 16:38:36 +02:00
Copilot
568f24cc84 Upgrade timeit module from Python 3.14.2 (#6854)
---------

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-30 22:40:48 +09:00
Shahar Naveh
51701ab2a4 Update class related tests from 3.14.2 (#6900)
* Update `test_class` from 3.14.2

* Update test_genericclass

* Update test_subclassinit

* Add test_metaclass

* Patch `test_class`

* Patch test_subclassinit

* Patch `test_metaclass`

----

Co-authored-by: CPython Developers <>
2026-01-30 22:38:49 +09:00
Noa
276a4bdc80 Make paths in macro arguments relative to the source file, not MANIFEST_DIR (#6873) 2026-01-30 22:37:18 +09:00
Shahar Naveh
62c67546ac Update optparse,gettext,textwrap from 3.14.2 (#6896)
* Update optparse from 3.14.2

* Update `gettext`

* Update `textwrap`
2026-01-30 20:48:57 +09:00
Jeong, YunWon
9183661d88 Merge pull request #6899 from youknowone/weakref
Update weakref from v3.14.2
2026-01-30 20:47:53 +09:00
Shahar Naveh
75bcd24918 Update py_compile from 3.14.2 (#6897) 2026-01-30 19:24:33 +09:00
Jeong, YunWon
3daabbd2be Fix weakref 2026-01-30 19:21:10 +09:00
CPython Developers
0446bc71a0 Update weakref from v3.14.2 2026-01-30 19:21:10 +09:00
Jeong, YunWon
8e9d591369 Align GetAwaitable to Python 3.14.2 (#6895) 2026-01-30 12:13:39 +09:00
ShaharNaveh
e4eb0a7116 Update fractions from 3.14.2 2026-01-30 07:48:29 +09:00
Jeong, YunWon
4ca2da4987 Merge pull request #6838 from youknowone/asyncio
Add _asyncio and add test_asyncio
2026-01-29 22:35:30 +09:00
Jeong, YunWon
d0003f85c5 skip test_asyncio on windows 2026-01-29 22:13:26 +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
d8fa1b4366 _asyncio rust impl 2026-01-29 16:48:33 +09:00
CPython Developers
850a0a7847 test_asyncio from Python 3.14.2 2026-01-29 16:48:33 +09:00
Jeong YunWon
aaa86584e5 Add _asyncio 2026-01-29 16:48:33 +09:00
Jeong YunWon
2e0b76556a Add more socket consts 2026-01-29 16:48:33 +09:00
Jeong, YunWon
fcca0feb70 Add missing windows APIs 2026-01-29 16:48:33 +09:00
Jeong, YunWon
e363b14e81 fix ssl MSG_PEEK (#6892) 2026-01-29 16:48:02 +09:00
Jeong, YunWon
e2fda95f9a Merge pull request #6885 from youknowone/overlapped
impl more overlapped
2026-01-28 17:01:06 +09:00
Jeong, YunWon
c3a5f9d5b2 cspell dict 2026-01-28 16:57:34 +09:00
Jeong, YunWon
0cc43e192c Implement Windows overlapped I/O for asyncio support
Add comprehensive Windows async I/O support to the overlapped module:

Winsock Extensions:
- Initialize AcceptEx, ConnectEx, DisconnectEx, TransmitFile via WSAIoctl
- Proper cleanup with all four extension locks checked

Overlapped Methods:
- ReadFile, ReadFileInto: Async file reading
- WriteFile: Async file writing
- WSARecv, WSARecvInto: Async socket receive
- WSASend: Async socket send
- WSARecvFrom, WSARecvFromInto: Async UDP receive with address
- WSASendTo: Async UDP send to address
- AcceptEx: Async socket accept
- ConnectEx: Async socket connect
- DisconnectEx: Async socket disconnect
- TransmitFile: Async file transmission over socket
- ConnectNamedPipe, ConnectPipe: Named pipe support

Module Functions:
- CreateIoCompletionPort: IOCP creation/association
- GetQueuedCompletionStatus: Dequeue completion packets
- PostQueuedCompletionStatus: Post completion packets
- RegisterWaitWithQueue: Register wait with completion port callback
- UnregisterWait, UnregisterWaitEx: Unregister waits with proper cleanup
- BindLocal: Bind socket to local address
- CreateEvent, SetEvent, ResetEvent: Event object management
- FormatMessage: Windows error message formatting

Safety & Correctness:
- Validate buffer contiguity before async operations
- Validate size parameters to prevent buffer overflow
- Use Arc for RegisterWaitWithQueue callback data to prevent UAF
  (callback may run after UnregisterWait returns per Windows API docs)
2026-01-28 16:56:47 +09:00
Jeong, YunWon
d257d95362 set encodings for opcode_metadata scripts 2026-01-28 16:56:47 +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
Elmir
44c3179ae0 Docs: add reference to rustpython_derive close to example (#6882)
Include a link for native module macros documentation, after an
example where they are used.
2026-01-28 10:25:48 +09:00
fanninpm
4c1c704bb1 Add ExpatError and error to pyexpat (#6889)
* Stub out xml.parsers.expat.ExpatError

* Alias `ExpatError` to `error`
2026-01-28 10:19:00 +09:00
fanninpm
601b9d8984 Make issue_assign job run on ubuntu-slim runner (#6890) 2026-01-28 08:28:57 +09:00
Jeong, YunWon
5b7f93f6b6 Fix CI: cargo doc --lock (#6888)
* cargo doc --locked

* Update Cargo.lock
2026-01-27 21:51:48 +09:00
Jeong, YunWon
aa99c05231 Merge pull request #6870 from ShaharNaveh/update-dis-3-14-2 2026-01-27 13:20:39 +09:00
dependabot[bot]
364ddaab54 Bump cranelift from 0.127.2 to 0.128.0 (#6877)
* Bump cranelift from 0.127.2 to 0.128.0

Bumps [cranelift](https://github.com/bytecodealliance/wasmtime) from 0.127.2 to 0.128.0.
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.128.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2026-01-27 13:20:06 +09:00
ShaharNaveh
253414f168 Update test_compiler_codegen and test_compiler_assemble 2026-01-27 10:49:05 +09:00
ShaharNaveh
7cc4f43779 Update test_peepholer from 3.14.2 2026-01-27 10:49:04 +09:00
dependabot[bot]
5a02051d68 Bump actions/checkout from 6.0.1 to 6.0.2 (#6881)
Bumps [actions/checkout](https://github.com/actions/checkout) from 6.0.1 to 6.0.2.
- [Release notes](https://github.com/actions/checkout/releases)
- [Commits](https://github.com/actions/checkout/compare/v6.0.1...v6.0.2)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-27 09:58:52 +09:00
dependabot[bot]
4eb11ba940 Bump actions/setup-python from 6.1.0 to 6.2.0 (#6880)
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 6.1.0 to 6.2.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v6.1.0...v6.2.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: 6.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-27 09:58:33 +09:00
Jeong, YunWon
edca32a194 Fix ssl shutdown (#6871)
* Fix ssl shutdown

* Fix thread
2026-01-27 02:50:15 +09:00
dependabot[bot]
93274d3888 Bump quote from 1.0.43 to 1.0.44
Bumps [quote](https://github.com/dtolnay/quote) from 1.0.43 to 1.0.44.
- [Release notes](https://github.com/dtolnay/quote/releases)
- [Commits](https://github.com/dtolnay/quote/compare/1.0.43...1.0.44)

---
updated-dependencies:
- dependency-name: quote
  dependency-version: 1.0.44
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-27 00:04:20 +09:00
dependabot[bot]
f548b3d71a Bump thiserror from 2.0.17 to 2.0.18
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 2.0.17 to 2.0.18.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/2.0.17...2.0.18)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-version: 2.0.18
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-26 23:48:29 +09:00
dependabot[bot]
0dd73170e5 Bump openssl-probe from 0.2.0 to 0.2.1
Bumps [openssl-probe](https://github.com/rustls/openssl-probe) from 0.2.0 to 0.2.1.
- [Release notes](https://github.com/rustls/openssl-probe/releases)
- [Commits](https://github.com/rustls/openssl-probe/compare/0.2.0...0.2.1)

---
updated-dependencies:
- dependency-name: openssl-probe
  dependency-version: 0.2.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-26 23:47:39 +09:00
Jeong, YunWon
6a3643cdde Improve deps output (#6874)
* Improve deps output: [x]/[ ] sync status, TODO counts

- Replace ambiguous [+] with [x] (synced) / [ ] (not synced)
- Add (TODO: n) suffix for test files with expectedFailure/skip markers

* Refactor update_lib: extract shared utilities
2026-01-26 18:35:35 +09:00
Jeong, YunWon
93b26bf595 Merge pull request #6869 from youknowone/opcode
Update opcode, dis from 3.14.2
2026-01-26 11:39:23 +09:00
Jeong YunWon
4b823ebaf5 mark test_dis failures 2026-01-26 10:40:23 +09:00
CPython Developers
131c296bb4 Update dis from v3.14.2 2026-01-26 10:40:22 +09:00
CPython Developers
0b806b9131 Update opcode from v3.14.2 2026-01-26 10:40:22 +09:00
Jeong YunWon
8c73f3cb30 emit RESUME 2026-01-26 10:40:22 +09:00
Jeong YunWon
9216500355 reimpl smallint 2026-01-26 10:40:22 +09:00
Jeong YunWon
b4d09e081d get_common_constants 2026-01-26 10:40:22 +09:00
Noa
617cdc9724 Make validate_downcastable_from unsafe (#6851) 2026-01-26 10:39:08 +09:00
Noa
0a9d41d3dd Depend on serde_core instead of serde (#6872) 2026-01-26 10:23:19 +09:00
Jeong, YunWon
7eceb145b1 more optimization (#6860) 2026-01-25 10:18:47 +02:00
CPython Developers
6595d50d18 Update test_apple from v3.14.2 2026-01-25 15:20:05 +09:00
Jeong, YunWon
9071147db5 [update_lib] Apply test grouping to deps (#6867)
* quick resolve test path too

* Fix migrate resolve

* Remove test/ from deps data

* resolve test to lib
2026-01-24 18:40:57 +02:00
Jeong, YunWon
4963cc659f Merge pull request #6858 from youknowone/win-lib
Update urllib and windows libraries from v3.14.2
2026-01-25 00:19:44 +09:00
Jeong, YunWon
26d64b9fda impl more msvcrt 2026-01-25 00:18:55 +09:00
CPython Developers
1251fbf0ba Update test_msvcrt from v3.14.2 2026-01-25 00:18:55 +09:00
CPython Developers
3e39990503 Update test_winapi from v3.14.2 2026-01-25 00:18:55 +09:00
CPython Developers
4f1d191ca9 Update nturl2path from v3.14.2 2026-01-25 00:18:55 +09:00
Jeong, YunWon
2ac1b04914 Upgrade nt_path from v3.14.2 2026-01-25 00:18:55 +09:00
Jeong YunWon
448658e49d Update urllib from v3.14.2 2026-01-25 00:18:55 +09:00
Shahar Naveh
77add04d3d Update to ruff 0.14.14 (#6861) 2026-01-24 22:49:19 +09:00
Jeong, YunWon
f35791ec64 Fix update_lib tests (#6866) 2026-01-24 22:47:03 +09:00
Jeong, YunWon
e0e29260f5 Remove Copy from PyPayload 2026-01-24 22:03:30 +09:00
Jeong, YunWon
0cc8f63849 [update_lib] deps grouping (#6854) 2026-01-24 21:29:11 +09:00
Copilot
185f360fea Update html module from Python 3.14.2 (#6855) 2026-01-24 19:12:23 +09:00
Copilot
f8d4d991f1 Upgrade zipimport to Python 3.14.2 (#6857) 2026-01-24 16:11:36 +09:00
Jeong, YunWon
483e4a2bab Align psuedo ops to CPython 3.14.2 (#6846)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Optimized attribute and super-attribute bytecode emission and
consolidated pseudo-instruction handling, improving consistency and
stack-effect accuracy.
* **Chores**
  * Adjusted opcode constants and simplified opcode/name mappings.
* **New Features**
* Added a utility to enumerate special method names and a helper for
resolving dependency parent modules.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-24 16:10:36 +09:00
Jeong YunWon
c0bdb9a3e5 align psuedo ops to 3.14.2 2026-01-24 16:09:40 +09:00
Jeong YunWon
771650a012 align HAVE_ARGUMENT 2026-01-24 16:09:40 +09:00
Jeong, YunWon
691d2816f9 update_lib todo also shows test todo (#6859)
also tracking untracked files considered in  #6775
2026-01-24 16:04:36 +09:00
Copilot
eedc70dfae Upgrade cmd module from CPython v3.14.2 (#6853)
Upgrades the `cmd` module and its tests from CPython v3.14.2 tag.
2026-01-24 11:37:32 +09:00
Copilot
da41a0cb20 Upgrade quopri from Python 3.14.0 (#6852)
Upgrades the `quopri` module from Python 3.14.0 as part of the ongoing
standard library update effort.

## Changes

- Updated `Lib/quopri.py` from CPython v3.14.0
  - Removed shebang line
  - Changed file mode from executable to regular file
- No functional changes to the module
2026-01-24 10:57:22 +09:00
Noa
f842fbe25d Use std::fmt::from_fn (#6850)
New in 1.93 - replaces our ad-hoc equivalent types.
2026-01-24 09:21:45 +09:00
Copilot
b0c5bbc589 Update warnings module from CPython 3.14.1 (#6840) 2026-01-24 01:24:41 +09:00
Jeong, YunWon
d86bec3252 Update copyreg from v3.14.2 (#6848) 2026-01-23 16:23:56 +00:00
Jeong, YunWon
180c68e76b improve deps CI formatting and name resolution (#6847)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Improvements**
* Enhanced test module dependency tracking in automated checks to
properly identify and report test-related dependencies.
* Improved dependency resolution logic with better module name mapping
and deduplication for clearer dependency reporting.
* Refined formatting of dependency information and todo items for
improved readability.
* Dependency review comments now automatically refresh with the latest
information when updated.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-24 00:32:32 +09:00
Jeong, YunWon
af7bbfa104 derive Copy where possible (#6844)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Made many lightweight/internal types trivially copyable to simplify
value handling across the codebase.
* Added a workspace lint to surface missing copy implementations as
warnings.
  * Extended buffer support with explicit retain/release hooks.

* **Bug Fixes**
* Improved diagnostics and debug output for thread/lock acquisition
scenarios.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-23 15:24:17 +00:00
CPython Developers
4c670ba5a2 Update copyreg from v3.14.2 2026-01-24 00:24:12 +09:00
CPython Developers
dbbd921a53 Update linecache from v3.14.2 2026-01-23 23:58:24 +09:00
CPython Developers
ac2729511f Update operator from v3.14.2 2026-01-23 23:57:31 +09:00
Jeong, YunWon
37fe0cfae2 Seperate between scope exit & unconditional jump opcodes (#6841)
See:
1fa166888b/Include/internal/pycore_opcode_utils.h (L39-L44)

and
1fa166888b/Include/internal/pycore_opcode_utils.h (L52-L55)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Updated compiler control flow analysis for improved accuracy in
dead-code elimination and stack-depth tracking.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-23 14:56:39 +00:00
ShaharNaveh
2c2b13784e Clippy 2026-01-23 16:41:24 +02:00
ShaharNaveh
a9364cbc52 Fix warnings 2026-01-23 16:41:19 +02:00
ShaharNaveh
2f76ef654b Add workspace lint 2026-01-23 16:41:19 +02:00
Lee Dogeon
5c7f6a2afa Update types from v3.14.2 (#6833)
This pull request updates `types` module to v3.14.2. While doing it, it
fixes also async-related feature. This pull request's base is generated
by #6827.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Generators that act as iterable coroutines are now recognized as
awaitable, improving async behavior.
* Yield-from and await interactions now handle coroutine-iterable
sources more consistently.

* **Bug Fixes**
* Reduces spurious TypeError cases when awaiting or yielding from
wrapped coroutine-like generators.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-23 23:23:02 +09:00
ShaharNaveh
2ee48bc5aa Seperate between scope exit & unconditional jump opcodes 2026-01-23 14:25:03 +02:00
Jeong, YunWon
efce325cbf Fix asyncio related compiler/library issues (#6837)
* Fix socket bytes support

* fix unwind_fblock

* fix posix.sendfile

* fix ssl_write

* Fix SSL ZeroReturn

* fix context

* fix generator

* Enable unittest test_async_case again
2026-01-23 19:59:29 +09:00
Lee Dogeon
9b56aa5b60 [update_lib] show dependent tests in deps subcommand (#6828)
---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2026-01-23 08:13:16 +09:00
Jeong, YunWon
125ade5f55 fix clippy 1.93.0 (#6836)
* fix clippy 1.93.0

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-23 02:18:39 +09:00
Jeong, YunWon
11a59bb405 Merge pull request #6835 from youknowone/updatelib-ci
CI runs update_lib
2026-01-23 00:57:07 +09:00
Jeong, YunWon
8cbaf3c2ef typevar as module (#6834) 2026-01-22 22:06:14 +09:00
Jeong YunWon
43bd4940ea CI tests update_lib 2026-01-22 20:59:49 +09:00
Jeong YunWon
0ba57b0632 Fix ast.Constant.__init__ 2026-01-22 20:59:49 +09:00
Jeong, YunWon
40a43f3210 instruction improvements (#6829)
New Features

Direct small-integer loading (0–255) and locals-loading for faster execution
Async-generator wrapping and improved generator resume behavior
Performance

Faster integer loads and streamlined jump/loop handling for better runtime performance
Bug Fixes

More robust StopIteration handling and stricter init return checks
Corrected iterator cleanup for async and sync loops
Improvements

Aligns loop and jump semantics with CPython 3.14 patterns
2026-01-22 17:25:56 +09:00
CPython Developers
aed3a60e17 Update pydoc_data from v3.14.2 2026-01-22 16:02:41 +09:00
Jeong, YunWon
47df6dd270 Merge pull request #6740 from youknowone/multi-phase-module-init
Multi phase module init
2026-01-22 12:12:43 +09:00
Jeong YunWon
20376451eb Implement Py_mod_create slot support in multi-phase init 2026-01-22 11:21:42 +09:00
dependabot[bot]
512c84dbc0 Bump lodash from 4.17.21 to 4.17.23 in /wasm/demo
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.21 to 4.17.23.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.21...4.17.23)

---
updated-dependencies:
- dependency-name: lodash
  dependency-version: 4.17.23
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-22 09:31:19 +09:00
CPython Developers
9c8aef3c05 Update token from v3.14.2 2026-01-22 08:02:43 +09:00
Jeong YunWon
bc02b2318c module_exec 2026-01-21 22:39:40 +09:00
Jeong YunWon
32d2406fa8 module_def 2026-01-21 22:39:40 +09:00
Jeong YunWon
fee1a4b097 multiphase 2026-01-21 22:39:39 +09:00
Jeong YunWon
3ccff6d7c9 os.stat remove winodws-only attrs 2026-01-21 22:39:39 +09:00
Jeong, YunWon
726a053ca2 Merge pull request #6818 from youknowone/regrtest
libregrtest from 3.14.2
2026-01-21 21:35:43 +09:00
Jeong, YunWon
9e9bfa56c2 Update libregrtest from v3.14.2 2026-01-21 20:44:26 +09:00
Jeong YunWon
2fb2a7eda8 winapi.WaitForSingleObject 2026-01-21 20:44:25 +09:00
fanninpm
122fac9c53 Optimize CI cache usage (#6707)
* Make whats_left.py compile with same settings as before

* Add --no-default-features to scripts/whats_left.py

* Build RustPython with no default features

* Retrigger CI
2026-01-21 20:17:42 +09:00
Lee Dogeon
ce1bbc7938 Bump mimetypes to 3.14.2 (#6808)
* Bump mimetypes to 3.14.2

* Unmark resolved tests

* Mark failed test in Windows
2026-01-21 20:14:30 +09:00
Jeong, YunWon
2df879c5ee Fix Drop to prevent TLS data loss (#6825)
Remove pending_tls_output.clear() from Drop implementation.

SSLSocket._real_close() in Python doesn't call shutdown() before
closing - it just sets _sslobj = None. This means pending TLS data
in the output buffer may not have been flushed to the socket yet.
Clearing this buffer in Drop causes data loss, resulting in empty
HTTP responses (test_socketserver failure on Windows).

The explicit clearing is also unnecessary since all struct fields
are automatically freed when the struct is dropped.
2026-01-21 17:29:22 +09:00
Jeong, YunWon
1b5deea53a Merge pull request #6826 from moreal/bump-3.14.2-reprlib
Update reprlib from v3.14.2
2026-01-21 17:17:47 +09:00
Lee Dogeon
4eecd15a2a Mark failing tests 2026-01-21 15:10:40 +09:00
CPython Developers
d7dba07304 Update reprlib from v3.14.2 2026-01-21 15:10:40 +09:00
Jeong, YunWon
d690b2d65e [update_lib] todo subcommand (#6823)
* [update_lib] todo

* better CI comment
2026-01-21 09:00:45 +09:00
Jeong, YunWon
22974cff20 Update struct from v3.14.2 (#6824)
Co-authored-by: CPython Developers <>
2026-01-21 03:05:05 +09:00
Jeong, YunWon
a7f2351244 Remove BEFORE_WITH,BINARY_SUBSCR (#6822) 2026-01-21 02:58:24 +09:00
Jeong, YunWon
58c804309b [update_lib] show deps (#6821)
* show_deps

* soft deps tree

* show deps CI
2026-01-21 01:25:30 +09:00
Jeong, YunWon
274e8b4b6b Remove JUMP_IF_NOT_EXC_MATCH, SET_EXC_INFO (#6820) 2026-01-21 01:23:43 +09:00
Jeong, YunWon
90ff571493 Update _collections_abc from v3.14.2 (#6819)
Co-authored-by: CPython Developers <>
2026-01-21 01:01:09 +09:00
Jeong, YunWon
e0cceaf31c Remove ReturnConst/Break/Continue ops (#6816)
* Remove ReturnConst

* Remove break/continue ops
2026-01-21 00:03:43 +09:00
Lee Dogeon
3bcd071e4d Bump collections to 3.14.2 (#6770)
* Bump collections to 3.14.2

* Unmark resolved tests
2026-01-20 23:58:43 +09:00
Jeong, YunWon
5ef8d48e5a update_lib hard dependency resolver (#6817)
* update_lib __init__ handling

* dependency

* Auto-format: ruff format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-20 23:52:28 +09:00
Jeong, YunWon
e01f26c1f6 Update inspect from v3.14.2 (#6815)
* Update inspect from v3.14.2

* temp asyncio.event._set_event_loop_policy

* mark inspect tests

---------

Co-authored-by: CPython Developers <>
2026-01-20 21:34:34 +09:00
Jeong, YunWon
94ccfb8b18 Prohibit AI PR submit (#6813) 2026-01-20 21:13:28 +09:00
Jeong, YunWon
0f28d4e199 Merge pull request #6811 from youknowone/functools
Implement more functools features and Update functools from v3.14.2
2026-01-20 19:18:14 +09:00
Lee Dogeon
0cad3cb8b8 Use empty list as default according to Python.asdl (#6812)
* Use empty list as default in ClassDef.{bases,keywords}

* Unmark resolved tests

* Use empty list as default in FunctionDef.type_params

* Use empty list as default in ClassDef.type_params
2026-01-20 18:02:42 +09:00
Jeong, YunWon
479bb7af1a skip weakref crash test 2026-01-20 17:33:07 +09:00
Jeong, YunWon
ff4f7a0e94 temp inspect patch 2026-01-20 17:33:07 +09:00
Jeong, YunWon
ddc5ba0b98 cspell phcount 2026-01-20 17:32:58 +09:00
Jeong, YunWon
c82da8b887 mark functools tests 2026-01-20 17:32:52 +09:00
CPython Developers
40c29f689f Update functools from v3.14.2 2026-01-20 17:32:52 +09:00
Jeong, YunWon
4d27603cb5 fix functools.reduce 2026-01-20 17:32:52 +09:00
Jeong, YunWon
b472e88caf classmethod/staticmethod __annotate__ 2026-01-20 17:32:52 +09:00
Jeong, YunWon
f0c3e7d51f Remove SUBSCRIPT, JUMP_IF_{TRUE,FALSE}_OR_POP (#6810)
* Align ForIter behavior (incomplete)

* Romove JUMP_IF_{TRUE,FALSE}_OR_POP, subscript

* Remove LoadAssetionError

* Update snapshot for ForIter behavior change
2026-01-20 16:21:23 +09:00
Lee Dogeon
52a854a57a Unmark resolved test 2026-01-20 15:29:05 +09:00
Lee Dogeon
c8b1cb8cab Bump re to 3.14.2 2026-01-20 15:29:05 +09:00
Jeong, YunWon
25a3d6dde1 functools.Placeholder 2026-01-20 13:45:52 +09:00
Jeong, YunWon
6e842cf110 PyPartial::__get__ 2026-01-20 11:42:59 +09:00
github-actions[bot]
f1fd1e9121 Auto-format: ruff format 2026-01-20 11:38:26 +09:00
Jeong, YunWon
41cdc5cd5b BooleanOptionalAction 2026-01-20 11:38:26 +09:00
Lee Dogeon
876d3f5e80 Correct testcase 2026-01-20 11:38:26 +09:00
Lee Dogeon
fe6a60ade7 Fix error lines extraction 2026-01-20 11:38:26 +09:00
Jeong, YunWon
d119c47d2e Remake update_lib 2026-01-20 11:38:26 +09:00
github-actions[bot]
6f41a9491b Auto-format: cargo fmt --all 2026-01-20 10:59:47 +09:00
Jeong, YunWon
1740b083b8 namespace constructor and __replace__ 2026-01-20 10:59:47 +09:00
Jeong, YunWon
1dceb7533d mark failing tests on test_types 2026-01-20 10:59:47 +09:00
Jeong, YunWon
301ff32a59 mark failing test_dataclasses 2026-01-20 10:59:47 +09:00
CPython Developers
2823053614 Update test_types from v3.14.2 2026-01-20 10:59:47 +09:00
CPython Developers
a7a823daaa Update typing from v3.14.2 2026-01-20 10:59:47 +09:00
Jeong, YunWon
700b34adeb Hashable for PyMappingProxy 2026-01-20 10:59:47 +09:00
Jeong, YunWon
bb72418d9e _typing.Union 2026-01-20 10:59:47 +09:00
Jeong, YunWon
2bbb3d07c6 _abc 2026-01-20 10:59:47 +09:00
Jeong, YunWon
ef2c0a6d9d More FromArgs message (#6806) 2026-01-20 10:37:27 +09:00
Jeong, YunWon
97167ab1cc Instruction 3.14 (#6805)
* renumber enum Instruction

* renumber magic

* Update test__opcode from 3.14.2

---------

Co-authored-by: CPython Devleopers <>
2026-01-20 03:52:52 +09:00
Jeong, YunWon
b76906a8bf Add sys._stdlib_dir (#6798) 2026-01-20 03:38:40 +09:00
dependabot[bot]
7d2f284ee6 Bump cranelift from 0.127.1 to 0.127.2 (#6802)
Bumps [cranelift](https://github.com/bytecodealliance/wasmtime) from 0.127.1 to 0.127.2.
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.127.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-20 02:16:24 +09:00
Jeong, YunWon
2da102fab8 FromArgs with error_msg (#6804) 2026-01-20 02:10:19 +09:00
dependabot[bot]
e5720232e1 Bump chrono from 0.4.42 to 0.4.43 (#6803)
Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.42 to 0.4.43.
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.42...v0.4.43)

---
updated-dependencies:
- dependency-name: chrono
  dependency-version: 0.4.43
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-20 01:43:11 +09:00
dependabot[bot]
aff85c87ce Bump junction from 1.3.0 to 1.4.1 (#6801)
Bumps [junction](https://github.com/tesuji/junction) from 1.3.0 to 1.4.1.
- [Release notes](https://github.com/tesuji/junction/releases)
- [Changelog](https://github.com/tesuji/junction/blob/main/CHANGELOG.md)
- [Commits](https://github.com/tesuji/junction/compare/v1.3.0...v1.4.1)

---
updated-dependencies:
- dependency-name: junction
  dependency-version: 1.4.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-20 01:42:55 +09:00
dependabot[bot]
b7f55decbd Bump cranelift-jit from 0.127.1 to 0.127.2 (#6800)
Bumps [cranelift-jit](https://github.com/bytecodealliance/wasmtime) from 0.127.1 to 0.127.2.
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift-jit
  dependency-version: 0.127.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-20 01:06:56 +09:00
Jeong, YunWon
82a8f67c71 Replace custom opcodes with CPython standard sequences (#6794)
* Replace custom opcodes with standard sequences

Remove RustPython-specific opcodes (BuildListFromTuples,
BuildMapForCall, BuildSetFromTuples, BuildTupleFromTuples)
and replace their usage with CPython 3.14 standard opcode
sequences:

- BuildListFromTuples → BUILD_LIST + LIST_EXTEND loop
- BuildSetFromTuples → BUILD_SET + SET_UPDATE loop
- BuildTupleFromTuples → BUILD_LIST + LIST_EXTEND + CALL_INTRINSIC_1(ListToTuple)
- BuildMapForCall → DICT_MERGE loop

Implement missing opcodes:
- ListExtend: Extend list with iterable elements
- SetUpdate: Add iterable elements to set
- DictMerge: Merge dict with duplicate key checking

* Auto-generate: generate_opcode_metadata.py

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-20 00:34:46 +09:00
Jeong, YunWon
d7a885cea8 sys._clear_type_descriptors (#6795) 2026-01-19 16:43:20 +09:00
Jeong, YunWon
6a064aad3b Drop for PySSLSocket (#6791) 2026-01-19 10:01:11 +09:00
Lee Dogeon
4ab6a45405 Use stdlib native modules in benchmarks (#6792)
Change benchmark interpreter from without_stdlib to with_init to load
Rust-optimized native modules like _json, ensuring benchmarks measure
actual optimized performance rather than pure Python fallbacks.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 08:43:25 +09:00
Jiseok CHOI
00440b179a Update sqlite3 and the tests to CPython 3.14.2 (#6787)
* Update sqlite3, dbm.sqlite3 and tests to CPython 3.14.2

* Add skip decorators for failing sqlite3 tests

Skip tests that fail due to unimplemented features or behavior differences:
- _iterdump not implemented (test_dump.py)
- Unraisable exception handling not implemented (test_hooks.py, test_userfunctions.py)
- Keyword-only arguments not supported for various methods
- Autocommit behavior differences (test_transactions.py)
- TransactionTests skipped due to timeout parameter type issue
- Various error message differences (test_dbapi.py)
- SQLITE_DBCONFIG constants not implemented
- Row and Connection signature inspection issues

All tests now pass with 95 skipped out of 493 total tests.

* Change @unittest.skip to @unittest.expectedFailure per code review

- Convert @unittest.skip decorators to @unittest.expectedFailure for tests that fail without panic/hang
- Keep @unittest.skip only for TransactionTests class (setUp fails with timeout=0 int type)

* fixup
2026-01-19 02:45:47 +09:00
Jeong, YunWon
130bb82a43 LoadClosure as pseudo op (#6789) 2026-01-19 02:45:00 +09:00
Lee Dogeon
9b5eefbb7b Replace _compression with compression and update related too (#6788) 2026-01-19 00:38:51 +09:00
Jeong, YunWon
0717b53123 Align CallFunctionEx to 3.14 (#6786) 2026-01-19 00:37:18 +09:00
Lee Dogeon
ed785e3d86 Bump base64 to 3.14.2 (#6776) 2026-01-19 00:04:06 +09:00
Jeong, YunWon
3a9f020234 update test_sys from 3.14.2 (#6781)
* sys.is_remote_debug_enabled, supports_isolated_interpreters

* Update test_sys form Python 3.14.2

---------

Co-authored-by: CPython Devleopers <>
2026-01-18 23:58:39 +09:00
Jiseok CHOI
050db4725f sqlite3: fix Connection.cursor() factory argument handling (#6783)
Fix test_is_instance in CursorFactoryTests by properly handling the
factory argument in Connection.cursor() method. Now the factory can
be passed as both positional and keyword argument, and returns the
correct subclass type instead of always returning PyRef<Cursor>.

- Use FromArgs derive macro with CursorArgs struct for argument parsing
- Return PyObjectRef instead of PyRef<Cursor> to allow subclasses
- Use fast_issubclass to validate returned cursor is a Cursor subclass
- Properly differentiate between 'no argument' and 'None passed'
2026-01-18 23:37:47 +09:00
Jeong, YunWon
9301ae2746 traverse and clear (#6780) 2026-01-18 23:23:11 +09:00
Jeong, YunWon
2b8fac3af3 auto mark parent tests (#6778)
* don't skip auto-format

* auto mark parent
2026-01-18 22:06:07 +09:00
Jeong, YunWon
252fa816d6 sys._jit (#6779) 2026-01-18 21:54:44 +09:00
Lee Dogeon
4b5e73577a Add metadata when uploading benchmark data (#6759)
Generate a metadata file alongside criterion benchmark data containing
the commit hash, ref name, and timestamp for tracking purposes.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 21:51:39 +09:00
Jeong, YunWon
d3d63ea2d3 enable test_bytes (#6777) 2026-01-18 21:33:37 +09:00
Jeong, YunWon
6f266651c0 better ssl write handling (#6763)
* ssl_write

* Fix thread count timing
2026-01-18 21:10:35 +09:00
Jeong, YunWon
e0479fe197 Merge pull request #6768 from youknowone/support
Update support to 3.14.2
2026-01-18 20:36:04 +09:00
Jeong, YunWon
e0b19c833c skip flaky test 2026-01-18 20:33:12 +09:00
Jeong, YunWon
8f7b1343bc mark and unmark successful/failing tests 2026-01-18 20:00:15 +09:00
Jeong, YunWon
3836958eaa Make ready_to_import always remove tempdir from sys.path (re-apply #6687) 2026-01-18 20:00:14 +09:00
CPython Devleopers
005014a3f9 Update test.support from 3.14.2 2026-01-18 19:56:55 +09:00
Jeong, YunWon
e0185aefb1 mark failing tests 2026-01-18 19:56:54 +09:00
CPython Devleopers
dfed341ec8 Upgrade unittest from 3.14.2 2026-01-18 19:56:54 +09:00
Lee Dogeon
5242ff5243 Bump json to 3.14.2 (#6774) 2026-01-18 19:16:48 +09:00
Jeong, YunWon
e8dd5826e6 init warnings before site (#6771) 2026-01-18 19:16:02 +09:00
Jeong, YunWon
f8a78e6ab6 stack soft limit (#6754) 2026-01-18 18:09:55 +09:00
Jeong, YunWon
941a7bb784 setup ndk on CI (#6773) 2026-01-18 18:02:57 +09:00
Jeong, YunWon
1ccd99ea20 use ast namespace (#6769) 2026-01-18 17:30:36 +09:00
Jeong, YunWon
eb50246b41 fix annotation (#6767) 2026-01-18 15:24:17 +09:00
Jeong, YunWon
7c7b824aa9 fix asyncgen finalizer (#6761) 2026-01-18 14:18:30 +09:00
fanninpm
e4ce70bbda Update Lib/warnings to CPython 3.14 (#6762)
* Update Lib/warnings to CPython 3.14

* Add context_aware_warnings setting

XXX- The default setting of this and thread_inherit_context should be
true.

* Unmark passing test

* Mark failing tests

* Skip failing test in test_sys for now

Updating test_sys to CPython 3.14 is beyond the scope of this PR.

* test_improper_option is fixed

---------

Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
2026-01-18 13:59:49 +09:00
Jeong, YunWon
96e08a425e Initialize warnings module during interpreter startup to process (#6766) 2026-01-18 13:15:40 +09:00
Jeong, YunWon
6616961d08 skip flaky tests (#6764) 2026-01-18 11:16:25 +09:00
Jeong, YunWon
abea6bd114 traverse for generator (#6760) 2026-01-18 09:36:09 +09:00
Jeong, YunWon
ca76cb7bb0 thread_inherit_context, upgrade threading & contextvar (#6727)
* thread_inherit_context

* Update contextvar, threading from CPython 3.14.2

* partially patch test_sys to 3.14.2

---------

Co-authored-by: CPython Devleopers <>
2026-01-18 08:53:41 +09:00
Jeong, YunWon
11c9b0e783 fix finalizing and atexit timing (#6626)
* fix finalizing and atexit timing

* fix shutdown
2026-01-18 01:54:16 +09:00
Shahar Naveh
8ce5f49908 Update graphlib, heapq, ipaddress to 3.14.2 (#6758) 2026-01-18 01:23:34 +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
Shahar Naveh
892116c009 Add some compiler tests from 3.13.11 (#6752)
* Add some compiler tests from 3.13.11

* Unmark passing test
2026-01-18 00:26:06 +09:00
Shahar Naveh
6dd5e36d02 Remove misleading placeholder comments (#6757) 2026-01-17 22:53:00 +09:00
Lee Dogeon
3d86b26caf Complement upgrade-pylib Claude Code command (#6742)
* Insert unittest import line if it doesn't exist

* Complement upgrade-pylib Claude Code command

* Ensure test module having import statement at least one
2026-01-17 21:54:16 +09:00
Jeong, YunWon
4eb49491a3 Change dockerfile to be available on aarch64 (#6751) 2026-01-17 21:53:13 +09:00
Jeong, YunWon
c490a357fd relocate scripts (#6753) 2026-01-17 21:52:53 +09:00
Jeong, YunWon
273c5a349b Merge pull request #6718 from youknowone/py-3.14
RustPython version to 3.14
2026-01-17 20:58:23 +09:00
github-actions[bot]
60fb4384e1 Auto-format: ruff check --select I --fix 2026-01-17 10:34:53 +00:00
Jeong, YunWon
faeed2cdcc clean up 2026-01-17 19:22:18 +09:00
Jeong, YunWon
133bdf655e auto_mark_test uses regex to check Run tests? sequentially 2026-01-17 19:22:18 +09:00
CPython Devleopers
314a61562c Update calendar from CPython 3.14.2 2026-01-17 19:22:00 +09:00
CPython Devleopers
d75f272c8b Update argparse from CPython 3.14.2 2026-01-17 19:22:00 +09:00
CPython Devleopers
ef22bf4774 Update _colorize from CPython 3.14.2 2026-01-17 19:22:00 +09:00
CPython Devleopers
65e08c02b6 Update ensurepip from 3.14.2 2026-01-17 19:22:00 +09:00
Jeong, YunWon
33689c1d0f Fix jit failure 2026-01-17 19:22:00 +09:00
Jeong, YunWon
522793850a mark and unmark unittest functions 2026-01-17 19:21:38 +09:00
CPython Devleopers
076d692b42 Upgrade string from CPython 3.14.2 2026-01-17 19:21:11 +09:00
Jeong, YunWon
346481d95e partially patch Lib/typing to 3.14 2026-01-17 19:21:11 +09:00
Jeong, YunWon
96038e48c5 partially patch inspect for PEP 649 in 3.13 2026-01-17 19:21:11 +09:00
Jeong, YunWon
37cc6b44f9 fix whats_left to support __annotate__ 2026-01-17 19:21:11 +09:00
Jeong, YunWon
dc93614f5a Add annotationlib,ann_module from 3.14.2
also partially update test_module
2026-01-17 19:21:11 +09: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
353a9f6104 PEP 649 annotation phase 2 2026-01-17 19:21:11 +09:00
Jeong, YunWon
51b628642c PEP 649 annotation phase 1 2026-01-17 19:21:11 +09:00
Jeong, YunWon
fdfede7545 fix win clippy 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
280caea579 upgrade venvlauncher 2026-01-17 19:21:10 +09:00
Jeong, YunWon
7594ef5121 upgrade site to 3.14.2 2026-01-17 19:21:10 +09:00
Jeong, YunWon
ea1e60e9ca mark version to 3.14 2026-01-17 19:21:10 +09:00
Jeong, YunWon
299f1ea0aa skip flaky test_concurrent_futures.test_process_pool.test_ressources_gced_in_workers (#6750) 2026-01-17 19:18:54 +09:00
Jeong, YunWon
f4363a6b27 PEP 750 tstring (#6744) 2026-01-17 18:41:40 +09:00
Jeong, YunWon
02cc257b42 Support pickle better with __getnewargs_ex__ (#6749)
* Implement pickle more

* add weakref check

* check exports in __setstate__

* remove reducelib
2026-01-17 18:37:16 +09:00
Terry Tianlin Luan
833f7343c8 Update email library v3.13.11 (#6642)
* Updated the email library + added test suite

* Added Windows altzone + Fixed memory error in `bytes_inner.rs`
2026-01-17 18:15:35 +09:00
Jeong, YunWon
c934265304 rename fix_test and support removing unexpected success (#6748)
* fix_test to remove unexpected success

* rename fix_test

* Auto-format: ruff format

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-17 00:11:20 +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
Shahar Naveh
380fa39eba Bytecode instrumented placeholder (#6741)
* Add all other bytecodes

* Mark passing/failing tests
2026-01-16 23:08:06 +09:00
Terry Tianlin Luan
4cb3b9d8f0 Updated the urllib + http libraries + test libraries (#6672)
* Updated urllib + urllib tests

* Updated http + test

* Annotated failing tests

* Fixed issues in httpservers, robotparser and urllib2net

* Fixed windows only success

* Annotated flaky test in test_logging
2026-01-16 23:03:49 +09:00
Lee Dogeon
ef871d227e Update json module to 3.13.11 (#6743) 2026-01-16 21:38:15 +09:00
Jeong, YunWon
746e71af87 reject SemLock reduce (#6738) 2026-01-16 10:18:31 +09:00
Jeong, YunWon
a0ace054f3 Fix asyncio compile (#6739) 2026-01-16 09:12:16 +09:00
Terry Tianlin Luan
609dbb1439 Downgraded skips in tests (#6716)
* Downgraded skips in tests

* Fixed failing tests

* Fixed test_ftplib + test_socket + test_ssl + test_threaded_import failures

* Removed comments about which tests are run in which environment

* Addressed PR comments

* Annotated skips on failing tests

* Removed unneeded tests

* Removed unneeded sys import from test_ftplib

* Added annotation to test_ftplib

* Readded skipIf to test_cleanup_with_symlink_modes with a more general ENV_POLLUTING_TESTS_WINDOWS

* Addressed PR comments

* Made changes to minimize diff in PR

* Apply suggestion from @youknowone

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2026-01-15 21:43:22 +09:00
Lee Dogeon
3a702ac772 Improve json.loads performance (#6704)
* Parse JSON in Rust

* Reuse key when decoding JSON

* Unmark resolved test

* Parse null/true/false directly in call_scan_once

Parse JSON constants (null, true, false) directly in Rust within
call_scan_once() instead of falling back to Python scan_once.
This reduces Python-Rust boundary crossings for array/object values.

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

* Parse numbers directly in call_scan_once

Parse JSON numbers starting with digits (0-9) directly in Rust within
call_scan_once() by reusing the existing parse_number() method.
This reduces Python-Rust boundary crossings for array/object values.

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

* Parse NaN/Infinity/-Infinity in call_scan_once

Parse special JSON constants (NaN, Infinity, -Infinity) and negative
numbers directly in Rust within call_scan_once(). This handles:
- 'N' -> NaN via parse_constant callback
- 'I' -> Infinity via parse_constant callback
- '-' -> -Infinity or negative numbers via parse_constant/parse_number

This reduces Python-Rust boundary crossings for array/object values.

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

* Correct wrong index access

* Leave more flame span

* Refactor json scanstring with byte index

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 19:53:46 +09:00
Terry Tianlin Luan
c5deb740ac Update asyncio library (#6601)
* Updated asyncio to v3.13.11

* Removed expectedFailure from `test_async_case.py`
2026-01-15 17:35:01 +09:00
dependabot[bot]
a3d1b5e7ac Bump xml from 1.2.0 to 1.2.1 (#6730)
Bumps [xml](https://github.com/kornelski/xml-rs) from 1.2.0 to 1.2.1.
- [Changelog](https://github.com/kornelski/xml-rs/blob/main/Changelog.md)
- [Commits](https://github.com/kornelski/xml-rs/compare/1.2.0...1.2.1)

---
updated-dependencies:
- dependency-name: xml
  dependency-version: 1.2.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-15 17:21:22 +09:00
dependabot[bot]
2a2caa1897 Bump rand_core from 0.9.4 to 0.9.5 (#6731)
Bumps [rand_core](https://github.com/rust-random/rand) from 0.9.4 to 0.9.5.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/commits)

---
updated-dependencies:
- dependency-name: rand_core
  dependency-version: 0.9.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-15 17:20:34 +09:00
Jeong, YunWon
c06701abc8 skip test_multiprocessing_{fork,spawn}.test_threads.py (#6735) 2026-01-15 14:29:41 +09:00
Jeong, YunWon
b214362ca1 remove polluting tests (#6733) 2026-01-15 08:36:56 +09:00
Shahar Naveh
e3890f9b4a Bytecode pseudo opcodes (#6715) 2026-01-15 02:52:25 +09:00
Jeong, YunWon
13a875f609 fix backslash handling in fix_test.py (#6729) 2026-01-15 00:01:14 +09:00
Jeong, YunWon
7a516c44c9 Update AI docs (#6728)
* update copilot instructions

* upgrade-pylib command
2026-01-14 23:51:41 +09:00
Jeong, YunWon
3d4aaaa6c1 thread.setname and context (#6726) 2026-01-14 17:20:52 +09:00
Jeong, YunWon
81d89d1d90 Fix flaky multiprocessing tests (#6725) 2026-01-14 16:59:10 +09:00
Lee Dogeon
2e5257d098 Introduce benchmark for json.loads (#6723) 2026-01-14 14:44:34 +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
Lee Dogeon
49e6931c7e Introduce flame_guard in rustpython-stdlib too (#6722) 2026-01-14 09:14:05 +09:00
Shahar Naveh
9eeea925c7 Move OpArg to its own file (#6703)
* Move OpArg to its own file

* Fix merge

* Fix more merge
2026-01-14 08:58:49 +09:00
Jeong, YunWon
bb57724d3b flush on WantWrite (#6717) 2026-01-13 22:05:49 +09:00
Jeong, YunWon
f9e2f9d273 Upgrade math,cmath to 3.14.2 and totally delegate to pymath (#6705)
* Upgrade test_math, test_cmath from 3.14.2

* pymath 0.1.5
2026-01-13 22:05:32 +09:00
Jeong, YunWon
e91bc11b0a Fix dict race condition (#6720) 2026-01-13 21:27:24 +09:00
Jeong, YunWon
4d7a289971 fix lib_update backslash support (#6719) 2026-01-13 19:02:34 +09:00
dependabot[bot]
7e47212886 Bump flate2 from 1.1.5 to 1.1.8 (#6711)
Bumps [flate2](https://github.com/rust-lang/flate2-rs) from 1.1.5 to 1.1.8.
- [Release notes](https://github.com/rust-lang/flate2-rs/releases)
- [Commits](https://github.com/rust-lang/flate2-rs/compare/1.1.5...1.1.8)

---
updated-dependencies:
- dependency-name: flate2
  dependency-version: 1.1.8
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-13 17:19:38 +09:00
dependabot[bot]
10f14fdedd Bump rand_core from 0.9.3 to 0.9.4 (#6714)
Bumps [rand_core](https://github.com/rust-random/rand) from 0.9.3 to 0.9.4.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/commits)

---
updated-dependencies:
- dependency-name: rand_core
  dependency-version: 0.9.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-13 10:43:06 +09:00
dependabot[bot]
1bb3439711 Bump winresource from 0.1.28 to 0.1.29 (#6713)
Bumps [winresource](https://github.com/BenjaminRi/winresource) from 0.1.28 to 0.1.29.
- [Commits](https://github.com/BenjaminRi/winresource/commits)

---
updated-dependencies:
- dependency-name: winresource
  dependency-version: 0.1.29
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-13 10:42:55 +09:00
Jeong, YunWon
69601a18a4 Upgrade threading to 3.13.11; sys.setprofile & impl more threading (#6691)
* Upgrade threading,test_threading from 3.13.11

* increase ci limit to 45mins

* impl more threading

* no static for asyncgen
2026-01-12 15:33:28 +09:00
Shahar Naveh
00bfea83bf Update ruff to 0.14.11 in the CI (#6708)
* Update ruff to 0.14.11 in the CI

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-12 10:52:15 +09:00
Lee Dogeon
f3b7f7fd47 Clarify commit message from pr-auto-commit (#6706)
* Clarify commit message from pr-auto-commit

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-12 08:08:50 +09:00
Jeong, YunWon
29bb8b47cd Super instructions (#6694)
* super instructions

* Fix classcell

* ZeroArg
2026-01-11 17:59:32 +09:00
Jeong, YunWon
12f08d6ed5 Merge pull request #6698 from youknowone/quick-import
preparing step to integrate fix_test into lib_updater
2026-01-11 17:20:14 +09:00
Jeong YunWon
f2d5594288 fix_test --quick-import 2026-01-11 16:48:21 +09:00
Jeong, YunWon
1d95a04ac8 Update test/libregrtest to CPython 3.13.10 (#6410)
* Update test/libregrtest to CPython 3.13.10

* Re-add try block around platform and encodings info

* Disable WindowsLoadTracker on Windows

* Disable struct._clearcache()

* Disable saved_test_environment context manager

* Disable support.record_original_stdout()

* Update test/test_regrtest.py to CPython 3.13.11

* Add autotest shim from CPython 3.13.11

* Mark failing tests and skip flaky ones in test/test_regrtest.py

* Mark failing test in test_fstring

* Add _test_eintr.py from CPython 3.13.11

* Skip long-running test in _test_eintr

* Mark failing/erroring tests in _test_eintr

* Skip panicking tests in test_io

* Unmark passing tests in test_io

* Mark failing test in test_urllib2net

* Unmark passing test in test_fstring

* Time out if any one test takes longer than 10 minutes

* Skip more flaky tests in test_threading

* Skip tests that pollute the environment for some reason

* Skip flaky tests in test.test_multiprocessing_fork.test_misc

* Skip flaky tests in test.test_multiprocessing_fork.test_manager

Had to go with the nuclear option.

* Skip flaky tests in test_regrtest

* Mark flaky tests in test_ftplib

* Fix multiprocessing tests on Darwin

* Remove test_sys from list of environment polluters

* Remove test_ftplib from list of environment polluters

* Add test.test_multiprocessing_fork.test_misc to list of environment
polluters

* Check 10 times if a test is still polluting the environment

* Save more of the test environment before a test is run

* Mark test_import as polluting the environment

* Unmark passing test in test_regrtest

* Mark flaky test in test_regrtest

* Remove tests from list of environment polluters

* Skip flaky test in test_logging

* Remove tests from list of polluting tests

* Skip certain problematic tests in test_threading

* Skip test causing worker bug in test_builtin

* Make env polluter skip in test_threading os-agnostic

* Remove test_file_eintr from list of polluters

* Remove test_subprocess from the list of polluters

* Address coderabbit comments

* fix threading._dangling

* Skip environment polluter in test.test_concurrent_futures.test_thread_pool

* Make skip in test_thread_pool os-agnostic

* Skip problematic tests in test_wait

* Skip flaky tests in test_process_pool

* Remove test_import from list of polluters

* Amend skips in test.test_multiprocessing_forkserver.test_processes

* Remove test_raise from list of polluters

* Remove test_ssl from list of polluters

* Skip flaky test in test_ssl

* Fix YAML formatting issue

---------

Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
2026-01-11 16:19:34 +09:00
Padraic Fanning
1dcded40b8 Fix YAML formatting issue 2026-01-10 22:52:29 -05:00
Padraic Fanning
7445b27083 Skip flaky test in test_ssl 2026-01-10 22:10:35 -05:00
Padraic Fanning
f9a1f2bda8 Remove test_ssl from list of polluters 2026-01-10 22:10:35 -05:00
Padraic Fanning
8d505dc0e5 Remove test_raise from list of polluters 2026-01-10 22:10:35 -05:00
Padraic Fanning
80af69e625 Amend skips in test.test_multiprocessing_forkserver.test_processes 2026-01-10 22:10:35 -05:00
Padraic Fanning
717265a59a Remove test_import from list of polluters 2026-01-10 22:10:35 -05:00
Padraic Fanning
daaae22077 Skip flaky tests in test_process_pool 2026-01-10 22:10:35 -05:00
Padraic Fanning
1642959b92 Skip problematic tests in test_wait 2026-01-10 22:10:35 -05:00
Padraic Fanning
1c07d3545e Make skip in test_thread_pool os-agnostic 2026-01-10 22:10:35 -05:00
Padraic Fanning
ae6deb7437 Skip environment polluter in test.test_concurrent_futures.test_thread_pool 2026-01-10 22:10:35 -05:00
Jeong, YunWon
def6974bf6 fix threading._dangling 2026-01-10 22:10:35 -05:00
Padraic Fanning
e6d2ba06b1 Address coderabbit comments 2026-01-10 22:10:35 -05:00
Padraic Fanning
a09ed1bf97 Remove test_subprocess from the list of polluters 2026-01-10 22:10:35 -05:00
Padraic Fanning
55c309669b Remove test_file_eintr from list of polluters 2026-01-10 22:10:35 -05:00
Padraic Fanning
d1e75c0ee0 Make env polluter skip in test_threading os-agnostic 2026-01-10 22:10:35 -05:00
Padraic Fanning
98d8ebcc1d Skip test causing worker bug in test_builtin 2026-01-10 22:10:35 -05:00
Padraic Fanning
b76c0a20a8 Skip certain problematic tests in test_threading 2026-01-10 22:10:35 -05:00
Padraic Fanning
d170b0281f Remove tests from list of polluting tests 2026-01-10 22:10:35 -05:00
Padraic Fanning
12811eb40c Skip flaky test in test_logging 2026-01-10 22:10:35 -05:00
Padraic Fanning
8765d86355 Remove tests from list of environment polluters 2026-01-10 22:10:35 -05:00
Padraic Fanning
40da80714c Mark flaky test in test_regrtest 2026-01-10 22:10:35 -05:00
Padraic Fanning
2769c08a0d Unmark passing test in test_regrtest 2026-01-10 22:10:35 -05:00
Padraic Fanning
0a826731cb Mark test_import as polluting the environment 2026-01-10 22:10:35 -05:00
Padraic Fanning
59b80e30ed Save more of the test environment before a test is run 2026-01-10 22:10:35 -05:00
Padraic Fanning
0d128ccc28 Check 10 times if a test is still polluting the environment 2026-01-10 22:10:35 -05:00
Padraic Fanning
3427215611 Add test.test_multiprocessing_fork.test_misc to list of environment
polluters
2026-01-10 22:10:35 -05:00
Padraic Fanning
99168e076c Remove test_ftplib from list of environment polluters 2026-01-10 22:10:35 -05:00
Padraic Fanning
9500f6609b Remove test_sys from list of environment polluters 2026-01-10 22:10:35 -05:00
Padraic Fanning
55c71aa0ee Fix multiprocessing tests on Darwin 2026-01-10 22:10:35 -05:00
Padraic Fanning
dc9475c26b Mark flaky tests in test_ftplib 2026-01-10 22:10:35 -05:00
Padraic Fanning
34fe0f2770 Skip flaky tests in test_regrtest 2026-01-10 22:10:35 -05:00
Padraic Fanning
3aa6bf8696 Skip flaky tests in test.test_multiprocessing_fork.test_manager
Had to go with the nuclear option.
2026-01-10 22:10:35 -05:00
Padraic Fanning
e831124a21 Skip flaky tests in test.test_multiprocessing_fork.test_misc 2026-01-10 22:10:35 -05:00
Padraic Fanning
1827af100b Skip tests that pollute the environment for some reason 2026-01-10 22:10:35 -05:00
Padraic Fanning
17cc559dd3 Skip more flaky tests in test_threading 2026-01-10 22:10:35 -05:00
Padraic Fanning
472c12cad7 Time out if any one test takes longer than 10 minutes 2026-01-10 22:10:35 -05:00
Padraic Fanning
8d2b215ccb Unmark passing test in test_fstring 2026-01-10 22:10:35 -05:00
Padraic Fanning
8aafbf2bf7 Mark failing test in test_urllib2net 2026-01-10 22:10:35 -05:00
Padraic Fanning
cadac344a7 Unmark passing tests in test_io 2026-01-10 22:10:35 -05:00
Padraic Fanning
c76e72571e Skip panicking tests in test_io 2026-01-10 22:10:35 -05:00
Padraic Fanning
1f56a0fe0c Mark failing/erroring tests in _test_eintr 2026-01-10 22:10:35 -05:00
Padraic Fanning
bedcb225e7 Skip long-running test in _test_eintr 2026-01-10 22:10:35 -05:00
Padraic Fanning
4a559f3ea4 Add _test_eintr.py from CPython 3.13.11 2026-01-10 22:10:35 -05:00
Padraic Fanning
2789ff7a9f Mark failing test in test_fstring 2026-01-10 22:10:35 -05:00
Padraic Fanning
4c833fc714 Mark failing tests and skip flaky ones in test/test_regrtest.py 2026-01-10 22:10:35 -05:00
Padraic Fanning
404836f187 Add autotest shim from CPython 3.13.11 2026-01-10 22:10:35 -05:00
Padraic Fanning
32fd6bec49 Update test/test_regrtest.py to CPython 3.13.11 2026-01-10 22:10:35 -05:00
Padraic Fanning
e4fb263788 Disable support.record_original_stdout() 2026-01-10 22:10:35 -05:00
Padraic Fanning
a8e7633f58 Disable saved_test_environment context manager 2026-01-10 22:10:35 -05:00
Padraic Fanning
f436c51ef2 Disable struct._clearcache() 2026-01-10 22:10:35 -05:00
Padraic Fanning
08762a35c2 Disable WindowsLoadTracker on Windows 2026-01-10 22:10:35 -05:00
Padraic Fanning
5d253d1ec0 Re-add try block around platform and encodings info 2026-01-10 22:10:35 -05:00
Padraic Fanning
f297888317 Update test/libregrtest to CPython 3.13.10 2026-01-10 22:10:35 -05:00
Shahar Naveh
440b8de763 Move Instruction enum to its own file (#6693)
* Move `Instruction` to its own file

* Fix codegen and frame.rs

* Adjust script
2026-01-11 10:04:24 +09:00
Jeong YunWon
2a1faf4265 integrate to lib_updater 2026-01-11 00:47:06 +09:00
Jeong, YunWon
3909b18eac lib_updater --quick-upgrade (#6695) 2026-01-11 00:11:41 +09:00
Shahar Naveh
6ff7b3ed27 LoadClassDeref -> LoadFromDictOrDeref (#6692) 2026-01-10 23:16:11 +09:00
Shahar Naveh
a400386774 Remove _dis module (#6690)
* Remove `_dis` module

* Adjust CodeFlag
2026-01-10 22:11:53 +09:00
Jeong, YunWon
9e225f52e2 impl gc finialized (#6689)
* impl gc finialized

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-10 19:50:25 +09:00
Jeong, YunWon
aa9fc7fede Pseudo ops (#6678)
* better expect

* pseudo instruction

* Fix CallKw narg

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-10 19:49:58 +09:00
Jeong, YunWon
2d3ef86231 fix SSL callback (#6688)
* fix SSL callback

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-10 19:49:40 +09:00
Shahar Naveh
6fe05987f0 Remove Reverse bytecode (#6675)
* Remove `Reverse` bytecode

* Update crates/compiler-core/src/bytecode.rs

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

* Gen

* Remove Reverse

* Auto-format: cargo fmt --all

* Revert comment

* Remove debug code

* Fix CI

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-10 18:55:15 +09:00
Shahar Naveh
9291178b01 Ci gen opcode metadata (#6677)
* Autogen opcode metadata

* Manually modify opcode metadata
2026-01-10 17:33:11 +09:00
Terry Tianlin Luan
8c157990cf Updated test_contextlib_async.py (#6686) 2026-01-10 16:38:21 +09:00
Jeong, YunWon
e835ce9275 Make ready_to_import always remove tempdir from sys.path (#6687) 2026-01-10 16:32:26 +09:00
Lee Dogeon
0cd6eb7b13 Write profile even if failed (#6685) 2026-01-10 15:26:49 +09:00
dependabot[bot]
53feed5920 Bump libc from 0.2.179 to 0.2.180 (#6683)
* Bump libc from 0.2.179 to 0.2.180

Bumps [libc](https://github.com/rust-lang/libc) from 0.2.179 to 0.2.180.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Changelog](https://github.com/rust-lang/libc/blob/0.2.180/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.179...0.2.180)

---
updated-dependencies:
- dependency-name: libc
  dependency-version: 0.2.180
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix musl compatibility in libc 0.2.180 bump (#6684)

* Bump libc from 0.2.179 to 0.2.180

Bumps [libc](https://github.com/rust-lang/libc) from 0.2.179 to 0.2.180.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Changelog](https://github.com/rust-lang/libc/blob/0.2.180/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.179...0.2.180)

---
updated-dependencies:
- dependency-name: libc
  dependency-version: 0.2.180
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Initial plan

* Revert os.rs changes by removing newly added files

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

* Fix musl compatibility by removing target_env musl from cfg

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

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@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>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2026-01-10 15:10:18 +09:00
dependabot[bot]
95f5a5b240 Bump cranelift from 0.127.0 to 0.127.1 (#6680)
Bumps [cranelift](https://github.com/bytecodealliance/wasmtime) from 0.127.0 to 0.127.1.
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift
  dependency-version: 0.127.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-10 09:33:40 +09:00
dependabot[bot]
91f0d70c0c Bump syn from 2.0.113 to 2.0.114 (#6679)
Bumps [syn](https://github.com/dtolnay/syn) from 2.0.113 to 2.0.114.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/2.0.113...2.0.114)

---
updated-dependencies:
- dependency-name: syn
  dependency-version: 2.0.114
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-10 08:30:42 +09:00
dependabot[bot]
f2224de8d7 Bump cranelift-jit from 0.127.0 to 0.127.1 (#6682)
Bumps [cranelift-jit](https://github.com/bytecodealliance/wasmtime) from 0.127.0 to 0.127.1.
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

---
updated-dependencies:
- dependency-name: cranelift-jit
  dependency-version: 0.127.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-10 08:26:41 +09:00
dependabot[bot]
d4be424bf6 Bump indexmap from 2.12.1 to 2.13.0 (#6681)
Bumps [indexmap](https://github.com/indexmap-rs/indexmap) from 2.12.1 to 2.13.0.
- [Changelog](https://github.com/indexmap-rs/indexmap/blob/main/RELEASES.md)
- [Commits](https://github.com/indexmap-rs/indexmap/compare/2.12.1...2.13.0)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-version: 2.13.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-10 08:26:12 +09:00
Jeong, YunWon
de0bc732c9 Replace CallMethod/LoadMethod opcodes with plain Call (#6674)
* implementing call the correct way

stack is [Option<PyObjectRef>]

* fix again

* list custom instructions

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-10 08:25:56 +09:00
Shahar Naveh
c2bfdf30bd Assign opcode ids (#6637) 2026-01-09 22:52:47 +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
Terry Tianlin Luan
b38cdaa30e Update the concurrent library + Added tests (#6673)
* Updated concurrent library

* Added test_concurrent_futures from v3.13.11

* Annotated failing tests in test_concurrent_futures
2026-01-09 15:28:12 +09:00
Copilot
a3425b435e Track symbol table cursors to avoid exhaustion (#6670)
* Handle missing symbol table without panic

* Update symbol table error message

* Track symbol table cursors to avoid exhaustion

---------

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>
2026-01-09 06:32:12 +09:00
Noa
bf80d2715d Update to windows-2025 runner on ci (#5571)
* Update to windows-2025 on ci

* Unmark unexpected successes

* Try adding .dll
2026-01-07 12:53:44 +09:00
Noa
09bde28281 Move typeid into vtable (#6231)
* Move typeid into vtable

* Bump rust-version
2026-01-07 12:33:29 +09:00
dependabot[bot]
42cc59a90c Bump openssl-probe from 0.1.6 to 0.2.0 (#6663)
* Bump openssl-probe from 0.1.6 to 0.2.0

Bumps [openssl-probe](https://github.com/alexcrichton/openssl-probe) from 0.1.6 to 0.2.0.
- [Release notes](https://github.com/alexcrichton/openssl-probe/releases)
- [Commits](https://github.com/alexcrichton/openssl-probe/compare/0.1.6...0.2.0)

---
updated-dependencies:
- dependency-name: openssl-probe
  dependency-version: 0.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix openssl-probe 0.2.0 API compatibility (#6669)

* Bump openssl-probe from 0.1.6 to 0.2.0

Bumps [openssl-probe](https://github.com/alexcrichton/openssl-probe) from 0.1.6 to 0.2.0.
- [Release notes](https://github.com/alexcrichton/openssl-probe/releases)
- [Commits](https://github.com/alexcrichton/openssl-probe/compare/0.1.6...0.2.0)

---
updated-dependencies:
- dependency-name: openssl-probe
  dependency-version: 0.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Initial plan

* Fix openssl-probe 0.2.0 API compatibility

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2026-01-07 10:13:13 +09:00
Lee Dogeon
6408228b3e Update DEVELOPMENT.md (#6671)
* Update DEVELOPMENT.md to reflect crates/ directory structure

* Update DEVELOPMENT.md to reflect Ruff parser-related changes
2026-01-07 10:09:51 +09:00
dependabot[bot]
4fbf617c06 Bump quote from 1.0.42 to 1.0.43 (#6667)
Bumps [quote](https://github.com/dtolnay/quote) from 1.0.42 to 1.0.43.
- [Release notes](https://github.com/dtolnay/quote/releases)
- [Commits](https://github.com/dtolnay/quote/compare/1.0.42...1.0.43)

---
updated-dependencies:
- dependency-name: quote
  dependency-version: 1.0.43
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-07 08:54:21 +09:00
dependabot[bot]
985961b013 Bump rustls from 0.23.35 to 0.23.36 (#6666)
Bumps [rustls](https://github.com/rustls/rustls) from 0.23.35 to 0.23.36.
- [Release notes](https://github.com/rustls/rustls/releases)
- [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rustls/rustls/compare/v/0.23.35...v/0.23.36)

---
updated-dependencies:
- dependency-name: rustls
  dependency-version: 0.23.36
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-07 08:54:10 +09:00
dependabot[bot]
8df2df3ed7 Bump webpki-roots from 1.0.4 to 1.0.5 (#6665)
Bumps [webpki-roots](https://github.com/rustls/webpki-roots) from 1.0.4 to 1.0.5.
- [Release notes](https://github.com/rustls/webpki-roots/releases)
- [Commits](https://github.com/rustls/webpki-roots/compare/v/1.0.4...v/1.0.5)

---
updated-dependencies:
- dependency-name: webpki-roots
  dependency-version: 1.0.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-07 08:52:50 +09:00
dependabot[bot]
7becac9a10 Bump proc-macro2 from 1.0.104 to 1.0.105 (#6664)
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.104 to 1.0.105.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.104...1.0.105)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-version: 1.0.105
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-07 08:52:40 +09:00
Terry Tianlin Luan
cd613edc71 Update the zipfile + zipimport libraries + tests - v3.13.11 (#6639)
* Updated zipimport library + test

* Updated zipfile library + test

* Annotated failing/erroring tests in test_zipfile and test_zipimport

* Changed all skips in `test_core.py` to expectedFailures

* skip EncodedMetadataTests

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2026-01-06 21:35:21 +09:00
Copilot
e367145a4a Add Linux pidfd syscalls to expose asyncio pidfd watcher (#6660)
* Add pidfd support syscalls

* Validate pidfd signal range

* Clarify pidfd syscall return handling

* Skip flaky is_alive_after_fork test

---------

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>
2026-01-06 15:10:23 +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
dependabot[bot]
906aebf5a1 Bump malachite-q from 0.8.0 to 0.9.0 (#6653)
* Bump malachite-q from 0.8.0 to 0.9.0

Bumps [malachite-q](https://github.com/mhogrefe/malachite) from 0.8.0 to 0.9.0.
- [Release notes](https://github.com/mhogrefe/malachite/releases)
- [Commits](https://github.com/mhogrefe/malachite/compare/v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: malachite-q
  dependency-version: 0.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump all malachite-* crates from 0.8.0 to 0.9.0 (#6656)

* Initial plan

* Update all malachite-* crates to 0.9.0

* Fix ctypes overflow check for malachite 0.9.0 compatibility

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2026-01-06 12:15:35 +09:00
dependabot[bot]
cf963b74c8 Bump libc from 0.2.178 to 0.2.179 (#6654)
* Bump libc from 0.2.178 to 0.2.179

Bumps [libc](https://github.com/rust-lang/libc) from 0.2.178 to 0.2.179.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Changelog](https://github.com/rust-lang/libc/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.178...0.2.179)

---
updated-dependencies:
- dependency-name: libc
  dependency-version: 0.2.179
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix musl and wasi builds after libc 0.2.179 upgrade (#6655)

* Initial plan

* Fix musl and wasi build failures after libc 0.2.179 upgrade

- Remove wasi-specific implementation of get_process_time that used CLOCK_PROCESS_CPUTIME_ID
- Exclude wasi from CLOCK_PROCESS_CPUTIME_ID constant export
- Add musl and wasi to use st_atim/st_mtim/st_ctim timespec fields for stat structure

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>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2026-01-06 10:07:51 +09:00
Shahar Naveh
ead7e0c39c Make use of Unary opcodes (#6647)
* Make use of `Unary` opcodes

* Add `Reserved140` opcode

* re-add support for UnaryPositive in JIT

* JIT support for `ToBool` instruction
2026-01-05 23:40:41 +09:00
dependabot[bot]
85bafc057a Bump syn from 2.0.112 to 2.0.113 (#6652)
Bumps [syn](https://github.com/dtolnay/syn) from 2.0.112 to 2.0.113.
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/2.0.112...2.0.113)

---
updated-dependencies:
- dependency-name: syn
  dependency-version: 2.0.113
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-05 22:53:46 +09:00
dependabot[bot]
ab885d37de Bump libffi from 5.0.0 to 5.1.0 (#6651)
Bumps [libffi](https://github.com/libffi-rs/libffi-rs) from 5.0.0 to 5.1.0.
- [Commits](https://github.com/libffi-rs/libffi-rs/compare/libffi-v5.0.0...libffi-v5.1.0)

---
updated-dependencies:
- dependency-name: libffi
  dependency-version: 5.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-05 22:53:15 +09:00
dependabot[bot]
dd65baf617 Bump insta from 1.45.1 to 1.46.0 (#6650)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.45.1 to 1.46.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.45.1...1.46.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-version: 1.46.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-05 22:53:03 +09:00
Shahar Naveh
4af869b121 Fix opcode args (#6649) 2026-01-05 22:24:56 +09:00
Terry Tianlin Luan
75838e567e Update pty + tty + associated libraries - v3.13.10 (#6630)
* Update tty + added the test from v3.13.10

* Updated pty.py + test
2026-01-05 14:38:04 +09:00
Terry Tianlin Luan
8977c39b60 Updated the re library + test (#6648)
* Updated re library + test

* Copied over generate_sre_constants from cpython/Tools

* Customized `generate_sre_constants.py` + ran to update `constants.rs`

* Clarified `dump_enum` docstring in `generate_sre_constants.py`
2026-01-05 13:55:07 +09:00
Jeong, YunWon
bdf3b3654e fix syntaxerror ast end_offset (#6646) 2026-01-05 08:01:41 +09:00
Gyubong Lee
ce5e1bd455 Update threading lib and tests from CPython 3.12.0a0 (#4156)
* Update threading.py from CPython v3.12.0a0

* Update test_threading.py from CPython v3.12.0a0

* mark failing tests

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2026-01-05 08:01:00 +09:00
Jeong, YunWon
6cc103bad3 Update README with venv and PIP instructions (#6127) 2026-01-05 01:35:56 +09:00
Jeong, YunWon
e1b22f19e6 vm.run_pyc_bytes (#6645)
* rustpython_vm::import::check_pyc_magic_number_bytes

* vm.new_scope_with_main

* PyCode::from_pyc

* vm.run_pyc_bytes

* add boundary check
2026-01-04 22:58:16 +09:00
Terry Tianlin Luan
ec564ac190 Updated tempfile libraries + associated tests - V3.13.11 (#6632)
* Updated subprocess library test

* Updated tempfile library + test

* Skipped the test_cleanup_with_symlink_modes test
2026-01-04 21:15:42 +09:00
Jeong, YunWon
b47337780b remove ssl from debugger configs (#6644) 2026-01-04 21:10:28 +09:00
Jeong, YunWon
bdd036ea6b pythonrun (#6643) 2026-01-04 20:52:35 +09:00
Jeong, YunWon
fd27c2d78f Fix SSL handshake partial send (#6635)
* simplify test_ftplib

* mark flaky test

* better ssl handshake, pending tls output

* flush_all_pending

* deadline

* flush pending
2026-01-04 17:53:59 +09:00
Jeong, YunWon
8bfe927de5 skip TestTLS_FTPClass (#6640) 2026-01-04 11:07:58 +09:00
Terry Tianlin Luan
68d65a7280 Updated token + weakref libraries + weakref test - v3.13.11 (#6633)
* Updated the token library

* Updated the weakref library

* Annotated the failing weakref test
2026-01-04 10:17:12 +09:00
Terry Tianlin Luan
f929a6eef8 Updated the platform + plistlib libraries + associated tests v.3.13.10 (#6611)
* Updated plistlib + test library

* Updated the platform library + test

* Re-added Rustpython platform version
2026-01-04 10:02:24 +09:00
Terry Tianlin Luan
4bec6bb6f9 Updated the pkgutil + unittest libraries + the pkgutil, unittest and import tests - v.3.13.11 (#6610)
* Updated unittest + tests

* Updated pkgutil + the associated test

* Updated test_import

* Fixed import + unittest test errors

* Updated test_dll_dependency_import with expectedFailure
2026-01-04 09:54:01 +09:00
Jeong, YunWon
eee360822c Rework compiler about exception handling (#6638)
* asyncgen

* fix coroutine

* rewrite compiler

* tests

* set pyc magic number
2026-01-04 09:15:38 +09:00
Terry Tianlin Luan
f0526b9e9a Updated the wsgiref + xmlrpc libraries + associated tests - v3.13.11 (#6634)
* Updated the wsgiref library + test

* Uncommented fixed wsgi tests

* Updated the xmlrpc library + test

* Added expectedFailure to test_request_length in test_wsgiref

* Annotated doc_xmlrpc test failures/errors
2026-01-03 16:29:10 +09:00
Terry Tianlin Luan
eea6cc49cb Update the signal + socket libraries + associated tests - v3.13.11 (#6631)
* Updated signal test library

* Update socketserve + test library

* Fixed test issues with mac

* Added sys import into ftplib

* Reverted ftplib test changes
2026-01-03 16:27:25 +09:00
Jeong, YunWon
cff37af5f6 Fix locale.getencoding, overlapped.getresult, chdir for windows (#6629)
* locale getencoding

* overlapped.getresult

* Fix windows chdir

* mark flaky
2026-01-03 11:43:29 +09:00
Terry Tianlin Luan
5ae75a679b Update the fractions and ftplib libraries + associated tests - v.3.13.10 (#6607)
* Updated ftplib + test library

* Updated fractions + test library
2026-01-03 08:28:25 +09:00
Terry Tianlin Luan
52dd8292c4 Updated enum + file_cmp library + tests - v3.13.10 (#6606)
* Updated enum library

* Updated filecmp + file_cmp test

* Removed unneeded @unittest.expectedFailures

* Updated unexpected success in enum test

* Fixed unexpected success in test_filecmp
2026-01-03 08:27:18 +09:00
Jeong, YunWon
0eddee500a fix fcntl, sslsocket traverse, super , excepthook (#6623)
* fix fcntl

* fix traverse

* fix super

* excepthook

* fix warn
2026-01-03 00:15:31 +09:00
Jeong, YunWon
546d35b8c1 impl multiprocessing SemLock (#6542) 2026-01-03 00:14:43 +09:00
Jeong, YunWon
346519bb6b Warn user not to override special magic methods (#6625) 2026-01-02 17:49:55 +09:00
Jeong, YunWon
32184103c3 ruff_source_file (#6624) 2026-01-02 13:14:39 +09:00
Jeong, YunWon
2e2924801c __{get,set,del}item__ without pymethods (#6622)
* __getitem__ without pymethod

* __setitem__ __delitem__ without pymethod

* sort slot names
2026-01-02 08:29:42 +09:00
Jeong, YunWon
1f8ef0aa36 sequence, mapping slots and fix separate __delitem__ slots (#6621)
* fix call

* Remove repr pymethod

* Remove __get__ and __set__ pymethod

* Remove __contains__ pymethod

* Remove __len__ pymethod

* mapping priors sequence

* fix ctypes
2026-01-02 00:35:59 +09:00
Jeong, YunWon
b19312b403 slot for numeric ops (#6619)
* fix sequence_repeat wrappers

* slot for numeric ops

* fix bpo-37619
2026-01-01 22:39:16 +09:00
Jeong, YunWon
d3e2fa47cc Remove wrong Deref (#6620) 2026-01-01 18:50:34 +09:00
Shahar Naveh
3e2ada0586 Update test_sys.py from 3.13.11 (#6428)
* mark RustPython as  free-threaded

* Py_GIL_DISABLED

* Update `test_sys.py` from 3.13.11

* mark tests

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2026-01-01 18:35:55 +09:00
Shahar Naveh
b446dac359 Update shelve.py from 3.13.11 (#6483)
* Update `test_shelve.py` from 3.13.11

* Update `shelve.py` from 3.13.11
2026-01-01 17:15:00 +09:00
Jeong, YunWon
a445a22868 fix compiler (#6615) 2026-01-01 16:55:39 +09:00
Jeong, YunWon
020ff3058c update_sub_slot, __delitem__, no __bool__, missing rops (#6618)
* fix update_sub_slot

* Fix __setitem__ __delitem__ handling

* contains

* no __bool__ anymore

* Add rops to wrapper

* Remove pymethod from set

* remove len
2026-01-01 15:00:30 +09:00
Jeong, YunWon
e10dc94992 Fix stdio_encoding, stdio_errors (#6617)
* stdio_errors, stdio_encodings

* add ascii

* unmark tests
2026-01-01 14:48:27 +09:00
Jeong, YunWon
e58cf84c71 Update dbm from 3.13.11, implement sqlite3 autocommit (#6616) 2026-01-01 14:44:53 +09:00
Terry Tianlin Luan
a4df238b3d Updated the importlib + nturl2path + pathlib libraries + associated tests - v3.13.10 (#6609)
* Updated the nturl2path library

* Updated pathlib library + test

* Updated urllib test

* Added expectedFailure to failing tests

* Updated importlib library
2026-01-01 08:58:59 +09:00
Jeong, YunWon
1e706d911e Interpreter (#6614)
* Refine documentation in interpreter.rs

Improve InterpreterConfig with convenience methods (with_debug, add_path, add_paths), better documentation with working examples, refactored stdlib setup into focused functions, and comprehensive unit tests while maintaining 100% backward compatibility.

* Improve error message for non-Unicode paths

* Use consistent make_module naming in all doc examples

* cut useful changes

---------

Co-authored-by: Mohamed Gharbi <galaxysea777@gmail.com>
2025-12-31 22:14:28 +09:00
Shahar Naveh
6ccf3b5104 Update ruff to 0.14.10 (#6271)
* Update `ruff` to `0.14.10`

* Mark failing test
2025-12-31 21:13:29 +09:00
Jeong, YunWon
7c8df94f4e Fix __origname__ of frozen modules (#6613) 2025-12-31 21:12:21 +09:00
Jeong, YunWon
a8cfa36c8a Remove duplicated richcompare pymethods and add missing rops' wrapper, __getattr__, proper __bool__ impl (#6579)
* slots: remove duplicate pymethods from object

* Add missing __rmul__

* migrate __bool__

* subclass_update, __getattr__
2025-12-31 20:26:38 +09:00
Jeong, YunWon
d3afd465f3 fix concurrent socket close (#6612) 2025-12-31 17:52:24 +09:00
Jeong, YunWon
b3b97cac7c fix symtable for named_expressions (#6604)
* check duplicated type parameter

* typealias

* fix self.in_comp_inner_loop_target
2025-12-31 15:02:08 +09:00
Jeong, YunWon
01a5f94e7b Fix error / warning messages (#6594)
* fix functools.partial repr

* warn_deprecated_throw_signature

* fix function error messages
2025-12-31 15:01:55 +09:00
Terry Tianlin Luan
bd0aaf6f4f Updated the hmac + mailbox libraries + associated tests (#6608)
* Updated hmac + test library

* Updated mailbox library

* Added mailbox library test (v3.13.10)
2025-12-31 14:58:34 +09:00
dependabot[bot]
37c47fca6b Bump qs and express in /wasm/demo (#6603)
Bumps [qs](https://github.com/ljharb/qs) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together.

Updates `qs` from 6.13.0 to 6.14.1
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.13.0...v6.14.1)

Updates `express` from 4.21.2 to 4.22.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/v4.22.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.21.2...v4.22.1)

---
updated-dependencies:
- dependency-name: qs
  dependency-version: 6.14.1
  dependency-type: indirect
- dependency-name: express
  dependency-version: 4.22.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-31 12:02:47 +09:00
Ashwin Naren
4cf5697e06 Symboltable updates (#5861)
* symboltable updates

* Fix symboltable

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2025-12-31 11:57:42 +09:00
Jeong, YunWon
00ae4a1751 enhance error codec and exit code (#6602) 2025-12-31 11:28:04 +09:00
dependabot[bot]
580f6e3f34 Bump cranelift-* from 0.126.1 to 0.127.0 (#6571)
Bumps [cranelift](https://github.com/bytecodealliance/wasmtime) from 0.126.1 to 0.127.0.
- [Release notes](https://github.com/bytecodealliance/wasmtime/releases)
- [Changelog](https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md)
- [Commits](https://github.com/bytecodealliance/wasmtime/commits)

--------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
2025-12-31 09:47:59 +09:00
Terry Tianlin Luan
cd012f9b2e Added doctest tests (#6598) 2025-12-31 09:43:10 +09:00
Terry Tianlin Luan
e22091ef60 Update straightforward packages Pt 1 (#6595)
* Deleted _pycodecs.py

* Updated code.py library

* Updated the _pydatetime.py lib

* Removed distutils package

* Updated doctest package

* * Updated datetimetester.py
* Added back in _pycodecs.py

* Used tool to verify datetimetester + test_code_module
2025-12-31 02:31:08 +09:00
Jeong, YunWon
6bf1ab65c0 Initiailzer for PyCStructure (#6586) 2025-12-31 01:58:34 +09:00
Vinh Nguyen
ca1c4c1f71 feat: Sync code.py + test_code_module.py from CPython v3.13.1 (#6181)
* feat: Sync code module from cpython 3.13

* also udpate test_code_module

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2025-12-31 01:54:50 +09:00
Jeong, YunWon
b98f06214d Update issubclass and make mro representation fit to CPython (#5866) 2025-12-31 01:42:11 +09:00
Jeong, YunWon
9fcc471c94 Prevent tb_next loop (#6596) 2025-12-30 17:36:15 +09:00
Ashwin Naren
7b9f0d9657 More tkinter (#5784)
* fix build

* fix usage of Tcl_GetVar2Ex

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* no panic on mainloop

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* add static var

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* fix getvar

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* add globalgetvar support

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* formatting

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* address review

* fix build

* Auto-format: cargo fmt --all

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Co-authored-by: Jeong YunWon <jeong@youknowone.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-30 17:07:03 +09:00
Jeong, YunWon
e79a1a1a66 Fix traceback (#6569)
* Fix traceback

* Update traceback from CPython 3.13.11

* unmark test_traceback

* fix code

* fix debug range

* fix tests
2025-12-30 16:58:53 +09:00
Terry Tianlin Luan
6bd1d90b6a Updated bdb.py + test_bdb.py (#6593)
* Updated bdb.py + test_bdb.py

* Double checked test_bdb.py with the script
2025-12-30 16:35:58 +09:00
Jeong, YunWon
6ed0b4f0ac Add PythonFinallizationError and upgrade multiprocessing (#6592)
* PythonFinallizationError

* fix posixprocess

* upgrade multiprocessing from 3.13.11
2025-12-30 15:15:16 +09:00
Jeong, YunWon
dac236dac0 more no_std clippy (#6587) 2025-12-30 15:15:02 +09:00
Jack O'Connor
5e1fc93f50 Update zipfile to 3.13.5 (#6069)
* Add Lib/test/archiver_tests.py @ 3.13.5

Needed for updated zipfile tests.

* Update zipfile to 3.13.5

Notes:

- I have to skip some brand new tests due to shift_jis encoding not
being supported

- `test_write_filtered_python_package` marked as `expectedFailure` with
"AttributeError: module 'os' has no attribute 'supports_effective_ids'"
  - I didn't want to do a partial or full update to os module in this PR

---------

Co-authored-by: Jack O'Connor <jack@jackoconnor.dev>
2025-12-30 13:42:47 +09:00
Terry Tianlin Luan
1464d5ca43 Adding + Fixing Clippy rules to better align with #[no_std] (#6570)
* * Added alloc_instead_of_core, std_instead_of_alloc, and std_instead_of_core clippy rules
* Manually changed part of the code to use core/alloc

* use clippy --fix to fix issues in stdlib

* * Used clippy --fix to fix issues in vm
* Imported Range in vm/src/anystr.rs

* * Used clippy --fix to fix issues in common
2025-12-30 13:10:14 +09:00
Jeong, YunWon
489289f54a Fix subprocess and Update subprocess from Python 3.13.11 (#6583)
* fix test_subprocess

* fix posixsubprocess

* fix io warning

* Update subprocess from Python 3.13.11

* fix

* Auto-format: cargo fmt --all

* fix macos

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-30 12:28:47 +09:00
Terry Tianlin Luan
f274164dcd Add __future__.py tests (#6585)
* Added tests for __future__.py from v3.13.10

* * Deleted futures not in v3.13.10
* "Fixed" issues in test_future.py
2025-12-30 12:28:03 +09:00
Jeong, YunWon
2f4ca509c8 Initializer for PyCSimple, PyCArray (#6581) 2025-12-30 00:58:26 +09:00
Jeong, YunWon
f91ffe34d4 Fix pyexpat parse (#6582) 2025-12-30 00:36:52 +09:00
Jeong, YunWon
4ce6827916 various fix to support subprocess/multiprocessing (#6567)
* hashlib.UnsupportedDigestmodError

* mmap readonly

* thread _refcount

* fix os.statvfs

* apply review
2025-12-30 00:24:07 +09:00
Jeong, YunWon
39aa6f9524 use accept_raw (#6578) 2025-12-29 23:17:16 +09:00
dependabot[bot]
80599603e5 Bump insta from 1.45.0 to 1.45.1 (#6575)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.45.0 to 1.45.1.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.45.0...1.45.1)

---
updated-dependencies:
- dependency-name: insta
  dependency-version: 1.45.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-29 22:53:04 +09:00
dependabot[bot]
879813f763 Bump rustix from 1.1.2 to 1.1.3 (#6572)
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 1.1.2 to 1.1.3.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Changelog](https://github.com/bytecodealliance/rustix/blob/main/CHANGES.md)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v1.1.2...v1.1.3)

---
updated-dependencies:
- dependency-name: rustix
  dependency-version: 1.1.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-29 22:52:52 +09:00
Jeong, YunWon
feb5066be2 stdlib_module_names (#6568) 2025-12-29 21:43:40 +09:00
Jeong, YunWon
45a1940fc6 Merge pull request #6564 from youknowone/socket 2025-12-29 14:26:56 +09:00
Jeong YunWon
ed62c8ef58 mark failures 2025-12-29 11:27:08 +09:00
Jeong, YunWon
183cebe8a1 Upgrade socket from 3.13.11 2025-12-29 11:27:08 +09:00
Jeong YunWon
5079ee8fe3 fix socket 2025-12-29 11:27:07 +09:00
Jeong YunWon
2271f74642 del for socket 2025-12-29 11:25:34 +09:00
Jeong YunWon
219b4e316b DEFAULT_TIMEOUT 2025-12-29 11:25:34 +09:00
Jeong YunWon
81c13347a4 CAN_ attrs 2025-12-29 11:25:31 +09:00
Jeong, YunWon
a7d417cf63 Fix socket.getattrinfo 2025-12-29 11:25:14 +09:00
Jeong, YunWon
d1ff2cde77 RichCompare contains pymethod. No AtomicCell for slots (#6562)
* slots: add comparison pymethods to Comparable trait

* No AtomicCell
2025-12-29 11:21:11 +09:00
Jeong, YunWon
476b75de49 Upgrade test_io from 3.13.11 and fix more io tests (#6565)
* fix various test_io

* Upgrade test_io from 3.13.11

* Fix more test_io
2025-12-28 20:36:15 +09:00
Jeong, YunWon
3600b6652d update _pyio, test_fileio from 3.13.11 and impl more io features (#6560)
* Update _pyio, test_fileio from 3.13.11

* impl more io

* unmark sucessful tests

* fix windows fileio
2025-12-28 18:06:47 +09:00
Jeong, YunWon
44327a8ee4 Upgrade test/support from CPython 3.13.11 (#6556)
* Upgrade test/support from CPython 3.13.11

* fix test_support
2025-12-28 16:30:44 +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
Jeong, YunWon
75daf6f5ec fix is_file (#6563) 2025-12-28 16:03:11 +09:00
Jeong, YunWon
a37f4ec38e upgrade shutil (#6558)
* Update shutil from v3.13.11

* fix os.remove

* fix os.fchmod

* fix is_file
2025-12-28 15:49:10 +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
Jeong, YunWon
f8199d7099 impl basicsize (#6557)
* shape_differs

* may_add_dict

* basicsize
2025-12-28 14:25:10 +09:00
Jeong, YunWon
ee747134b5 signal timer (#6535)
* fix waitpid

* signal timer
2025-12-28 12:04:33 +09:00
Jeong, YunWon
527111bc98 PyWrapperDescrObject and rewrite toggle_slot (#6536)
* SlotFunc

* slotdef

* unify slots

* remove unsed slots
2025-12-28 11:44:36 +09:00
Jeong, YunWon
7edc3bba5d tp_itemsize (#6544) 2025-12-28 10:27:58 +09:00
Jeong, YunWon
012799f560 Fix enum and os.read related to signal (#6552)
* fix enum

* fix os.read to check signals
2025-12-28 10:13:03 +09:00
Jeong, YunWon
fd6c548766 no redundant venvlauncher targets (#6554) 2025-12-28 09:08:16 +09:00
Jeong, YunWon
ce00640b22 fix input to check pty child (#6553)
* fix input to check pty child

* Auto-format: cargo fmt --all

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-28 09:08:03 +09:00
Jeong, YunWon
9b2ad34a08 check surrogates (#6547) 2025-12-28 00:06:29 +09:00
Jeong, YunWon
5b20c458af Implement more except* (#6545)
* clean build documentation

* SetExcInfo

* fix EG subclass

* test_except_star
2025-12-27 23:03:23 +09:00
Shahar Naveh
8d9002800e Update test_dis.py from 3.13.11 (#6528) 2025-12-27 22:53:37 +09:00
Jeong, YunWon
75ecd72428 test_builtin.test_import (#6546)
* fix warnings

* fix test_import
2025-12-27 21:38:12 +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
Shahar Naveh
b704f42158 Reduce usage JumpIfTrueOrPop & JumpIfFalseOrPop opcdes. Refactor compile_compare (#6524)
* Remove `JumpIfTrueOrPop` & `JumpIfFalseOrPop` opcdes

* Use correct instruction name

* Extract `compile_cmpop` to its own method

* Better alignment with CPython code

* Restore `PopJumpIf` instructions

* Revert PopJumpIfFalse for comparisons
2025-12-27 00:16:16 +09:00
Jeong, YunWon
7f4d308efc Implement maybe_pyc_file and .pyc file execution (#6539)
* Implement maybe_pyc_file and .pyc file execution

* unmark failing tests
2025-12-26 22:13:00 +09:00
Jeong, YunWon
4a6e8fb29e Add except* support (#6530) 2025-12-26 21:54:23 +09:00
Jeong, YunWon
57b4b4ae45 fix sys path (#6537) 2025-12-26 21:43:00 +09:00
Jeong, YunWon
1856415196 Fix f-string conversion flag ValueError when compiling AST (#6533) (#6534)
The ast_from_object for ConversionFlag was using bytecode::ConvertValueOparg::from_op_arg()
which only accepts internal oparg values (0, 1, 2, 3, 255), but Python's AST uses ASCII codes
('s'=115, 'r'=114, 'a'=97, -1=None).

This caused compile() on parsed AST with conversion flags to fail with "invalid conversion flag".
2025-12-26 21:38:05 +09:00
Jeong, YunWon
72a90da13b increase timeout-minutes to 45 (#6541) 2025-12-26 20:39:48 +09:00
Jeong, YunWon
c9bf8df19c copyslot for init (#6515) 2025-12-26 09:46:33 +09:00
Jeong, YunWon
ae39b132e4 impl more ntpath (#6531) 2025-12-26 09:43:01 +09:00
Jeong, YunWon
21f24cdcc7 impl more winapi (#6529) 2025-12-26 01:37:21 +09:00
Jeong, YunWon
40acd55290 venvlauncher (#6527) 2025-12-26 01:29:58 +09:00
Jeong, YunWon
2063c1e0bc Implement winapi.GetLongPathName (#6525) 2025-12-25 22:37:59 +09:00
Shahar Naveh
bcdf37bef1 Align opcode names in dis (#6526)
* opcodes dis repr like cpython. POP-> POP_TOP

* Adjust frame.rs

* Fix codegen

* snapshots

* Add doc for `PopTop`

* fix jit
2025-12-25 22:17:31 +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
Jeong, YunWon
151f0746a3 Implement copyslot (#6505) 2025-12-25 16:56:41 +09:00
Jeong, YunWon
aaecdd1747 repr for getset (#6514) 2025-12-25 16:55:19 +09:00
Jeong, YunWon
7eb0fe4984 Fix potential deadlock (#6509) 2025-12-25 15:49:44 +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
Jeong, YunWon
92acf339a1 fix pyexpat hang (#6507) 2025-12-25 13:31:29 +09:00
Jeong, YunWon
49dbbbd5b9 Fix SSL test_preauth_data_to_tls_server (#6508) 2025-12-25 13:28:50 +09:00
Jeong, YunWon
aae6bf566f Add tp_str (#6495)
* clean up hash

* __str__ slot wrapper
2025-12-25 11:00:53 +09:00
Copilot
6dbc8f0cfa Set SourceFileLoader for script execution in run_simple_file (#6496)
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 10:33:22 +09:00
Jeong, YunWon
5122aed738 Fix install ujson (#6502) 2025-12-25 10:32:51 +09:00
Copilot
ebdc033c59 Bundle Lib directory in GitHub releases (#6497)
* Initial plan

* Add Lib directory archives to release workflow

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

* Add release notes explaining users need both binary and Lib archive

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

* Remove unnecessary --notes-start-tag parameter

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

* Only create zip archive, remove tar.gz

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>
2025-12-25 09:48:20 +09:00
Jeong, YunWon
7ebb0f0c5c impl path_converter and os functions (#6484)
* os.setpgrp

* tcgetpgrp

* impl more os functions

* impl PathConverter
2025-12-25 09:21:09 +09:00
Copilot
72cf6c36d5 Add missing xmlparser attributes: namespace_prefixes, ordered_attributes, specified_attributes, intern (#6494)
* Add namespace_prefixes and other missing xmlparser attributes

- Added namespace_prefixes, ordered_attributes, specified_attributes (boolean attributes)
- Added intern dictionary attribute
- Added stub handlers for all missing handler types to ensure compatibility
- Created bool_property macro to ensure boolean attributes are converted correctly

* Remove expectedFailure decorators from passing tests

- Tests for buffer_text, namespace_prefixes, ordered_attributes, and specified_attributes now pass

---------

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 09:09:58 +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
cbde5ce321 iter with slot-wrapper (#6488) 2025-12-24 23:35:35 +09:00
Jeong YunWon
c2a7393191 uniform __str__ 2025-12-24 22:23:43 +09:00
Jeong YunWon
a4e60f569e repr 2025-12-24 22:23:43 +09:00
Shahar Naveh
7c3bc5ed8d Update test_http_cookies.py from 3.13.11 (#6481)
* Update `test_http_cookies.py` from 3.13.11

* Mark failing test

* Update `http/cookies.py` from 3.13.11

* Unmark passing test

* Lower amount
2025-12-24 19:45:48 +09:00
Shahar Naveh
9d1477699c Update test_threading_local.py from 3.13.11 (#6482)
* Update `test_threading_local.py` from 3.13.11

* Mark failing test
2025-12-24 18:57:00 +09:00
Jeong, YunWon
c4e77287d1 __hash__ to slot_wrapper (#6480) 2025-12-24 18:56:47 +09:00
Jeong, YunWon
3d7e521acd introduce slot_wrapper (#4884) 2025-12-24 17:29:47 +09:00
Jeong, YunWon
4f0b940b16 impl preexec_fn (#6479) 2025-12-24 17:02:21 +09:00
Jeong, YunWon
309b2ad32d Fix ast end_location (#6478) 2025-12-24 16:54:54 +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
Jeong, YunWon
c763d67ef4 Fix dict.keys behavior (#6476) 2025-12-24 13:50:26 +09:00
Jeong, YunWon
215c5c6d7b signal.pthread_sigmask (#6475) 2025-12-24 13:15:33 +09:00
Jiseok CHOI
00205aad14 Bump libsqlite3-sys from 0.28 to 0.36 (#6472)
* Bump libsqlite3-sys from 0.28 to 0.36

Update libsqlite3-sys to version 0.36 and adapt to API changes by
replacing sqlite3_close_v2 with sqlite3_close. The v2 variant is no
longer directly exported in the newer version.

Fixes #6471

* Fix clippy
2025-12-24 13:10:57 +09:00
Jeong, YunWon
c35cb89f91 Merge pull request #6473 from youknowone/libffi
Upgrade libffi 5
2025-12-24 10:35:52 +09:00
Jeong YunWon
7c7e55ffc4 Upgrade libffi 2025-12-24 08:44:13 +09:00
Jeong, YunWon
2785bd8224 Merge pull request #6457 from youknowone/ctypes
Enable ctypes
2025-12-24 08:40:19 +09:00
Jeong YunWon
4a352344b6 mark failing test_ctypes 2025-12-24 00:13:30 +09:00
Jeong YunWon
7e6e0f66c8 test_ctypes from CPython 3.13.11 2025-12-24 00:13:30 +09:00
Jeong YunWon
03d6f4634f Upgrade ctypes to Python v3.13.11 2025-12-24 00:13:30 +09:00
Jeong YunWon
987216bcb8 enable ctypes 2025-12-24 00:13:30 +09:00
Jeong YunWon
79abbf0b29 fix ctypes 2025-12-24 00:13:30 +09:00
Jeong YunWon
4bf0bac52d debuggable whats_left 2025-12-23 23:29:15 +09:00
Jeong YunWon
286a5b5b8f msc_info in get_version 2025-12-23 23:28:58 +09:00
Jeong YunWon
fc0a34a5a5 Remove unused ctypes/field.rs 2025-12-23 21:58:51 +09:00
Jeong, YunWon
b44229f7ca debug whats_left 2025-12-23 21:58:51 +09:00
Jeong YunWon
9760249a75 fix multiarch 2025-12-23 16:41:28 +09:00
Jeong, YunWon
ec7588841f Merge pull request #6470 from youknowone/common-fix
Mark unrunnable test_threading. Fix SSL args names. Add args to sysconfigdata
2025-12-23 16:09:57 +09:00
Jeong, YunWon
df523cb58c skip spawnve on windows 2025-12-23 15:01:40 +09:00
Jeong YunWon
a84452ab45 fix sysconfigdata 2025-12-23 13:12:56 +09:00
Jeong YunWon
73e1c3816e fix ssl 2025-12-23 11:56:26 +09:00
Jeong YunWon
d919fe516e mark test_threading 2025-12-23 11:55:40 +09:00
dependabot[bot]
2342006b37 Bump aws-lc-rs from 1.15.1 to 1.15.2 (#6469)
Bumps [aws-lc-rs](https://github.com/aws/aws-lc-rs) from 1.15.1 to 1.15.2.
- [Release notes](https://github.com/aws/aws-lc-rs/releases)
- [Commits](https://github.com/aws/aws-lc-rs/compare/v1.15.1...v1.15.2)

---
updated-dependencies:
- dependency-name: aws-lc-rs
  dependency-version: 1.15.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-23 08:57:03 +09:00
dependabot[bot]
5925f1483c Bump insta from 1.44.3 to 1.45.0 (#6468)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.44.3 to 1.45.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.44.3...1.45.0)

---
updated-dependencies:
- dependency-name: insta
  dependency-version: 1.45.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-22 22:25:09 +09:00
Jeong, YunWon
fdd2ac3b30 disallow __new__, __init__ (#6446)
* disallow __new__, __init__

* migrate to Initializer

* apply review
2025-12-22 21:10:43 +09:00
Shahar Naveh
569bee103f Use ruff_python_ast::visitor::Visitor for detecting await (#6466) 2025-12-22 12:43:58 +09:00
Jeong, YunWon
8b3bf558fc Introduce PyConfig to implement Paths correctly (#6461)
* getpath

* introduce PyConfig

* landmark in getpath
2025-12-21 08:25:17 +09:00
Jeong, YunWon
09fa97d1b9 CI to test Apple Intel (#6465) 2025-12-21 00:54:05 +09:00
Jeong, YunWon
898fe85f40 More openssl impl (#6464)
* Add openssl build to CI

* more openssl impls
2025-12-21 00:38:50 +09:00
Jeong, YunWon
6660170bf8 Share more ssl consts and fix openssl (#6462)
* Reuse SSL error names

* Share ssl error codes

* fix ssl

* fix openssl
2025-12-20 22:06:22 +09:00
Jeong, YunWon
7bfa5d9ced Buffer LongDouble + ndim (#6460)
* fix fix_test

* ndim buffer
2025-12-20 18:31:00 +09:00
Jeong, YunWon
46c61a65a6 Upgrade venv to v3.13.11 (#6459)
* Upgrade venv

* get_venv_base_executable

* mark failing tests
2025-12-20 12:17:11 +09:00
Jeong, YunWon
ab1105a61d Fix fix_test.py (#6415) 2025-12-20 09:55:28 +09:00
Shahar Naveh
6c186e3893 Update smptlib and test_smtpnet.py from 3.13.11 (#6435)
* Update `test_smtpnet.py` from 3.13.11

* Update `test_smtplib.py` from 3.13.11

* Update `smtplib.py` from 3.13.11

* Catch AttributeError
2025-12-19 22:51:09 +09:00
Jeong, YunWon
70b93898d4 ctypes overhaul (#6450) 2025-12-19 14:10:55 +09:00
fanninpm
100b043fb6 Merge pull request #6453 from ShaharNaveh/skip-flakey-subprocess-test
Skip flakey test
2025-12-18 10:49:02 -05:00
Jeong, YunWon
9e439667da Fix openssl build and shared ssl/error.rs (#6456)
* Fix openssl

* shared error
2025-12-18 10:44:56 +09:00
Jeong, YunWon
a4c93dfbbf Remove useless &PyRef patterns (#6455)
* fix &PyTypeRef

* Remove useless &PyObjectRef

* Remove useless &PyRef
2025-12-17 20:58:00 +09:00
Jeong, YunWon
0412dfdb3b Fix winerror handling (#6454) 2025-12-17 20:57:34 +09:00
Shahar Naveh
9d2dd17455 Add regression test (#6452) 2025-12-17 19:02:44 +09:00
Shahar Naveh
be559ae453 Update support/import_helper.py from 3.13.11 (#6451)
* Update `support/import_helper.py` from 3.13.11

* Unmark passing test
2025-12-17 08:15:25 +09:00
ShaharNaveh
f3916950bf Skip flakey test 2025-12-16 21:35:55 +01:00
Shahar Naveh
adc2b0dbbe Update test_zipfile64.py from 3.13.11 (#6433)
* Update `test_zipfile64.py` from 3.13.11

* Mark flaky test
2025-12-17 00:28:06 +09:00
Jeong, YunWon
9aa1f18998 Unraiseable traceback (#6449) 2025-12-17 00:16:51 +09:00
Jeong, YunWon
246fab63f7 flag: DISALLOW_INSTANTIATION (#6445)
* Set tp_new slot when build heap/static type

* Improve type tp_call impl to check tp_new existence and error if not exist

* Set DISALLOW_INSTANTIATION flag on several types according to cpython impl

* Allow #[pyslot] for function pointer

* Fix DISALLOW_INSTANTIATION

---------

Signed-off-by: snowapril <sinjihng@gmail.com>
Co-authored-by: snowapril <sinjihng@gmail.com>
2025-12-17 00:12:03 +09:00
Jeong, YunWon
aef4de4ab8 fix buffer (#6447) 2025-12-16 23:27:21 +09:00
Jeong, YunWon
65bdfc3d4e Integrate OSError creations into OSErrorBuilder (#6443) 2025-12-16 23:11:35 +09:00
Jeong, YunWon
272b36daa5 small fixes (#6444)
* fix memoryview

* retype slot zelf
2025-12-16 11:16:38 +09:00
Jeong, YunWon
30cc772454 sys.set_asyncgen_hook (#6439)
* PyAnextAwaitable::state

* sys.set_asyncgen_hook
2025-12-16 10:11:17 +09:00
dependabot[bot]
e6d9a9aef0 Bump actions/download-artifact from 6.0.0 to 7.0.0 (#6441) 2025-12-15 23:54:53 +09:00
dependabot[bot]
78d2e5bdf1 Bump actions/upload-artifact from 5.0.0 to 6.0.0
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5.0.0 to 6.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-15 23:53:21 +09:00
Jeong, YunWon
550497eb79 Use parking_lot in faulthandler (#6438) 2025-12-15 17:56:48 +09:00
Lee Dogeon
8e21db11d6 Update architecture/architecture.md (#6437)
* Replace architecture overview image with mermaid graph

* Update architecture.md with correct paths and links

- Fix file paths to reflect crates/ directory structure
- Update GitHub permalink references to current commit
- Remove trailing slashes from package names
- Use archive.org for broken desosa.nl link
- Change master to main branch reference

* Update architecture documentation for ruff_python_parser

RustPython now uses ruff_python_parser from astral-sh/ruff instead of
the separate RustPython/Parser project. Update architecture documentation
to reflect this change.
2025-12-15 09:57:06 +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
Jeong, YunWon
21300f689d Allow with() in pyexception (#6436) 2025-12-14 12:16:49 +09:00
Jeong, YunWon
b3c2aa6b51 PyAnextAwaitable (#6427) 2025-12-14 12:15:29 +09:00
Shahar Naveh
db71554dbc Update test_urllib2net.py from 3.13.11 (#6434) 2025-12-13 22:06:55 +09:00
Shahar Naveh
dbacb07246 Update test_urllibnet.py from 3.13.11 (#6432) 2025-12-13 22:06:41 +09:00
Shahar Naveh
835918afa1 Set timeout only on test step (#6431) 2025-12-13 11:09:26 +09:00
Shahar Naveh
1e3d4fe218 Update test_xmlrpc.py from 3.13.11 (#6430) 2025-12-13 11:09:11 +09:00
Shahar Naveh
901324f21e Update test_raise.py from 3.13.11 (#6423) 2025-12-13 11:08:47 +09:00
Jeong, YunWon
30dd5bedc6 use posix error messages under 127 (#6420)
* use posix error messages under 127

* use posix error message for unix

* unmark successful tests
2025-12-13 09:24:17 +09:00
Shahar Naveh
e227956a58 Update test_generators.py from 3.13.11 (#6426) 2025-12-13 00:02:02 +09:00
Shahar Naveh
f49d20df22 Update test_setcomps.py from 3.13.11 (#6425) 2025-12-12 23:47:16 +09:00
Shahar Naveh
9ccf4c1872 Ruff auto-format (#6422) 2025-12-12 22:46:39 +09:00
Jeong, YunWon
093ba251ab Merge pull request #5377 from youknowone/inspect
Update dataclasses, inspect from CPython 3.13
2025-12-12 22:44:39 +09:00
Shahar Naveh
6f8050526f Ruff as part of PR auto-format (#6421) 2025-12-12 21:59:56 +09:00
Jeong, YunWon
c11a72a4f1 impl more ast (#6419) 2025-12-12 21:50:54 +09:00
Jeong, YunWon
9bbfdf5067 mark expectedFailure 2025-12-12 21:44:00 +09:00
Jeong, YunWon
ef6c6ad117 patch test_inspect 2025-12-12 21:44:00 +09:00
Jeong, YunWon
152d10bfea hybrid dis.py from CPython 3.13.10 2025-12-12 21:44:00 +09:00
Jeong, YunWon
d11604995a Upgrade dataclasses from CPython 3.13.10 2025-12-12 21:43:57 +09:00
Jeong, YunWon
d22956ebc1 inspect from v3.13.10 2025-12-12 21:43:24 +09:00
Jeong YunWon
be5f660dfe impl more ast 2025-12-12 21:43:24 +09:00
Shahar Naveh
49522e7a5e Update ruff CI version (#6418) 2025-12-12 21:12:19 +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
35f88608d2 Fix test_subprocess and locale (#6416)
* Fix test_subprocess

* fix windows locale
2025-12-12 21:03:26 +09:00
Jeong, YunWon
752c0f68fd fix windows locale 2025-12-12 20:26:47 +09:00
Jeong, YunWon
b9fa405fd4 Fix test_subprocess 2025-12-12 20:26:47 +09:00
Shahar Naveh
75dcf8042e Tidy codegen::ir::BlockIdx api (#6413)
* Tidy `codegen::ir::BlockIdx` api

* Update crates/codegen/src/ir.rs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-12-12 20:05:31 +09:00
Jeong, YunWon
5a5b721576 Fix misused PyTypeError (#6412) 2025-12-12 17:23:27 +09:00
Jeong, YunWon
df3a0b2f25 impl {raise_,str}signal (#6411)
* year>=1900 on windows

* signal

* set_wakeup_fd
2025-12-12 17:02:32 +09:00
Jeong, YunWon
4bec0ad1c6 Fix test_runpy (#6409) 2025-12-12 15:26:00 +09:00
Jeong, YunWon
772b92edde Fix windows socket (#6408)
* fix _path_splitroot

* Fix windows socket
2025-12-12 10:37:40 +09:00
Jeong, YunWon
2ff1fba6ed Faulthandler (#6406) 2025-12-12 09:23:59 +09:00
Jeong, YunWon
3438fb2850 nt junction (#6407)
* pylib strip path

* nt._path_* functions,

* nt junction
2025-12-12 09:03:19 +09:00
Jeong, YunWon
d34b2cf8f0 TypeData (#6403)
* HeapTypeExt::type_data

* Apply TypeDataSlot to ctypes
2025-12-12 07:57:31 +09:00
Jeong, YunWon
bfd873a8b8 a few unreachable->unimplemented, clippy (#6405)
* unreachable -> unimplemented

* Fix clippy on 1.92
2025-12-12 01:13:28 +09:00
Jeong, YunWon
f379ea8327 winapi._findfirstfile,nt.chmod (#6401) 2025-12-12 00:18:02 +09:00
Jeong, YunWon
04d55fa5c6 Faulthandler (#6400) 2025-12-12 00:08:55 +09:00
Jeong, YunWon
72e892a57d Remove cargo vcpkg from windows build (#6404) 2025-12-11 23:20:24 +09:00
Jeong, YunWon
a477835970 py_new separation for set/tuple/bytes/str 2025-12-11 23:17:10 +09:00
Jeong, YunWon
5f496c955c PyType::py_new to return Self (#6398)
* PyType::py_new to return Self

* int/float/complex
2025-12-11 22:19:11 +09:00
Jeong, YunWon
00543942aa nt.skiproot, winapi.LCMapStringEx (#6399) 2025-12-11 21:42:28 +09:00
Jeong, YunWon
4828fb3ba6 test_os, test_io on windows (#6379)
* Allow hidden env vars on nt

* Enable test_os on windows

* enable test_io on windows
2025-12-11 13:11:29 +09:00
dependabot[bot]
20d9099bf3 Bump insta from 1.44.2 to 1.44.3 (#6394)
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.44.2 to 1.44.3.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.44.2...1.44.3)

---
updated-dependencies:
- dependency-name: insta
  dependency-version: 1.44.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-11 08:34:32 +09:00
dependabot[bot]
3a7a5205fb Bump log from 0.4.28 to 0.4.29 (#6396)
Bumps [log](https://github.com/rust-lang/log) from 0.4.28 to 0.4.29.
- [Release notes](https://github.com/rust-lang/log/releases)
- [Changelog](https://github.com/rust-lang/log/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/log/compare/0.4.28...0.4.29)

---
updated-dependencies:
- dependency-name: log
  dependency-version: 0.4.29
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-11 08:34:20 +09:00
dependabot[bot]
81c9b05f97 Bump libc from 0.2.177 to 0.2.178 (#6395)
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.177 to 0.2.178.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Changelog](https://github.com/rust-lang/libc/blob/0.2.178/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.177...0.2.178)

---
updated-dependencies:
- dependency-name: libc
  dependency-version: 0.2.178
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-11 08:34:06 +09:00
Jeong, YunWon
2055145a7e validate_downcast (#6393) 2025-12-10 23:31:38 +09:00
Jeong, YunWon
1b17587585 __slots__ xor __dict__ , name mangling (#6392)
* __slots__ xor __dict__

* mangle_name for `__` prefixed members
2025-12-10 23:30:10 +09:00
Jeong, YunWon
98fff96f1c __doc__ handing in the right way (#6390) 2025-12-10 20:04:09 +09:00
Jeong, YunWon
90717e5ef7 doc db to include types.* (#6391)
* Add types.* for doc/generate.py

* udpate-doc-db workflow

* Update doc DB for CPython 3.13.9

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-10 19:23:27 +09:00
Jeong, YunWon
c71c78c1a0 Upgrade pyo3 (#6389) 2025-12-10 10:29:20 +09:00
Jeong, YunWon
a64cfac2ca Fix multiprocessing closesocket, set_errno (#6388)
* Fix multiprocessing closesocket

* set_errno
2025-12-10 10:02:53 +09:00
Jeong, YunWon
30fb9d73cc Fix test_io on windows (#6387)
* mark skip on test_io

* Drop for FileIO

* IO Desctructors

* Iterator
2025-12-10 09:21:32 +09:00
Jeong, YunWon
14232ad0d2 new_last_{os,errno}_error (#6381)
* new_last_{os,errno}_error

* Remove os::errno_err

* enable ssl multithread test
2025-12-10 09:12:38 +09:00
dependabot[bot]
f723974924 Bump system-configuration from 0.6.1 to 0.7.0 (#6385)
Bumps [system-configuration](https://github.com/mullvad/system-configuration-rs) from 0.6.1 to 0.7.0.
- [Changelog](https://github.com/mullvad/system-configuration-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mullvad/system-configuration-rs/compare/v0.6.1...v0.7.0)

---
updated-dependencies:
- dependency-name: system-configuration
  dependency-version: 0.7.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-10 09:01:29 +09:00
dependabot[bot]
9f8090c830 Bump libloading from 0.8.9 to 0.9.0 (#6384)
Bumps [libloading](https://github.com/nagisa/rust_libloading) from 0.8.9 to 0.9.0.
- [Commits](https://github.com/nagisa/rust_libloading/compare/0.8.9...0.9.0)

---
updated-dependencies:
- dependency-name: libloading
  dependency-version: 0.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-10 09:01:17 +09:00
dependabot[bot]
42b969b088 Bump oid-registry from 0.7.1 to 0.8.1 (#6383)
Bumps [oid-registry](https://github.com/rusticata/oid-registry) from 0.7.1 to 0.8.1.
- [Commits](https://github.com/rusticata/oid-registry/compare/oid-registry-0.7.1...oid-registry-0.8.1)

---
updated-dependencies:
- dependency-name: oid-registry
  dependency-version: 0.8.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-10 09:01:05 +09:00
dependabot[bot]
4ebdadea45 Bump pyo3 from 0.26.0 to 0.27.2 (#6386)
Bumps [pyo3](https://github.com/pyo3/pyo3) from 0.26.0 to 0.27.2.
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pyo3/pyo3/compare/v0.26.0...v0.27.2)

---
updated-dependencies:
- dependency-name: pyo3
  dependency-version: 0.27.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-10 01:02:31 +09:00
Jeong, YunWon
ac48643447 Add TextIOWrapper.truncate, fix a few bugs (#6382) 2025-12-10 00:58:21 +09:00
Jeong, YunWon
26b3445d14 windows pipe/getppid (#6378)
* pipe/pid

* libc first
2025-12-09 23:49:32 +09:00
Jeong, YunWon
8bc46cf83d Fix windows inode to use u128 (#6377) 2025-12-09 23:40:54 +09:00
Sean Lawlor
6003c87582 Freeze ruff libraries to the REV that the TAG points to. (#6375)
Tags can move and be re-aliased to different revisions, and this actually freezes the rev (similar to how a published crate would) so that it only applies to this specific commit hash.
2025-12-09 23:19:42 +09:00
Jeong, YunWon
c578861598 nt.terminalsize (#6374)
* terminalsize

* use _get_osfhandle
2025-12-09 23:17:53 +09:00
Jeong, YunWon
79cd048e1f native ExceptionGroup (#6358) 2025-12-09 23:02:44 +09:00
Jeong, YunWon
5365805312 minimize ssl lock (#6376) 2025-12-09 23:01:12 +09:00
Jeong, YunWon
db95946b8d Fix SSL deferred error (#6371)
* Fix SSL to return deferred error on the right time

* lease conn_guard

* SslError::Io

* is_connection_closed
2025-12-09 21:59:31 +09:00
Jeong, YunWon
a99164fd7b nt is_dir,is_file,listmount,listvolume (#6373)
* is_dir/is_file for windows

* listmount/listvolume

* check_env_var_len
2025-12-09 20:08:16 +09:00
Jeong, YunWon
cc534d2954 Fix failing reason (#6370) 2025-12-09 10:46:40 +09:00
dependabot[bot]
904cc0a575 Bump pem-rfc7468 from 0.7.0 to 1.0.0 (#6369)
Bumps [pem-rfc7468](https://github.com/RustCrypto/formats) from 0.7.0 to 1.0.0.
- [Commits](https://github.com/RustCrypto/formats/compare/pem-rfc7468/v0.7.0...pem-rfc7468/v1.0.0)

---
updated-dependencies:
- dependency-name: pem-rfc7468
  dependency-version: 1.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 10:46:14 +09:00
dependabot[bot]
0760551cf7 Bump lz4_flex from 0.11.5 to 0.12.0 (#6367)
Bumps [lz4_flex](https://github.com/pseitz/lz4_flex) from 0.11.5 to 0.12.0.
- [Release notes](https://github.com/pseitz/lz4_flex/releases)
- [Changelog](https://github.com/PSeitz/lz4_flex/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pseitz/lz4_flex/compare/0.11.5...0.12.0)

---
updated-dependencies:
- dependency-name: lz4_flex
  dependency-version: 0.12.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 09:29:01 +09:00
dependabot[bot]
7f15c8c1bd Bump js-sys from 0.3.82 to 0.3.83 (#6366)
Bumps [js-sys](https://github.com/wasm-bindgen/wasm-bindgen) from 0.3.82 to 0.3.83.
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/commits)

---
updated-dependencies:
- dependency-name: js-sys
  dependency-version: 0.3.83
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 09:28:49 +09:00
dependabot[bot]
614cb84e7a Bump wasm-bindgen from 0.2.105 to 0.2.106 (#6365)
Bumps [wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen) from 0.2.105 to 0.2.106.
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.105...0.2.106)

---
updated-dependencies:
- dependency-name: wasm-bindgen
  dependency-version: 0.2.106
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 09:28:33 +09:00
dependabot[bot]
df7694ca51 Bump x509-parser from 0.16.0 to 0.18.0 (#6364)
Bumps [x509-parser](https://github.com/rusticata/x509-parser) from 0.16.0 to 0.18.0.
- [Changelog](https://github.com/rusticata/x509-parser/blob/x509-parser-0.18.0/CHANGELOG.md)
- [Commits](https://github.com/rusticata/x509-parser/compare/x509-parser-0.16.0...x509-parser-0.18.0)

---
updated-dependencies:
- dependency-name: x509-parser
  dependency-version: 0.18.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 06:24:38 +09:00
dependabot[bot]
087e812bc0 Bump pyo3 from 0.26.0 to 0.27.2 (#6363)
Bumps [pyo3](https://github.com/pyo3/pyo3) from 0.26.0 to 0.27.2.
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pyo3/pyo3/compare/v0.26.0...v0.27.2)

---
updated-dependencies:
- dependency-name: pyo3
  dependency-version: 0.27.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 06:08:52 +09:00
dependabot[bot]
808c8afbe1 Bump criterion from 0.7.0 to 0.8.1 (#6361)
Bumps [criterion](https://github.com/criterion-rs/criterion.rs) from 0.7.0 to 0.8.1.
- [Release notes](https://github.com/criterion-rs/criterion.rs/releases)
- [Changelog](https://github.com/criterion-rs/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/criterion-rs/criterion.rs/compare/criterion-plot-v0.7.0...criterion-v0.8.1)

---
updated-dependencies:
- dependency-name: criterion
  dependency-version: 0.8.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 06:08:15 +09:00
dependabot[bot]
d432cfd350 Bump uuid from 1.18.1 to 1.19.0 (#6362)
Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.18.1 to 1.19.0.
- [Release notes](https://github.com/uuid-rs/uuid/releases)
- [Commits](https://github.com/uuid-rs/uuid/compare/v1.18.1...v1.19.0)

---
updated-dependencies:
- dependency-name: uuid
  dependency-version: 1.19.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 06:08:04 +09:00
Jeong, YunWon
7a5d81a469 Fix os.utime for windows/macos (#6354) 2025-12-09 06:07:48 +09:00
dependabot[bot]
e4b9b26037 Bump winresource from 0.1.27 to 0.1.28 (#6360)
Bumps [winresource](https://github.com/BenjaminRi/winresource) from 0.1.27 to 0.1.28.
- [Commits](https://github.com/BenjaminRi/winresource/commits)

---
updated-dependencies:
- dependency-name: winresource
  dependency-version: 0.1.28
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-09 06:07:31 +09:00
Jeong, YunWon
bb4e30a6df fspath try from (#6359) 2025-12-09 05:44:21 +09:00
Jeong, YunWon
b200f0e8d2 Replace windows to windows-sys (#6356) 2025-12-09 05:08:45 +09:00
Jeong, YunWon
7157697f96 last_posix_errno (#6341) 2025-12-09 04:41:44 +09:00
Jeong, YunWon
bafaa1a826 scandir/lstat (#6357) 2025-12-09 04:32:06 +09:00
Jeong, YunWon
abfd148d63 SSLError (#6351) 2025-12-09 02:55:34 +09:00
Jeong, YunWon
a484ba4790 st_file_attributes (#6353) 2025-12-09 02:49:36 +09:00
Jeong, YunWon
abc5c223a6 os.waitstatus_to_exitcode for windows (#6355) 2025-12-09 02:46:05 +09:00
Jeong, YunWon
42d0a583e8 fix remove 2025-12-09 02:43:58 +09:00
Jeong, YunWon
649606fc58 Unconstructible 2025-12-09 02:43:58 +09:00
Jeong, YunWon
4438dba49c use ToWide 2025-12-09 02:43:58 +09:00
dependabot[bot]
638a408eff Bump malachite-* from 0.6.1 to 0.8.0 (#6344)
* Bump malachite-base from 0.6.1 to 0.8.0

Bumps [malachite-base](https://github.com/mhogrefe/malachite) from 0.6.1 to 0.8.0.
- [Release notes](https://github.com/mhogrefe/malachite/releases)
- [Commits](https://github.com/mhogrefe/malachite/compare/v0.6.1...v0.8.0)

---
updated-dependencies:
- dependency-name: malachite-base
  dependency-version: 0.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump malachite-*

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
2025-12-09 01:54:25 +09:00
dependabot[bot]
a3d638ab5f Bump windows-sys from 0.59.0 to 0.61.2 (#6346)
* Bump windows-sys from 0.59.0 to 0.61.2

Bumps [windows-sys](https://github.com/microsoft/windows-rs) from 0.59.0 to 0.61.2.
- [Release notes](https://github.com/microsoft/windows-rs/releases)
- [Commits](https://github.com/microsoft/windows-rs/commits)

---
updated-dependencies:
- dependency-name: windows-sys
  dependency-version: 0.61.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix breaking changes

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
2025-12-09 00:53:12 +09:00
Jeong, YunWon
bf565e917a Windows execv, spawnv, wait (#6350)
* more const

* wait

* exec

* mkdir
2025-12-09 00:37:52 +09:00
dependabot[bot]
2a425351e2 Bump phf from 0.11.3 to 0.13.1 (#6345)
Bumps [phf](https://github.com/rust-phf/rust-phf) from 0.11.3 to 0.13.1.
- [Release notes](https://github.com/rust-phf/rust-phf/releases)
- [Changelog](https://github.com/rust-phf/rust-phf/blob/main/RELEASE_PROCESS.md)
- [Commits](https://github.com/rust-phf/rust-phf/compare/phf-v0.11.3...v0.13.1)

---
updated-dependencies:
- dependency-name: phf
  dependency-version: 0.13.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-08 23:55:58 +09:00
Jeong, YunWon
4592787946 get_inheritable, dup for windows (#6343) 2025-12-08 23:55:03 +09:00
dependabot[bot]
8ad7f912ea Bump actions/setup-python from 6.0.0 to 6.1.0 (#6349)
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 6.0.0 to 6.1.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v6...v6.1.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: 6.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-08 23:10:53 +09:00
dependabot[bot]
7e34ab743a Bump actions/checkout from 5.0.1 to 6.0.1 (#6348)
Bumps [actions/checkout](https://github.com/actions/checkout) from 5.0.1 to 6.0.1.
- [Release notes](https://github.com/actions/checkout/releases)
- [Commits](https://github.com/actions/checkout/compare/v5.0.1...v6.0.1)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-08 23:09:50 +09:00
dependabot[bot]
4e6ef4150d Bump webpki-roots from 0.26.11 to 1.0.4 (#6347)
Bumps [webpki-roots](https://github.com/rustls/webpki-roots) from 0.26.11 to 1.0.4.
- [Release notes](https://github.com/rustls/webpki-roots/releases)
- [Commits](https://github.com/rustls/webpki-roots/compare/v/0.26.11...v/1.0.4)

---
updated-dependencies:
- dependency-name: webpki-roots
  dependency-version: 1.0.4
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-08 23:09:23 +09:00
Jiseok CHOI
7250b1f854 refactor(sqlite): add check_cursor_valid method for cursor state validation (#6342)
Extract cursor validity check into a separate method that doesn't hold
the lock. This is useful for executescript which only needs to verify
the cursor state but doesn't need to modify CursorInner.

- Add check_cursor_valid() method that checks if cursor is initialized
  and not closed without retaining the mutex guard
- Use check_cursor_valid() in executescript instead of inner() since
  executescript doesn't modify CursorInner
2025-12-08 21:54:40 +09:00
Jeong, YunWon
42d497a142 Enable PIP test on windows (#6211)
* Patch ensurepip whl to work on windows

* Enable PIP test on windows
2025-12-08 16:36:33 +09:00
Jeong, YunWon
876368e476 windows umask, win32_xstat_slow_impl, fake EXT_SUFFIX (#6340)
* umask

* EXT_SUFFIX

* File Attributes and win32_xstat_slow_impl

* unmark tests
2025-12-08 10:39:15 +09:00
Jeong, YunWon
cab41c807b windows codecs (#6337)
* mbcs_codec

* oem codec
2025-12-08 01:51:51 +09:00
Jeong, YunWon
f4b8b019ca winapi suppliment (#6338)
* winapi.ExitProcess

* Fix winapi Handle

* msvcrt.GetErrorMode

* windows stats

* unmark tests
2025-12-08 01:35:31 +09:00
Jiseok CHOI
a14dd5921d fix(sqlite): Raise ProgrammingError when operating on a closed cursor (#6339) 2025-12-08 00:14:31 +09:00
Jeong, YunWon
cb7450df31 ssl module for windows (#6332)
* SSL for windows

* mark expected failure on test_ssl_in_multiple_threads
2025-12-08 00:08:53 +09:00
Jeong, YunWon
590da47499 pin flate2 under 1.1.5 (#6335) 2025-12-07 12:10:09 +09:00
Jeong, YunWon
aea956d601 WindowsError (#6333) 2025-12-06 17:21:52 +09:00
Jeong, YunWon
56a7fb129a upgrade cranelift (#6331) 2025-12-06 10:01:37 +09:00
Jeong, YunWon
b3141d1231 mmap for windows (#6329) 2025-12-06 09:26:33 +09:00
Jeong, YunWon
89bcae7bea fix time (#6330) 2025-12-06 08:30:57 +09:00
Jeong, YunWon
c826f9d809 PyStructSequence Compatibility (#6327)
* Fix local time

* PyStructSequence
2025-12-05 22:44:00 +09:00
Jeong, YunWon
6f786b58ad Merge pull request #5594 from arihant2math/winreg
Rewrite of winreg module and bump to 3.13.2
2025-12-05 22:31:09 +09:00
Jeong, YunWon
d8dde123b1 Complete winreg 2025-12-05 19:57:26 +09:00
Ashwin Naren
517987c7b3 rewrite of winreg module and add test_winreg 2025-12-05 15:10:45 +09:00
Yash Suthar
c2ca9a7d31 prefer nb_bool slot in try_to_bool instead of __bool__ (#6328)
Fixed: #6113

---------

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
2025-12-05 08:32:45 +09:00
Shahar Naveh
2b90e826ec Use rust idioms for accessing a Vec in codegen/src/compile.rs (#6326)
* Use rust idioms for accessing a `Vec`

* clippy

* Remove `unsafe`
2025-12-04 09:17:04 +09:00
Shahar Naveh
f49c18578a Move PrintExpr to IntristicFunction1 (#6324) 2025-12-03 21:17:36 +09:00
fanninpm
59f422de66 Add _io.TextIOWrapper.detach method (#6267)
* Stub out _io.TextIOWrapper.detach method

* Implement _io.TextIOWrapper.detach method

* Make _io.TextIOWrapper.detach not re-enter lock
2025-12-03 16:11:39 +09:00
Shahar Naveh
305fb489e7 Remove ImportNameless bytecode (#6325) 2025-12-03 07:07:33 +09:00
Shahar Naveh
9f203ee7d2 Update test_print from 3.13.9 (#6323) 2025-12-03 07:05:58 +09:00
Shahar Naveh
26d5307520 Align f-string related bytecodes with 3.13 (#6321)
* Align `f-string` related bytecodes with 3.13

* Resolve name collision

* Adjust for ruff return value
2025-12-03 07:05:16 +09:00
Shahar Naveh
d287d1e063 Sort Instruction enum & related match arms (#6322)
* Sort `Instruction` enum

* Sort `fmt_dis` match arms

* Sort `run_instruction`

* Sort JIT `add_instruction`
2025-12-02 23:25:33 +09:00
Jeong, YunWon
563dc0fc9e Separate Debug from PyPayload (#6320) 2025-12-02 20:20:31 +09:00
Jeong, YunWon
bf8152b4b8 Remove unused _membership_iter_search (#6318) 2025-12-02 10:11:04 +09:00
Shahar Naveh
9130dd8068 Unify BINARY_OP bytecodes (#6317)
* Unify BINARY_OP bytecodes

* Add missing op to `as_inplace`

* Fix doc example

* Fix jit

* Fix doc

* Use correct opname

* Fix dis fmt

* Inplace ops support in JIT
2025-12-02 09:00:26 +09:00
Jeong, YunWon
8e0a86d163 init debug helper (#6315) 2025-11-30 16:58:07 +09:00
Shahar Naveh
b84f7c19ad Fix super and Update test_{descr,super}.py from 3.13.9 (#6314)
* Update `test_descr.py` from 3.13.9

* Update `test_super.py` from 3.13.9
2025-11-30 10:16:50 +09:00
Shahar Naveh
4051becc9e Ensure BuildSlice oparg to be either 2 or 3 (#6313)
* Force `BuildSlice` oparg to be either 2 or 3

* `compile_slice` to return `BuildSliceArgCount`
2025-11-30 09:05:29 +09:00
Jeong, YunWon
6782fa2219 ctypes buffer (#6311)
* Fix array

* from buffer

* AsBuffer

* Fix instruction

* constructable pointer

* thunk

* in_dll

* fix sizeof/alignment
2025-11-29 21:17:04 +09:00
Jeong, YunWon
e5aec9d7fd DISALLOW_INSTANTIATION (#6310) 2025-11-29 12:46:14 +09:00
Jeong, YunWon
4fcce4d0b9 ctypes struct/union/array (#6309)
* PyCStructure

* impl union

* array

* temp remove

* apply review
2025-11-29 12:13:49 +09:00
Jeong, YunWon
95b8c60756 Fix __build_class__ compatibility (#6308)
* Update __build_class__

* fix test
2025-11-29 11:54:04 +09:00
Shahar Naveh
7d8f0b989c Split TestOperator instruction (#6306)
* Split `TestOperator` inatruction

* Update snapshot

* Set as have label
2025-11-29 09:02:52 +09:00
Jeong, YunWon
a81912857d Ctypes __mul__ (#6305) 2025-11-29 02:15:25 +09:00
Jeong, YunWon
23ec5a55ad Fix import ctypes and Lib/ctypes/__init__.py from cpython3.13.9 (#6304)
* Fix ctypes import blockers

* Update Lib/ctypes/__init__.py from cpython3.13.9
2025-11-29 01:32:52 +09:00
Shahar Naveh
fef9de22c4 Remove Rotate* & Duplicate* instructions (#6303)
* Remove `Instruction::Duplicate2?`

* Remove `Instruction::Rotate*` instructions

* Fix jit

* Update snapshot
2025-11-29 00:46:27 +09:00
Jeong, YunWon
9528ee8246 Merge pull request #5653 from arihant2math/ctypes-pt5
_ctypes pt. 5
2025-11-29 00:24:21 +09:00
Jeong YunWon
8af105fc4f Make mergeable 2025-11-29 00:22:44 +09:00
Jeong YunWon
14cf4e32d0 Fix PyCSimple 2025-11-29 00:22:44 +09:00
Ashwin Naren
f37ea52565 Ctypes
more pointer implementation

fix import

add more classes

ctypes overhall

updates

fix build

fix warnings, pass test

fix panic on improper library load

test on macos

formatting

tmp

minor updates
2025-11-28 23:27:24 +09:00
Wildan M
0e6e256f8e Fix redox compilation in stdlib (#6298) 2025-11-28 08:41:22 +09:00
dependabot[bot]
1b3261a090 Bump node-forge from 1.3.1 to 1.3.2 in /wasm/demo (#6297)
Bumps [node-forge](https://github.com/digitalbazaar/forge) from 1.3.1 to 1.3.2.
- [Changelog](https://github.com/digitalbazaar/forge/blob/main/CHANGELOG.md)
- [Commits](https://github.com/digitalbazaar/forge/compare/v1.3.1...v1.3.2)

---
updated-dependencies:
- dependency-name: node-forge
  dependency-version: 1.3.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-28 08:39:46 +09:00
Jeong, YunWon
896144edc3 Merge pull request #6300 from ShaharNaveh/update-libc-177 2025-11-28 08:39:24 +09:00
ShaharNaveh
081a8f0451 Regenerate libc constatnts 2025-11-27 17:16:42 +02:00
ShaharNaveh
e733b7ecf9 Update libc to 0.2.177 2025-11-27 17:15:02 +02:00
Jeong, YunWon
1e7a49036a try auto-format again (#6295) 2025-11-25 20:04:30 +09:00
dependabot[bot]
ea3eb2a9ef Bump actions/checkout from 4 to 6 (#6294)
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Commits](https://github.com/actions/checkout/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-25 05:30:13 +09:00
dependabot[bot]
817f91b5bf Bump xml from 1.0.1 to 1.2.0 (#6292)
Bumps [xml](https://github.com/kornelski/xml-rs) from 1.0.1 to 1.2.0.
- [Changelog](https://github.com/kornelski/xml-rs/blob/main/Changelog.md)
- [Commits](https://github.com/kornelski/xml-rs/compare/1.0.1...1.2.0)

---
updated-dependencies:
- dependency-name: xml
  dependency-version: 1.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-25 05:29:53 +09:00
Jiseok CHOI
f61b62e5a2 Ensure sqlite blob methods respect closed connections (#6290) 2025-11-24 00:04:43 +09:00
Jiseok CHOI
a9469a20d5 Fix sqlite connection reinitialization (#6288)
* Fix sqlite connection reinitialization

* Align sqlite connection reinit with CPython

* Enable sqlite test_connection_bad_reinit

* Fix sqlite reinit flag without threading

* Use stronger memory ordering for initialized flag synchronization
2025-11-22 22:13:06 +09:00
Jiseok CHOI
567fb4dec0 fix(sqlite): raise ProgrammingError when operating on a blob with a closed connection, (#6286)
Fixed #6285
2025-11-22 20:42:24 +09:00
Shahar Naveh
f7ddcd2795 Break after annotation future found (#6284) 2025-11-19 01:00:41 +09:00
Jeong, YunWon
bab03bd75b Merge pull request #6283 from youknowone/test-wasm32-without-js
Test wasm32 without js
2025-11-17 22:10:53 +09:00
Jeong YunWon
9134cca17b Make CI to run rustpython-without-js test 2025-11-17 21:30:28 +09:00
Jeong YunWon
eac8968f84 Add wasm runtime and fix the example code to actually run
Co-Authored-By: Valentyn Faychuk <valy@faychuk.com>
Co-Authored-By: Lee Dogeon <dev.moreal@gmail.com>
2025-11-17 21:30:28 +09:00
Jeong YunWon
5fb5db9617 relocate wasm test crate under example_projects 2025-11-17 18:58:07 +09:00
Shahar Naveh
916d3ba94b Move wasm/lib -> crates/wasm (#6280) 2025-11-17 18:47:05 +09:00
Shahar Naveh
88eca9693a Move stdlib -> crates/stdlib (#6268) 2025-11-16 23:25:45 +09:00
Jeong, YunWon
1a783fc9ec Replace SSL backend to rustls (#6244) 2025-11-16 22:17:35 +09:00
Lee Dogeon
7c4c1eabf0 Fix wasm32-unknown-unknown target build (#6278) 2025-11-16 22:16:34 +09:00
Shahar Naveh
1568d2a7fb Remove leftovers after vm crate move (#6279) 2025-11-16 19:15:32 +09:00
Shahar Naveh
93e4e42b53 Move compiler/source -> crates/compiler-source (#6261) 2025-11-16 19:14:35 +09:00
Jeong YunWon
6991a80e13 Add __main__.__cached__ 2025-11-15 23:09:31 +09:00
Jeong YunWon
4f8ef16937 Re-organize vm.run_script inner functions 2025-11-15 23:09:31 +09:00
Shahar Naveh
8715ae76f1 Move derive -> crates/derive (#6264) 2025-11-15 22:54:25 +09:00
Shahar Naveh
8968aeafb9 Move vm -> crates/vm (#6269) 2025-11-15 21:51:33 +09:00
Shahar Naveh
041dd30602 Move compiler/src -> crates/compiler (#6270) 2025-11-15 19:50:19 +09:00
Shahar Naveh
9e60940f1b Move vm/sre_engine -> crates/sre_engine (#6265) 2025-11-15 19:49:48 +09:00
Shahar Naveh
6479a2063c move derive-impl -> crates/derive-impl (#6263) 2025-11-15 19:49:00 +09:00
Shahar Naveh
cc2e84b9fc Move jit -> crates/jit (#6262) 2025-11-15 18:26:24 +09:00
Shahar Naveh
7f45ba4c9c Move compiler/codegen -> crates/codegen (#6260) 2025-11-15 18:25:46 +09:00
Jeong, YunWon
477c9b32f0 Fix OSError.__str__ to not display 'None' for filename (#6266) 2025-11-15 12:29:20 +09:00
Shahar Naveh
2071fa2e69 Move compiler/literal -> crates/literal (#6259)
* Move `compiler/literal` -> `crates/compiler-literal`

* Use correct crate name
2025-11-15 07:27:04 +09:00
Shahar Naveh
bb54c5b0e6 Move compiler-core -> crates/compiler-core (#6258) 2025-11-15 07:21:29 +09:00
Shahar Naveh
3728879baf Move wtf8 -> crates/wtf8 (#6257) 2025-11-15 07:21:04 +09:00
Shahar Naveh
4b7e49a17e Move common -> crates/common (#6256) 2025-11-15 07:19:53 +09:00
Shahar Naveh
5eac229eae Move pylib -> crates/pylib (#6225)
* Move `pylib

* clean `build.rs` a bit
2025-11-15 07:05:08 +09:00
Jeong, YunWon
609d99f1e3 implement sys.implementation cache_tag (#6255) 2025-11-14 23:55:17 +09:00
Shahar Naveh
db1adaa2c2 Move __doc__ crate to crates/doc (#6234)
* Add `__doc__` crate

* Base auto-generate ci

* Add dummy files

* Update docs

* Set codegen-units to 1 for doc db

* Mark `*.inc.rs` as auto generated

* Disable doctest

* Reset docs
2025-11-14 23:47:51 +09:00
Jiseok CHOI
9ce85862ce Add BaseException.add_note() and __notes__ attribute support (#6252) 2025-11-14 10:31:47 +09:00
dependabot[bot]
4562930233 Bump streetsidesoftware/cspell-action from 7 to 8 (#6246)
Bumps [streetsidesoftware/cspell-action](https://github.com/streetsidesoftware/cspell-action) from 7 to 8.
- [Release notes](https://github.com/streetsidesoftware/cspell-action/releases)
- [Changelog](https://github.com/streetsidesoftware/cspell-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/streetsidesoftware/cspell-action/compare/v7...v8)

---
updated-dependencies:
- dependency-name: streetsidesoftware/cspell-action
  dependency-version: '8'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-12 08:24:16 +09:00
Yash Suthar
0f8c0bc8a8 remove old auto-formte implimentaion (#6251)
Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
2025-11-11 07:35:08 +09:00
Yash Suthar
2d4617236e Update CI auto-formate (#6237)
---------

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
Co-authored-by: fanninpm <luxverdans@sbcglobal.net>
2025-11-10 23:46:14 +09:00
Jeong, YunWon
c9ba9560b5 new_buffer_error (#6243) 2025-11-10 20:58:08 +09:00
Shahar Naveh
9792001703 Add newtype of CodeUnits (#6241) 2025-11-10 09:48:25 +09:00
Jeong, YunWon
d8a4a09ec0 Fix #[pyclass(base=...)] notation (#6242) 2025-11-10 09:47:57 +09:00
fanninpm
ed9a61d956 Add builtin_items updater to whats_left job (#6238)
Corresponds to RustPython/rustpython.github.io#81.
2025-11-09 18:00:59 +09:00
Yash Suthar
5cad66cebf Revert "Update CI auto-format (#6233)" (#6236)
This reverts commit 377151a57f.
2025-11-05 03:14:27 +09:00
Yash Suthar
377151a57f Update CI auto-format (#6233)
---------

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
2025-11-04 17:37:22 +09:00
Shahar Naveh
a7e8ac684b Remove user defined docstrings (#6232) 2025-11-02 00:01:02 +09:00
Jiseok CHOI
e096ce7bc7 Implement property.__name__ attribute (#6230)
* Implement property.__name__ attribute

Add getter and setter for the __name__ attribute on property objects.
The getter returns the explicitly set name if available, otherwise
falls back to the getter function's __name__. Raises AttributeError
if no name is available, matching CPython 3.13 behavior.

The implementation handles edge cases:
- Returns None when explicitly set to None
- Propagates non-AttributeError exceptions from getter's __getattr__
- Raises property-specific AttributeError when getter lacks __name__

This fix enables test_property_name in test_property.py to pass.

* Refactor to use get_property_name in __name__ implementation

Consolidate duplicate logic by making name_getter() use the existing
get_property_name() helper method. This eliminates code duplication
and improves maintainability.

Changes:
- Update get_property_name() to return PyResult<Option<PyObjectRef>>
  to properly handle and propagate non-AttributeError exceptions
- Simplify name_getter() to delegate to get_property_name()
- Update format_property_error() to handle the new return type

This addresses review feedback about the relationship between
get_property_name() and __name__ implementation.

* style comment
2025-11-01 18:30:03 +09:00
Jiseok CHOI
9e7d291b63 Add callable validation to codecs.register_error (#6229)
Validate that the handler argument passed to codecs.register_error
is callable, raising TypeError with message 'handler must be callable'
if it is not. This matches CPython behavior.

This fix enables test_badregistercall in test_codeccallbacks.py to pass.
2025-10-31 00:08:04 +09:00
Jeong, YunWon
614028f9a8 more ssl impl (#6228) 2025-10-29 23:01:04 +09:00
Yash Suthar
8f048dd9fd Implement minimal builtins.anext() (#6226)
* Implement minimal builtins.anext()

* Removed expectedFailure for builtins.anext() tests

* Removed expectedFailure from test_contextlib_async tests fixed by anext

---------

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
2025-10-29 19:09:37 +09:00
Jeong, YunWon
fda9ceea54 Update ssl.py from CPython 3.13.9 (#6217)
* update ssl.py from CPython 3.13.9

* test_ssl

* mark failing tests

* remove test/*.pem

* fix certdata path

* unmark fixed tests
2025-10-28 13:19:12 +09:00
Jeong, YunWon
2acc3be6cf More SSL impl (#6224)
* fix ipv6 formattig

* consts

* fspath

* fix set_ecdh_curve

* minimum/maximum version

* Add SSL_CTX_security_level
2025-10-28 12:00:44 +09:00
Yash Suthar
b6e8a875ac Resolve number slots via MRO in PyNumber and operator, ensure inherit… (#6222)
* Resolve number slots via MRO in PyNumber and operator, ensure inherited and dynamically added methods are found.

Use class().mro_find_map() to mimic the same behaviour as CPython.

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
2025-10-28 12:00:22 +09:00
Christopher Gambrell
6b25fe5c95 5539 - CTRL+Z then Enter will now close shell on Windows. (#6223)
* CTRL+Z then Enter will now close shell on Windows.

* Additional comment.

* Use EOF const

* Add cfg(windows) for EOF_CHAR

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-10-28 11:02:24 +09:00
dependabot[bot]
0e15e771c3 Bump actions/upload-artifact from 4 to 5 (#6221)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 5.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-28 09:37:37 +09:00
dependabot[bot]
d63e44aa3a Bump actions/download-artifact from 5 to 6 (#6220)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 5 to 6.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-28 09:37:14 +09:00
Jeong, YunWon
9a2792a44b PySSLCertificate (#6219) 2025-10-27 22:31:59 +09:00
Jeong YunWon
517b55b8b5 pyssl errors 2025-10-27 18:37:01 +09:00
Jeong YunWon
37915336ea Expand #[pyexception] macro working with module attr 2025-10-27 18:37:01 +09:00
Jeong, YunWon
2e7a8b4735 Implement more SSL methods (#6210)
* openssl-sys version

* selected_alpn_protocol

* get_ciphers

* get_channel_binding

* Add Tls1_1 and Tls1_2

* consts

* fix ssl truncate bug

* verify_flags

* shared ciphers

* verify_client_post_handshake

* shutdown

* get_verified_chain

* fix lints

* fix _wrap_socket

* Fix convert_openssl_error

* clean up ssl

* X509_check_ca

* set default verify flag

* Fix version

* fix import

* consts

* fix httplib
2025-10-26 19:19:24 +09:00
Yash Suthar
c6c931aa0b Fix ldexp to prevent math range errors (#6216)
* Fix ldexp to prevent math range errors

Implemented IEEE 754-compliant handling for large numbers to avoid
overflow and represent results using scientific notation.

Fixes #5471

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>

* Fix ldexp to handle denormalized inputs correctly

Detect denormalized input values below f64::MIN_POSITIVE
Scale subnormal inputs by 2^54 to bring them into normalized range

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>

* tests(math): remove expectedFailure from testLdexp_denormal

As now we have implemented IEEE 754 format , so this will pass.

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>

* Update Lib/test/test_math.py

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

* fixed formate in math.rs

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>

---------

Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-10-26 17:33:49 +09:00
yt2b
1d23f6e8df Panic occurs when formatting with separator and some format specifier (#6213)
* Fix get_separator_interval

* Add extra tests

* Remove FormatType::Number from match arm
2025-10-24 21:41:28 +09:00
Jeong, YunWon
9825d8a376 ensurepip from Python 3.13.9 (#5740) 2025-10-23 19:53:58 +09:00
dependabot[bot]
79dcba8fe7 Bump actions/setup-python from 5 to 6 (#6159)
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5 to 6.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-23 19:05:37 +09:00
Jeong, YunWon
3ec905e08a ssl.{SSLSession,MemoryBIO} (#6209)
* SSLSession

* get_unverified_chain

* SSL MemoryBIO
2025-10-23 18:37:40 +09:00
Jeong, YunWon
2463bdff0e Fix time.strptime (#6208) 2025-10-23 17:28:53 +09:00
Shahar Naveh
153d0eef51 Revert "Use ruff for Expr unparsing (#6124)"
This reverts commit 0fb7d0fae2.
2025-10-22 22:34:52 +09:00
Jeong, YunWon
f22aed2614 Fix PyCode constructor/replace (#6193)
* Fix PyCode constructor

* Reuse MarshalError
2025-10-22 21:09:42 +09:00
Shahar Naveh
0fb7d0fae2 Use ruff for Expr unparsing (#6124)
* Use ruff for unparse backend

* Update `test_future_stmt/*.py` from 3.13.7

* Mark failing tests

* Mark failing test

* Merge remote-tracking branch 'upstream/main' into ruff-unparse

* Reapply ruff code

* remove git symbols

* Unmark passing test
2025-10-22 20:29:50 +09:00
Jeong, YunWon
efd3a4e44b Update Lib with changed files in 3.13.8 (#6186)
* Update changed files from 3.13.7 -> 3.13.8

* Reapply some patches

* Reaaply patches to `test_bytes.py`

* fix test markers in `test_exceptions.py`

* Patch `test_posix.py`

* Patched `test_{pyexpat,site,sysconfig}.py`

* Patched `test_typing.py`

* Patch failing tests in `test_typing.py`

* Update `seq_tests` from 3.13.8

* Mark failing tests in `test_genericalias.py`

* mark failing tests in `test_pyexpat.py`

* Mark failing tests in `test_posix.py`

* reapply patch

* mark failing tests

* skip flaky test
2025-10-22 20:28:05 +09:00
Shahar Naveh
5d9e62390c Update functools from 3.13.9 (#6205)
* Update `functools.py` from 3.13.9

* mark/unmark tests
2025-10-22 20:26:19 +09:00
ShaharNaveh
a50cc9b915 skip flaky test 2025-10-22 12:04:01 +03:00
ShaharNaveh
715529bef1 mark failing tests 2025-10-22 11:36:40 +03:00
ShaharNaveh
68e7310d22 reapply patch 2025-10-22 11:02:36 +03:00
ShaharNaveh
604b708741 Mark failing tests in test_posix.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
e069244f89 mark failing tests in test_pyexpat.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
296da56190 Mark failing tests in test_genericalias.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
624a561145 Update seq_tests from 3.13.8 2025-10-22 10:57:47 +03:00
ShaharNaveh
3f7deb49c8 Patch failing tests in test_typing.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
9557acb1c3 Patched test_typing.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
aa56ebb057 Patched test_{pyexpat,site,sysconfig}.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
84b254209f Patch test_posix.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
e18354b990 fix test markers in test_exceptions.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
360f8caead Reaaply patches to test_bytes.py 2025-10-22 10:57:47 +03:00
ShaharNaveh
9b400a9b6f Reapply some patches 2025-10-22 10:57:47 +03:00
ShaharNaveh
19b6241ef9 Update changed files from 3.13.7 -> 3.13.8 2025-10-22 10:57:47 +03:00
winlogon
b15e537692 Use PyStrRef for TypeAliasType name (#6203)
* fix(PyStrRef): fix TODO in typing.rs where PyObjectRef was used

* chore(fmt): apply rustfmt to code
2025-10-21 12:14:57 +09:00
Jiseok CHOI
2faa05dcfb Fix sqlite Connection initialization check (#6199)
* Fix sqlite3 Connection initialization check

Add proper __init__ validation for sqlite3.Connection to ensure base class
__init__ is called before using connection methods. This fixes the
test_connection_constructor_call_check test case.

Changes:
- Modified Connection.py_new to detect subclassing
- For base Connection class, initialization happens immediately in py_new
- For subclassed Connection, db is initialized as None
- Added __init__ method that performs actual database initialization
- Updated _db_lock error message to match CPython: 'Base Connection.__init__ not called.'

This ensures CPython compatibility where attempting to use a Connection
subclass instance without calling the base __init__ raises ProgrammingError.

* use Initializer trait
2025-10-21 11:11:31 +09:00
Jiseok CHOI
25a464eeae Fix sqlite3 Cursor initialization check (#6198)
Add proper __init__ validation for sqlite3.Cursor to ensure base class
__init__ is called before using cursor methods. This fixes the
test_cursor_constructor_call_check test case.

Changes:
- Modified Cursor to initialize with inner=None in py_new
- Added explicit __init__ method that sets up CursorInner
- Updated close() method to check for uninitialized state
- Changed error message to match CPython: 'Base Cursor.__init__ not called.'

This ensures CPython compatibility where attempting to use a Cursor
instance without calling the base __init__ raises ProgrammingError.
2025-10-21 09:33:55 +09:00
dependabot[bot]
13329f0a48 Bump actions/setup-node from 5 to 6 (#6197)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 5 to 6.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-21 09:32:19 +09:00
Shahar Naveh
fcf196935e Update ruff 0.14.1 (#6195)
* Update ruff to 0.14.1

* Fix test regression in `test_compile`

* Unmark passing test

* Update `test_syntax` from 3.13.9

---------

Co-authored-by: Noa <coolreader18@gmail.com>
2025-10-20 22:46:46 +09:00
Shahar Naveh
9a5d5d6194 Fix CI (#6196)
* Update `vcpkg` to 2025.09.17

* Pin selenium version

* Use `localhost` instead of `0.0.0.0`
2025-10-20 21:40:38 +09:00
fanninpm
3473d824a8 Replace skips in test_importlib/source/test_file_loader with expectedFailures (#6194)
* Replace skips with expectedFailure markings for SimpleTest

* Uncomment Source-PEP451 tests and apply similar monkey-patches as before

* Uncomment Source-PEP302 tests and apply similar monkey-patches as before

* Uncomment Sourceless-PEP451 tests and apply similar monkey-patches as
before

* Uncomment Sourceless-PEP302 tests and apply similar monkey-patches as
before
2025-10-20 17:32:05 +09:00
dependabot[bot]
3b48dcc7c1 Bump serde-wasm-bindgen from 0.3.1 to 0.6.5 (#6188)
Bumps [serde-wasm-bindgen](https://github.com/RReverser/serde-wasm-bindgen) from 0.3.1 to 0.6.5.
- [Commits](https://github.com/RReverser/serde-wasm-bindgen/commits/v0.6.5)

---
updated-dependencies:
- dependency-name: serde-wasm-bindgen
  dependency-version: 0.6.5
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-10-13 11:03:49 +09:00
Anton
b56e469a5f Handle OsError in REPL (#6187) 2025-10-13 10:18:51 +09:00
Shahar Naveh
7986fee56f Revert "Pin CI image to windows-2025 (#6148)" (#6182)
This reverts commit 43d643ad09.
2025-10-12 12:55:46 +09:00
Shahar Naveh
c979059eeb Configure dependabot to ignore ruff updates (#6185)
* Make dependabot ignore ruff updates

* Regenrate Cargo.lock

* Fix clippy

* Fix typo
2025-10-12 12:55:23 +09:00
Shahar Naveh
3a6fda4daf Update opcode from 3.13.7 (#6156)
* Update `opcode` from 3.13.7

* Base `_opcode`

* Add `test__opcode.py` from 3.13.7

* Impl `has_*` methods

* Add more methods

* Update `dis.py` from 3.13.7

* Update `support/bytecode_helper.py` from 3.13.7

* correct is_valid

* Patch failing tests

* Unpatch `support/__init__.py`

* clippy

* Make comments to doc

* impl `_varname_from_oparg` for code

* Unmark passing tests

* Revert changes to `dis`

* Mark failing tests
2025-10-05 11:14:33 +09:00
dependabot[bot]
1aea1467da Bump on-headers, serve and compression in /wasm/demo (#6168)
Bumps [on-headers](https://github.com/jshttp/on-headers) to 1.1.0 and updates ancestor dependencies [on-headers](https://github.com/jshttp/on-headers), [serve](https://github.com/vercel/serve) and [compression](https://github.com/expressjs/compression). These dependencies need to be updated together.


Updates `on-headers` from 1.0.2 to 1.1.0
- [Release notes](https://github.com/jshttp/on-headers/releases)
- [Changelog](https://github.com/jshttp/on-headers/blob/master/HISTORY.md)
- [Commits](https://github.com/jshttp/on-headers/compare/v1.0.2...v1.1.0)

Updates `serve` from 14.2.4 to 14.2.5
- [Release notes](https://github.com/vercel/serve/releases)
- [Commits](https://github.com/vercel/serve/compare/14.2.4...v14.2.5)

Updates `compression` from 1.7.4 to 1.8.1
- [Release notes](https://github.com/expressjs/compression/releases)
- [Changelog](https://github.com/expressjs/compression/blob/master/HISTORY.md)
- [Commits](https://github.com/expressjs/compression/compare/1.7.4...v1.8.1)

---
updated-dependencies:
- dependency-name: on-headers
  dependency-version: 1.1.0
  dependency-type: indirect
- dependency-name: serve
  dependency-version: 14.2.5
  dependency-type: direct:development
- dependency-name: compression
  dependency-version: 1.8.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-21 19:34:03 +09:00
Shahar Naveh
3c01be29c4 Update some tests to 3.13.7 (#6171)
* Update `test_call.py` from 3.13.7

* Update `test_yield_from.py` from 3.13.7

* Update more tests to 3.13.7

* More tests to 3.13.7

* Remove patch from passing test
2025-09-21 19:33:41 +09:00
Shahar Naveh
24f4fbad82 Run scheduled CI jobs only on upstream repo (#6157)
* Run scheduled CI jobs only on upstream repo

* Only disable if scheduling on forks
2025-09-21 02:05:32 +09:00
Shahar Naveh
30cbc41298 Update github actions in CI (#6169)
* Update `setup-python` to v6

* Update `checkout` to v5
2025-09-21 01:53:00 +09:00
dependabot[bot]
150e8ef43d Bump actions/download-artifact from 4 to 5 (#6162)
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 4 to 5.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-21 00:01:06 +09:00
dependabot[bot]
4b91e985ac Bump ruff_python_ast from 0.11.0 to 0.13.1 (#6166)
Bumps [ruff_python_ast](https://github.com/astral-sh/ruff) from 0.11.0 to 0.13.1.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](2cd25ef641...706be0a6e7)

---
updated-dependencies:
- dependency-name: ruff_python_ast
  dependency-version: 706be0a6e7e09936511198f2ff8982915520d138
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-20 23:42:02 +09:00
dependabot[bot]
fdae128cec Bump actions/setup-node from 4 to 5 (#6160)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 4 to 5.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-20 23:41:28 +09:00
Shahar Naveh
11e1330758 Reconfigure dependabot (#6158)
* Add `cargo` to dependabot

* Remove noisy comments

* Don't group updates
2025-09-20 22:46:02 +09:00
Jeong, YunWon
aa0eb4bedf rustpython-common wasm_js feature (#6116) 2025-09-17 09:11:13 +09:00
Shahar Naveh
141ed72693 Dependencies cleanup (#6151)
* Update deps

* Remove some unused deps

* Update lockfile
2025-09-17 09:10:35 +09:00
Shahar Naveh
62067aefd3 Update uuid from 3.13.7 (#6155) 2025-09-16 21:58:36 +09:00
Shahar Naveh
b7d9d7d9ae Update test/test_fstring.py from 3.13.7 (#6154)
* Update `test_fstring.py` from 3.13.7

* Patch failing tests
2025-09-16 21:57:36 +09:00
Shahar Naveh
67958ec791 Update {io,encodings} from 3.13.7 (#6153)
* Update `io` from 3.13.7

* Patch test & upsate `encodings` from 3.13.7

* Unmark passing tests
2025-09-16 21:53:25 +09:00
Jeong, YunWon
b666c52df9 code object linetable (#6150)
* Code.replace

* implement linetable
2025-09-16 21:49:54 +09:00
Shahar Naveh
6ead82154e Update glob from 3.13.7 (#6152) 2025-09-16 09:35:08 +09:00
Shahar Naveh
ca95366219 Update fnmatch from 3.13.7 (#6149) 2025-09-15 21:36:11 +09:00
Shahar Naveh
43d643ad09 Pin CI image to windows-2025 (#6148)
For more info see see:
https://github.blog/changelog/2025-07-31-github-actions-new-apis-and-windows-latest-migration-notice/
2025-09-13 21:24:10 +09:00
Shahar Naveh
cc4ebe6256 Update{runpy,numbers}.py from 3.13.7 (#6141)
* Update number.py from 3.13.7

* Update `runpy.py` from 3.13.7
2025-09-11 22:43:11 +09:00
Shahar Naveh
f429ac4939 Use ast.unparse for generating patches with lib_updater.py (#6142)
* Use `ast.unparse` for decorator generation and every ut_method

* Ensure ut_method type for external patches

* use textwrap

* Apply patches to `test_os.py`

* Apoly on `test_xml_etree.py`

* Run on some test files

* Update `test_str.py`

* Update `test_logging.py` from 3.13.7
2025-09-11 22:42:19 +09:00
Shahar Naveh
0c3d14affc Fix docs link in copilot (#6145) 2025-09-11 14:05:59 +09:00
Shahar Naveh
63de4387e7 Fix broken CI on windows (#6143)
* Fix `test_dtrace.py`

* Fix `test_genericpath.py`

* fix `test_ntpath.py`

* Fix `test_py_compile.py`

* Fix `test_shutil.py`

* fix `test_stat.py`

* Fix `test_tarfile.py`

* Mark failing tests
2025-09-11 14:05:04 +09:00
Shahar Naveh
7044d43dc8 Update {site,sysconfig}.py from 3.13.7 (#6132)
* Update `{site,sysconfig}.py` from 3.13.7

* Update vm/src/stdlib/sysconfig.rs
2025-09-08 13:48:51 +09:00
Shahar Naveh
74c2d490ac Update zoneinfo and _strptime from 3.13.7 (#6139) 2025-09-07 17:09:55 +09:00
Shahar Naveh
59d71be85f Update test_collections.py from 3.13.7 (#6136) 2025-09-07 17:08:35 +09:00
Shahar Naveh
9da2e04880 Update html* from 3.13.7 (#6133) 2025-09-07 17:07:54 +09:00
Shahar Naveh
1d53e0c923 Update codecs from 3.13.7 (#6130) 2025-09-07 16:13:22 +09:00
Shahar Naveh
da71b92dd3 Pickle warning for itertools (#6129) 2025-09-07 16:10:22 +09:00
Jeong, YunWon
b640ef1241 Add comment about 6 params (#6125) 2025-09-07 16:06:49 +09:00
Shahar Naveh
c5c2bd050d Add tool for easier test updates (#6089)
* Add scripts/lib_updater.py

* Update `Lib/test/test_os.py` with tool

* Update `test_list.py` as well
2025-09-07 16:05:54 +09:00
Noa
85ca28094e Apply clippy suggestions to switch to let chains (#6126) 2025-09-04 15:34:10 +09:00
xgampx
48d8031f0c lookup slot in hash() (#6102)
* avoid get_class_attr for __hash__; read hash slot via mro_find_map

Reduce calls and lock acquisitions on hot paths by bypassing get_class_attr(__hash__) and directly resolving the hash implementation with mro_find_map(|cls| cls.slots.hash.load()).

* fix linting in hash function
2025-09-03 23:32:15 -05:00
Noa
0c8ae3a384 Update nix to 0.30 (#6120) 2025-09-04 08:44:27 +09:00
Shahar Naveh
056795eed4 Attenpt to automate posix consts (#6117) 2025-09-03 22:19:30 +09:00
Noa
cca4fe6d80 Switch to newer thread::LocalKey convenience methods (#6123) 2025-09-03 22:14:59 +09:00
Jeong, YunWon
d17dcd817e Merge pull request #6115 from ShaharNaveh/update-some-tests-2
Update some tests from 3.13.7
2025-09-03 00:27:57 +09:00
Shahar Naveh
1688e744ba fn unparse_expr -> UnparseExpr::new (#6121) 2025-09-02 23:55:42 +09:00
Shahar Naveh
8b6e1e398b Update test_itertools.py to 3.13.7 (#6122)
* Update `test_itertools.py` to 3.13.7

* Apply patch where test name was changed

* Fix some failing tests
2025-09-02 20:19:57 +09:00
Noa
fa91df6539 Merge pull request #6118 from ever0de/feat/sqlite-fetchmany-size-arg
sqlite3: Support 'size' keyword argument in `Cursor::fetchmany`
2025-09-01 14:17:35 -05:00
Noa
2b67f40c34 Merge pull request #6119 from ShaharNaveh/update-deps
Update dns-lookup and xml-rs (renamed to xml)
2025-09-01 12:50:41 -05:00
ShaharNaveh
1d1aa663f0 Trigger CI 2025-09-01 16:49:06 +03:00
ShaharNaveh
1fe5fd55d3 Update xml(-rs) to 1.0 2025-09-01 14:01:03 +03:00
ShaharNaveh
711f95ec09 Update dns-lookup to 3.0 2025-09-01 13:59:16 +03:00
ShaharNaveh
020692e56b Update lockfile 2025-09-01 11:28:04 +03:00
ShaharNaveh
de3cb8cdbb Mark more failing tests 2025-09-01 11:19:00 +03:00
Jiseok CHOI
2e16f51c68 use FromArgs 2025-09-01 15:43:07 +09:00
Jiseok CHOI
a2b194a6f8 sqlite3: Support 'size' keyword argument in Cursor::fetchmany 2025-09-01 15:23:04 +09:00
ShaharNaveh
373de5ee57 Update test_with.py from 3.13.7 2025-08-31 12:43:52 +03:00
ShaharNaveh
a1c11cdc40 Update test_fileio.py from 3.13.7 2025-08-31 12:37:48 +03:00
ShaharNaveh
41fb6c5a1a Add Lib/test/test_file_eintr.py from 3.13.7 2025-08-31 12:23:58 +03:00
ShaharNaveh
e00a95d15c Update test_userdict.py from 3.13.7 2025-08-31 12:14:40 +03:00
ShaharNaveh
d732c307dc Update test_univnewlines.py from 3.13.7 2025-08-31 12:13:09 +03:00
ShaharNaveh
6a3c348351 Update test_richcmp.py 2025-08-31 12:01:32 +03:00
ShaharNaveh
ec8f37dcd6 Update test_pprint.py from 3.13.7 2025-08-31 11:59:46 +03:00
ShaharNaveh
88506059f9 Update test_pow.py from 3.13.7 2025-08-31 11:58:21 +03:00
ShaharNaveh
15b1b62adb Update test_isinstance.py from 3.13.7 2025-08-31 11:50:04 +03:00
ShaharNaveh
6a4d4b727c Uodate test_grammar.py from 3.13.7 2025-08-31 11:47:32 +03:00
ShaharNaveh
d9ffc47c43 Update test_dynamic.py from 3.13.7 2025-08-31 11:09:34 +03:00
ShaharNaveh
ed6caed3d9 Update test_decorators.py from 3.13.7 2025-08-31 11:08:20 +03:00
ShaharNaveh
37324b443b Update test_eof.py from 3.13.7 2025-08-31 10:54:43 +03:00
ShaharNaveh
88b12bafc9 Update test_kqueue.py from 3.13.7 2025-08-31 10:35:23 +03:00
ShaharNaveh
b56082a980 Update test_keywordonlyarg.py from 3.13.7 2025-08-31 10:34:57 +03:00
Noa
75093873b8 Merge pull request #5789 from coolreader18/crt_fd-rework
Rework crt_fd to be more aligned with io-safety
2025-08-29 11:02:38 -05:00
Noa
8437b06dad Unmark passing tests 2025-08-29 10:59:53 -05:00
Noa
dc4be47751 Windows fixes 2025-08-29 10:59:53 -05:00
Noa
51cbf57470 Rework crt_fd to be more aligned with io-safety 2025-08-29 10:59:51 -05:00
Jeong, YunWon
1c992f84e5 Merge pull request #6110 from youknowone/pattern-mapping
More Pattern matching implementation mapping + class
2025-08-28 12:59:52 +09:00
Jack O'Connor
763d5d48b5 Add sorted.py to microbenchmarks (#6086)
* Add microbenchmark for `sorted`

I chose 5 * Iterations to try better show that RustPython
sort implementation scales noticeably worse CPython's
with respect to the number of elements.

* Mention how to run a specific benchmark

* Update python version in bench README

3.13 better reflects the current state of the project vs 3.7.
2025-08-28 09:58:20 +09:00
Jeong YunWon
f4543f5f51 Fix defaultdict 2025-08-26 21:49:26 +09:00
Jeong YunWon
be54bc0dfd Fix multiple inheritance 2025-08-26 21:49:10 +09:00
Jeong YunWon
b807bc7fc4 Fix patma guard 2025-08-26 21:48:46 +09:00
Jeong YunWon
21fb4aafcf apply review 2025-08-26 21:48:46 +09:00
Jeong YunWon
4b638011bb Add failing test markers 2025-08-26 21:48:46 +09:00
CPython Developers
a109a596c8 Import test_patma from CPython 3.13.7 2025-08-26 21:48:46 +09:00
Jeong YunWon
8ae2dc75f6 MATCH_SELF 2025-08-26 21:48:46 +09:00
Jeong YunWon
50c557419e more match pattern 2025-08-26 21:48:46 +09:00
Jeong, YunWon
c6d1a5784a Fix mkdir error args (#6114) 2025-08-26 20:46:22 +09:00
Jeong, YunWon
776cabb883 New Instruction ToBool,PopJumpIfFalse (#6112)
* New Instruction ToBool

* Rename JustIf{True,False} => PopJumpIf{...}
2025-08-26 16:12:14 +09:00
Jeong, YunWon
16cdcfb96f Fix PyNumber::boolean (#6111) 2025-08-26 15:16:47 +09:00
Jeong, YunWon
711b1a62d5 PyTypeFlags::{SEQUENCE,MAPPING} (#6109) 2025-08-26 10:42:05 +09:00
Jeong, YunWon
dae95849ea Update some tests from 3.13.7 (#6108)
* Update `test_opcache.py`

* Update test_optparse.py

* Add some missing folders & test files

* Update `test_long.py` and impl "is_integer" for int

* Update `support/hypothesis_helper.py` from 3.13.7

* Update test_binascii

* Update test_math

* Add `test_math_property.py`

* Update `test_property.py` from 3.13.7

* Update `test_cmath.py` from 3.13.7

* Unmark passing tests

* Update `test_ucn.py` from 3.13.7

* Mark failing tests

* Add `site-packages` dir
2025-08-24 17:44:31 +09:00
Shahar Naveh
5c6f92d497 Fix unused imports for android (#6106) 2025-08-24 17:04:09 +09:00
ShaharNaveh
e7c87969f0 Add site-packages dir 2025-08-24 10:36:07 +03:00
ShaharNaveh
6cb00e2ae9 Mark failing tests 2025-08-24 00:44:32 +03:00
ShaharNaveh
d28164c150 Update test_ucn.py from 3.13.7 2025-08-24 00:17:50 +03:00
ShaharNaveh
61bc6e8d1c Unmark passing tests 2025-08-23 23:21:19 +03:00
ShaharNaveh
6a232a8830 Update test_cmath.py from 3.13.7 2025-08-23 22:20:54 +03:00
ShaharNaveh
d82554124c Update test_property.py from 3.13.7 2025-08-23 22:13:48 +03:00
ShaharNaveh
1fbd1cd28f Add test_math_property.py 2025-08-23 22:09:11 +03:00
ShaharNaveh
7e03ec7812 Update test_math 2025-08-23 22:06:50 +03:00
ShaharNaveh
fa3ecba7a5 Update test_binascii 2025-08-23 21:53:29 +03:00
ShaharNaveh
2de20539a9 Update support/hypothesis_helper.py from 3.13.7 2025-08-23 21:46:28 +03:00
ShaharNaveh
933db1075f Update test_long.py and impl "is_integer" for int 2025-08-23 21:43:35 +03:00
ShaharNaveh
c0b3cc9048 Add some missing folders & test files 2025-08-23 19:45:53 +03:00
ShaharNaveh
713cb7043e Update test_optparse.py 2025-08-23 19:44:08 +03:00
ShaharNaveh
b4d086b540 Update test_opcache.py 2025-08-23 19:25:28 +03:00
Shahar Naveh
e3e0e8a364 Update base64.py from 3.13.6 (#6087) 2025-08-21 13:22:21 +09:00
Jiseok CHOI
e909e32f31 sqlite: Fix missing ProgrammingError for parameter mismatch (#6104) 2025-08-21 13:19:38 +09:00
Shahar Naveh
9417e1023d Update xml from 3.13.7 (#6100) 2025-08-21 13:15:39 +09:00
Jack O'Connor
109e64c2ba Allow multiple indented blocks in REPL (#6097)
There aren't any tests but being able to do nested for loops seems like
a pretty big win to me so I'm going to put up for review.

The original returned boolean clearly had **false positives** for
detecting bad errors for things like nested `if` and `for` statements.
What is less clear is if there are any **true positives** which I am no
longer catching with the updated return value.

Co-authored-by: Jack O'Connor <jack@jackoconnor.dev>
2025-08-21 13:15:02 +09:00
Shahar Naveh
ceb7046bc4 Fix int respect sys.set_int_max_str_digits value (#6094) 2025-08-21 13:14:10 +09:00
Jeong, YunWon
bfc513e997 Fix future clippy warnings (#6103) 2025-08-20 17:34:29 +09:00
Shahar Naveh
527ce3a872 Update Lib/test/test_float.py from 3.13.7 (#6099)
* Update `Lib/test/test_float.py` from 3.13.7

* Update mathdata

* Unmark passing tests
2025-08-20 14:16:19 +09:00
Lee Dogeon
44a8c9f0b3 Remove completed TODO of extra_tests/fstring.py (#6095) 2025-08-20 14:08:53 +09:00
Shahar Naveh
e6001a48d7 Update netrc.py from 3.13.6 and make pwd accesible on Android (#6083) 2025-08-20 14:08:05 +09:00
Shahar Naveh
242814fa72 Update locale.py from 3.13.6 and made _locale available on android (#6091) 2025-08-20 13:44:57 +09:00
Jeong, YunWon
ddc08498cc Fix match mapping pattern (#6081) 2025-08-20 13:26:18 +09:00
Jeong, YunWon
a9a9e3bf11 Merge pull request #6085 from youknowone/dict-update 2025-08-09 07:41:13 +09:00
Jeong YunWon
d56fcd0774 DictUpdate instruction 2025-08-08 23:53:40 +09:00
Jack O'Connor
33ea50c2e9 Add return annotation to __annotations__ last (#6071)
Functions like `functools.singledispatch` are sensitive to the order of
items in the `__annotations__` map.

CPython puts returns last.
2025-08-08 23:31:12 +09:00
Jiseok CHOI
e922722191 Implement type check in member descriptor __set__ (#6080) 2025-08-08 19:45:15 +09:00
Jeong, YunWon
158c027c23 Rust 1.89 clippy fix (#6082) 2025-08-08 15:00:18 +09:00
Shahar Naveh
133aada0b7 Update os.py from 3.13.5 (#6076)
* Update `os.py` from 3.13.5

* Set availablity of some `os` functions

* revert some cfg

* Mark more failing tests
2025-08-08 14:37:35 +09:00
Jeong, YunWon
4ae5a1f894 Fix ImportError fields (#6079) 2025-08-07 18:29:05 +09:00
Jack O'Connor
93eacdac20 Update zipapp.py from 3.13.5 (#6075) 2025-08-06 10:31:55 +09:00
Shahar Naveh
cac4948afe Update rustyline & socket2 (#6074)
* Update rustyline to 17.0.0

* Update dns-lookup and socket2

* run `cargo update`
2025-08-06 10:31:21 +09:00
Jack O'Connor
b480d234dd Reorder struct lconv members to match locale.h (#6073)
`struct lconv` in locale.h
https://codebrowser.dev/glibc/glibc/locale/locale.h.html#lconv::int_p_cs_precedes.

Order of relevant section in glibc locale.h
```C
char int_p_cs_precedes;
char int_p_sep_by_space;
char int_n_cs_precedes;
char int_n_sep_by_space;
```
2025-08-06 10:30:23 +09:00
Shahar Naveh
91979a3d0e Update {nt,posix}path.py from 3.13.5 (#6070)
* Update `{nt,posix}path.py` from 3.13.5

* Mark failing tests
2025-08-05 23:18:10 +09:00
Shahar Naveh
f5a77a1f68 Update difflib.py from 3.13.5 (#6067) 2025-08-05 17:53:34 +09:00
Jiseok CHOI
a58d582001 Implement unsupported ops for sqlite3.Blob (#6066) 2025-08-05 17:53:06 +09:00
Shahar Naveh
c4a805107f Update genericpath.py from 3.13.5 (#6065) 2025-08-04 20:10:02 +09:00
Shahar Naveh
72fc3c0ba4 Update pickle{tools,}.py from 3.13.5 (#6064) 2025-08-04 20:09:36 +09:00
Shahar Naveh
566d9aabae Update gettext.py from 3.13.5 (#6063) 2025-08-04 20:08:35 +09:00
Shahar Naveh
18a9bf0caf Update configparser.py from 3.13.5 (#6062) 2025-08-04 20:08:17 +09:00
Shahar Naveh
4841776856 Update contextlib from 3.13.5, (#6056)
* Update `contextlib` from 3.13.5

* Add `test_contextlib_async.py`
2025-08-01 22:39:00 +09:00
Shahar Naveh
710941c27f Update bz2.py from 3.13.5 (#6055) 2025-08-01 22:16:32 +09:00
Shahar Naveh
2d65c7f859 Update some deps (#6053) 2025-08-01 22:14:56 +09:00
Jeong, YunWon
92fdfc4c37 Prevent direct instantiation of sqlite3.{Statement,Blob} (#6052)
* Prevent direct instantiation of sqlite3.{Statement,Blob}

* Use `Unconstructible` trait for internal types
2025-08-01 22:13:19 +09:00
Shahar Naveh
7f1fc3602f Add symtable.py from 3.13.5 (#6048)
* Add `symtable.py` from 3.13.5

* Update symtable methods

* Correct `type` return type
2025-08-01 22:12:11 +09:00
Jiseok CHOI
ec0a2325e4 Use Unconstructible trait for internal types 2025-08-01 18:04:15 +09:00
Jeong, YunWon
c3754cdca2 Merge pull request #6049 from youknowone/fix-support
Fix test.support.requires_debug_ranges
2025-08-01 17:52:58 +09:00
Jiseok CHOI
b2d6594bd9 Prevent direct instantiation of sqlite3.{Statement,Blob} 2025-08-01 13:39:45 +09:00
Jeong YunWon
f8891ffe3a Fix test_compile 2025-08-01 09:17:08 +09:00
Jeong YunWon
36cc6d1945 Backport CPython gh-137195
https://github.com/python/cpython/pull/137195
2025-08-01 09:16:34 +09:00
Shahar Naveh
f32a5b105a Update unittest partially (#6051)
* Update `test_unittest` from 3.13.5

* Remove old `test_unittest.py`
2025-07-31 10:53:39 +09:00
Ashwin Naren
1c55f9eee2 Add test.support.interpreters at 3.13.2 (#5684) 2025-07-30 20:20:07 +09:00
Jiseok CHOI
1e6da5f430 sqlite: Align Connection.__call__ error handling with CPython (#6042) 2025-07-30 14:05:17 +09:00
Jeong, YunWon
cee579e7ea Merge pull request #6047 from youknowone/wtf8 2025-07-30 12:45:03 +09:00
Shahar Naveh
4bf32a04f4 Apply some clipy lints (#6045) 2025-07-30 12:16:02 +09:00
Jeong YunWon
9583af057b Apply PyUtf8Str 2025-07-30 12:14:47 +09:00
Jeong YunWon
d46c882347 remove try_to_str
Rewrite sqlite3 UTF8 validation
2025-07-30 12:14:47 +09:00
Jeong YunWon
053cfeecce downcastable_from 2025-07-30 12:02:37 +09:00
Jeong, YunWon
f402deef6d Deprecate ::new_ref (#6046) 2025-07-30 01:09:21 +09:00
Jeong, YunWon
59a8a569dd Wtf8-compatible fixes (#5985)
* deprecate more payload_* functions

* loose trait bount for PyInterned

* Fix levenstein

* Fix genericalias

* Fix PyBoundMethod::repr

* fix repr

* Fix fromhex
2025-07-30 01:03:12 +09:00
Shahar Naveh
57029f6efa Derive Default for GroupByState (#6043) 2025-07-29 00:55:13 +09:00
Jiseok CHOI
d8f1d188c3 stdlib(sqlite): Raise ProgrammingError in closed Blob context manager (#6041) 2025-07-27 21:47:05 +09:00
Jeong, YunWon
89c58d678a Merge pull request #6037 from ShaharNaveh/update-support-init
Update `Lib/test/support/__init__.py` from 3.13.5
2025-07-27 10:50:52 +09:00
Jiseok CHOI
38ca076cb5 feat(stdlib/sqlite): Implement slice assignment for Blob (#6039) 2025-07-27 10:43:11 +09:00
ShaharNaveh
69f6423424 Try to have time_ns same as std 2025-07-26 20:01:21 +02:00
ShaharNaveh
d5793e04ec Don't import unittest.mock in test_int.py 2025-07-26 17:48:07 +02:00
ShaharNaveh
cbe975818e Remove extra spaces 2025-07-26 17:47:53 +02:00
ShaharNaveh
06196fa4f4 Merge remote-tracking branch 'upstream/main' into update-support-init 2025-07-26 17:31:26 +02:00
ShaharNaveh
0d1a02583a Have time_ns for wasi 2025-07-26 17:30:46 +02:00
Jack O'Connor
4079776c36 Add kde function and tests to RustPython statistics module (#6030)
* Copy CPython 3.13 statistics module into RustPython

* Adjust CPython "magic constants" in KDE tests

## test_kde

I'm not too sure why but this one takes a few seconds to run the second
for loop which calculates the cumulative distribution and does a rough
calculation of the area under the curve.

## test_kde_random

I have a lower bound for RustPython to sort a random list of 1_000_000
numbers on my laptop of > 1 hour. By dropping n to 30_000 sort will not
take an egregious amount of time to run. It is then necessary to lower
the tolerance for the math.isclose check, or the computed values may
**randomly** fail due to the higher variance caused by the smaller
sample size.

* Reintroduce expected failure in test_statistics.TestNormalDict.test_slots

* Sync Rust `normal_dist_inv_cdf` with Python equivalent

See https://github.com/python/cpython/pull/95265.

To quote:
> Restores alignment with random.gauss(mu, sigma) and
random.normalvariate(mu, sigma) both. of which are equivalent to
sampling from NormalDist(mu, sigma).inv_cdf(random()). The two functions
in the random module happy accept sigma=0 and give a well-defined
result.

> This also lets the function gently handle a sigma getting smaller,
eventually becoming zero. As sigma decrease, NormalDist(mu,
sigma).inv_cdf(p) forms a tighter and tighter internal around mu and
becoming exactly mu in the limit. For example, NormalDist(100,
1E-300).inv_cdf(0.3) cleanly evaluates to 100.0but withsigma=1e-500``
the function previously would raised an unexpected error.
2025-07-26 00:42:22 +09:00
ShaharNaveh
b829333f1d Fix patch of gc_threshold 2025-07-25 16:59:37 +02:00
ShaharNaveh
0e3ff8ae5f Fix patch of disable_gc 2025-07-25 16:58:25 +02:00
ShaharNaveh
73f5ceb79b Update test_int.py 2025-07-25 16:20:36 +02:00
ShaharNaveh
a5b240aab8 skip crashing test 2025-07-25 16:13:07 +02:00
ShaharNaveh
0648e975d9 Upsate test_dictviews 2025-07-25 16:07:59 +02:00
ShaharNaveh
5d9f9acb1d Update test_collections.py 2025-07-25 16:06:00 +02:00
ShaharNaveh
26cdbfe048 Mark tests correctly 2025-07-25 15:59:14 +02:00
ShaharNaveh
17e60754f6 Fix patching of support 2025-07-25 15:47:48 +02:00
ShaharNaveh
bb08398957 Update test_userlist.py 2025-07-25 15:47:32 +02:00
ShaharNaveh
0d1a68dfab mark failing tests in test_picklebuffer.py 2025-07-25 15:41:37 +02:00
ShaharNaveh
7f97034055 Mark failing tests 2025-07-25 14:53:03 +02:00
ShaharNaveh
409f5dda9f Add more code to support/__init__.py 2025-07-25 14:53:03 +02:00
ShaharNaveh
68cd33f37e Update pickle tests from 3.13.5 2025-07-25 14:53:03 +02:00
ShaharNaveh
4fb5736694 Add run_doctest 2025-07-25 14:53:03 +02:00
ShaharNaveh
b51f6de0c8 Reapply RustPython patches 2025-07-25 14:53:03 +02:00
ShaharNaveh
3058d99fd5 Copy parts of old code to make libregtest work 2025-07-25 14:53:03 +02:00
ShaharNaveh
74201365c6 Update Lib/test/support/__init__.py from 3.13.5 2025-07-25 14:53:03 +02:00
Shahar Naveh
c232b7f1f8 Update csv.py from 3.13.5 (#6035)
* Use `raise_if_stop!` macro

* Update `csv.py` from 3.13.5

* Mark failing tests
2025-07-25 19:08:01 +09:00
Shahar Naveh
ae03bacb39 Update {_py,}decimal.py from 3.13.5 (#6034) 2025-07-25 19:04:49 +09:00
Jiseok CHOI
fb9147736d stdlib(sqlite3): Raise ProgrammingError for missing named parameter (#6036) 2025-07-25 19:02:56 +09:00
Shahar Naveh
9499d39f55 Update html from 3.13.5 (#6031) 2025-07-25 10:58:21 +09:00
Shahar Naveh
6a9579efc7 Update trace.py from 3.13.5 (#6029) 2025-07-25 10:50:41 +09:00
Shahar Naveh
8621b3d7da Added pyclbr from 3.13.5 (#6028) 2025-07-25 10:50:17 +09:00
Shahar Naveh
24f2524e6e Added "os.wait" tests from 3.13.5 (#6027)
* Added "wait" tests from 3.13.5

* Trigger CI
2025-07-25 10:49:05 +09:00
Shahar Naveh
74bee7cbbe Update codeop.py from 3.13.5 (#6026) 2025-07-25 10:47:20 +09:00
Shahar Naveh
01edb93957 Resolve libc::RLIM_NLIMITS warning on android (#6025)
* Resolve warning on android

* Apply CodeRabbit suggestion
2025-07-25 10:46:32 +09:00
Jiseok CHOI
bcf56279ec Raise UnicodeEncodeError for surrogates in sqlite.executescript (#6024) 2025-07-25 10:45:33 +09:00
Shahar Naveh
6bce5e1616 Cleanup vm/src/stdlib/stat.rs (#6018) 2025-07-25 10:44:49 +09:00
Shahar Naveh
b7336366cb Update test_enumerate.py from 3.13.5 (#6032) 2025-07-25 10:43:16 +09:00
Shahar Naveh
96f47a415e Export ruff_source_file types in rustpython_compiler_core (#6020)
* export ruff types in `compiler::core`

* Use exported ruff types in `vm/**`

* unlink `ruff_source_file` as a direct dependency
2025-07-23 12:28:38 +09:00
Shahar Naveh
582e25b11b Update tabnanny.py from 3.13.5 (#6021) 2025-07-23 12:27:56 +09:00
Shahar Naveh
d897f9e0e0 Unpin Rust nightly in CI (#6022) 2025-07-23 12:27:41 +09:00
Shahar Naveh
9995cc60b5 Update warnings from 3.13.5 (#6019) 2025-07-23 12:27:26 +09:00
Shahar Naveh
ba22ad2c0c Replace compiler::source module with ruff_source_file (#6016)
* Replace `compiler::source`` with ruff

* Require `ruff_source_file`
2025-07-22 20:52:25 +09:00
Jiseok CHOI
57bdf35ee6 Enforce valid UTF-8 encoding for sqlite collation names (#6015)
* Make public `PyStr::ensure_valid_utf8`

* Enforce valid UTF-8 encoding for sqlite collation names
2025-07-21 23:42:47 +09:00
Jiseok CHOI
bbe98ddd86 Construct detailed message on text decode failure (#6014) 2025-07-21 22:33:09 +09:00
Jeong, YunWon
52395497dd Update test_typing from Python 3.13.5 (#6013) 2025-07-21 21:14:25 +09:00
Jeong, YunWon
bd7947ec8f Fix test_typing.test_args_kwargs (#6012) 2025-07-21 16:54:27 +09:00
Jeong, YunWon
a1ee7f5461 Fix __dict__ getset type (#6010) 2025-07-21 16:13:17 +09:00
Jeong, YunWon
cd58d154cf Type alias type (#6011)
* Constructor for TypeAliasType

* Fix PyBaseObject::py_new

* Representable for TypeAliasType
2025-07-21 14:42:18 +09:00
Jeong, YunWon
3bce41baab Fix test_typing.test_unpack_wrong_type (#6009) 2025-07-21 00:54:14 +09:00
Jeong, YunWon
99c1afe0be compile_subscript (#6008)
* ListToTuple

* star_unpack_helper
2025-07-21 00:53:36 +09:00
Shahar Naveh
c497061290 Update json from 3.13.5 (#6007)
* Update `json` from 3.13.5

* Update `test_json` from 3.13.5
2025-07-20 18:44:46 +09:00
Shahar Naveh
8177525d49 Update ast.py from 3.13.5 (#6006) 2025-07-20 18:37:38 +09:00
Jeong, YunWon
4e0c1aa83d compile_type_param_bound_or_default (#6005) 2025-07-20 17:12:56 +09:00
Jiseok CHOI
ff35dcd95a feat(vm/slot): implement Py_TPFLAGS_MANAGED_DICT for class objects (#5949) 2025-07-20 14:11:36 +09:00
Jeong YunWon
5284b73320 Refactor compile_function 2025-07-20 10:57:24 +09:00
Jeong YunWon
7736df030a Fix scope error 2025-07-20 10:57:24 +09:00
Jeong YunWon
6b773f6e14 Fix is_optimized 2025-07-20 10:57:24 +09:00
Jiseok CHOI
6f80ac0edd Align SQL comment parsing with CPython (#5996) 2025-07-20 10:51:42 +09:00
Shahar Naveh
d7a9b69995 Update stat from 3.13.5 (#5992)
* Update stat from 3.13.5

* Set correct value for S_IFWHT on macos
2025-07-20 10:37:43 +09:00
Shahar Naveh
4f9dd41041 Update _weakrefset.py from 3.13.5 (#6004)
* Update `_weakrefset` from 3.13.5

* Update `test_weakset.py` from 3.13.5
2025-07-20 10:33:22 +09:00
Shahar Naveh
9739592798 Update logging from 3.13.5 (#6003)
* Update logging from 3.13.5

* Mark failing tests

* Mark some failing windows tests

* Skip flaky test

* Mark more failing tests
2025-07-20 10:33:02 +09:00
Shahar Naveh
cb6057a50c Update selector.py from 3.13.5 (#6002) 2025-07-20 10:31:58 +09:00
Shahar Naveh
11b8e73566 Merge pull request #6000 from ShaharNaveh/update-mp
Update multiprocess from 3.13.5
2025-07-20 10:31:30 +09:00
Jeong, YunWon
da5a44ee01 Pin rustc nightly to nightly-2025-07-18 for miri tests (#5999)
* Pin rustc nightly to `nightly-2025-07-18` for miri tests

* Fix indent

* Set the miri rustc channel via env var
2025-07-20 00:33:49 +09:00
ShaharNaveh
95880cee72 Set the miri rustc channel via env var 2025-07-19 11:42:49 +02:00
ShaharNaveh
6b1e4a7964 Fix indent 2025-07-19 11:30:43 +02:00
Shahar Naveh
fa7849d43f Pin rustc nightly to nightly-2025-07-18 for miri tests 2025-07-19 11:28:45 +02:00
Jiseok CHOI
bd8e557b70 test(importlib): Enable bad bytecode tests for PEP451 loaders (#5997) 2025-07-19 12:16:19 +09:00
Jiseok CHOI
f8d03fd680 Correctly implement isolation_level setter to handle deletion (#5983) 2025-07-18 23:08:51 +09:00
Jeong, YunWon
799f38baea Merge pull request #5978 from ShaharNaveh/update-test-exception
Update `test_exception*.py` from 3.13.5
2025-07-17 13:55:25 +09:00
Shahar Naveh
1fcb656363 Set {min,max}_arity (#5994)
* General cleanup

* Compute {min,max}_arity
2025-07-17 13:49:25 +09:00
Shahar Naveh
80a9e0ed54 Update rlcompleter from 3.13.5 (#5990) 2025-07-17 13:44:18 +09:00
Shahar Naveh
559a7a56e5 Update _colorize.py from 3.13.5 (#5988) 2025-07-17 13:43:32 +09:00
Jiseok CHOI
5f1290d86e Implement properties on _TextIOBase and StringIO (#5987) 2025-07-17 13:42:38 +09:00
Shahar Naveh
63e6c01924 CI: Increase windows timeout from 40 -> 45 (#5993) 2025-07-17 00:04:51 +09:00
Shahar Naveh
04407be6b2 Update secrets from 3.13.5 (#5991) 2025-07-17 00:04:12 +09:00
Shahar Naveh
a0a6f735a1 Update quopri from 3.13.5 (#5989) 2025-07-17 00:03:25 +09:00
ShaharNaveh
4515c614bf mark more tests 2025-07-16 13:37:18 +03:00
ShaharNaveh
9e22580a95 Update test_faulthandler from 3.13.5 2025-07-16 13:37:18 +03:00
ShaharNaveh
058c76cee8 mark a failing test 2025-07-16 13:37:18 +03:00
ShaharNaveh
323b2da2dd Remove duplicated class name 2025-07-16 13:37:18 +03:00
ShaharNaveh
55e2c97154 Don't require debug_ranges 2025-07-16 13:37:18 +03:00
ShaharNaveh
2c87988f8d Update test_traceback.py from 3.13.5 2025-07-16 13:37:18 +03:00
ShaharNaveh
f6d755b4ff mark failing tests 2025-07-16 13:37:18 +03:00
ShaharNaveh
0fbe6ce268 Update test_exceptions from 3.13.5 2025-07-16 13:37:18 +03:00
ShaharNaveh
e064f8cef2 Update test_exception_variations.py from 3.13.5 2025-07-16 13:37:18 +03:00
ShaharNaveh
f53a8d919a Don't skip passing test 2025-07-16 13:37:18 +03:00
ShaharNaveh
966d6d2d26 Update test_exception_group.py from 3.13.5 2025-07-16 13:37:18 +03:00
Jeong, YunWon
6a3dff63bb Downcastable (#5986)
* simplify int power

* downcastasble

* deprecate payload*
2025-07-16 18:00:18 +09:00
Jiseok CHOI
177bfb7077 Remove deleter attribute from pygetset (#5984) 2025-07-16 09:44:14 +09:00
Shahar Naveh
5309e8c7c4 Fix invalid args count msg (#5960) 2025-07-16 01:54:51 +09:00
Jiseok CHOI
5957f5d31a Fix off-by-one error in SQL length limit check (#5982) 2025-07-16 01:53:20 +09:00
Jiseok CHOI
f465af3a7c Reject SQL queries containing null characters (#5981) 2025-07-16 01:52:28 +09:00
Jiseok CHOI
6d2152cafe Correctly handle None for protocol in adapt(..) (#5979) 2025-07-16 01:49:53 +09:00
Shahar Naveh
a54873d302 Update shlex from 3.13.5 (#5977) 2025-07-15 21:27:05 +09:00
Jeong, YunWon
b965ce7392 Remove misplaced SymbolScope::TypeParams (#5975)
* Rename SymbolTableType -> CompileScope

* Remove SymbolScope::TypeParams
2025-07-15 17:56:19 +09:00
Jeong, YunWon
2dd0ce54f9 remove ellipsis() (#5973) 2025-07-15 16:10:40 +09:00
Jeong, YunWon
1d3603419e SetFunctionAttribute (#5968)
* PyRef::into_non_null

* SetFunctionAttribute

* set_function_attribute

* frame helper in PyFuncion

* remove closure lock

* cleanup unused args
2025-07-15 03:12:23 +09:00
Jiseok CHOI
d4f85cf073 Provide detailed error for circular from imports (#5972) 2025-07-15 01:45:42 +09:00
Jiseok CHOI
ed433837b3 Introduce PyUtf8Str and fix(sqlite): validate surrogates in SQL statements (#5969)
* fix(sqlite): validate surrogates in SQL statements

* Add `PyUtf8Str` wrapper for safe conversion
2025-07-15 00:54:42 +09:00
Jeong, YunWon
fd35c7a706 Impl Drop for PyAtomicRef (#5970) 2025-07-14 22:54:44 +09:00
Jeong YunWon
dd4f0c3a9f fix lint 2025-07-14 20:40:54 +09:00
Jeong YunWon
406be9cd15 Upgrade radium to 1.1.1 2025-07-14 20:40:54 +09:00
Jeong, YunWon
eef8890f32 Integrate PyTupleTyped into PyTuple (#5959)
* Fix derive(Traverse)

* PyPayload::payload_type_of

* PyTupleTyped as alias of PyTuple

* Fully integrate PyTupleTyped into PyTuple
2025-07-14 18:43:18 +09:00
Jeong YunWon
6342ad4fa7 Fully integrate PyTupleTyped into PyTuple 2025-07-14 14:27:48 +09:00
Jeong YunWon
14ce76e6c8 PyTupleTyped as alias of PyTuple 2025-07-14 14:27:48 +09:00
Jeong YunWon
09489712e6 PyPayload::payload_type_of 2025-07-14 14:27:48 +09:00
Jeong YunWon
635b4afff1 Fix derive(Traverse) 2025-07-14 14:27:48 +09:00
Shahar Naveh
36f4d30e01 Update test_tuple.py from 3.13.5 (#5966) 2025-07-14 14:26:08 +09:00
Shahar Naveh
4fe4ff4f99 Update test_{list,listcomps}.py from 3.13.5 (#5965) 2025-07-14 14:24:00 +09:00
Jiseok CHOI
5ab64b7002 fix(sqlite): align adaptation protocol with CPython (#5964) 2025-07-14 14:22:52 +09:00
Shahar Naveh
97e85b220e Update test_{dict,weakref}.py from 3.13.5 (#5963)
* Update test_dict.py from 3.13.5

* Update `test_weakref.py` from 3.13.5
2025-07-14 14:21:59 +09:00
Jiseok CHOI
d42e8f0042 fix(sqlite): produce correct error for surrogate characters (#5962) 2025-07-14 14:21:36 +09:00
Shahar Naveh
ed8d7157d9 Update test_{complex,float}.py from 3.13.5 (#5961) 2025-07-14 14:20:28 +09:00
Ashwin Naren
04d8d69a8c upgrade parts of test.support (#5686) 2025-07-14 14:19:33 +09:00
Jeong, YunWon
8ab7aa2c6b type.__dict__ (#5957) 2025-07-13 13:12:03 +09:00
Jeong, YunWon
16aaad7aeb PyTraceback Constructor (#5958) 2025-07-13 10:20:07 +09:00
Jeong, YunWon
52d46326de make_closure (#5955) 2025-07-13 01:00:15 +09:00
Jeong, YunWon
e21ec550d4 Fix set___name__ and set___qualname__ deadlock (#5956) 2025-07-13 00:22:41 +09:00
Shahar Naveh
ac20b00e26 str.replace support count as keyword arg (#5954) 2025-07-12 22:43:47 +09:00
Shahar Naveh
e75aebb967 Update str related tests from 3.13.5 (#5953)
* Update str related tests from 3.13.5

* Apply RustPython patches

* Mark new failing tests
2025-07-12 20:44:34 +09:00
Jeong, YunWon
fef660e6b3 more PEP695 (#5917)
* compile_class_body

* type.__orig_bases__ regression of test_all_exported_names

* rework type_params scope

* refactor compile_class_def
2025-07-12 20:42:57 +09:00
Jeong, YunWon
3ef0cfc50c compiler enter_scope (#5950)
* enter_scope

* drop_class_free

* push_output based on enter_scope
2025-07-12 19:28:22 +09:00
Shahar Naveh
1303ace453 Update textwrap from 3.13.5 (#5952) 2025-07-12 19:18:31 +09:00
Shahar Naveh
3f9a5fddbb Don't skip non hanging test (#5951) 2025-07-12 19:18:08 +09:00
Shahar Naveh
f19478edec Update operator from 3.13.5 (#5935) 2025-07-12 01:10:30 +09:00
Jeong, YunWon
c4234c1692 SymbolTable::varnames, fblock (#5948)
* SymbolTable::varnames

* varname_cache copies it

* fasthidden & static attributes

* metadata

* fblock
2025-07-11 22:43:08 +09:00
Shahar Naveh
c3967bf849 Set timeout for CI (#5947) 2025-07-11 19:18:23 +09:00
Jeong, YunWon
59c7fcbb98 compiler set_qualname (#5930)
* set_qualname

* remove qualified_path
2025-07-11 18:21:51 +09:00
Shahar Naveh
50c241fd71 Fix yaml error in take issue command (#5946) 2025-07-11 17:44:46 +09:00
Jeong, YunWon
392f9c26c5 Instruction::Resume (#5944)
* ImportStar

* Instruction::Resume
2025-07-11 17:25:57 +09:00
Jeong, YunWon
0ae6b4575c typing TypeAlias (#5945) 2025-07-11 16:16:01 +09:00
Jeong, YunWon
8b6c78c884 SymbolTableType::Lambda (#5942) 2025-07-11 13:35:52 +09:00
Jeong, YunWon
9b133b8560 CodeInfo::private (#5943) 2025-07-11 13:11:15 +09:00
Jeong, YunWon
2f94a63958 Add SymbolUsage::TypeParams (#5941) 2025-07-11 11:24:20 +09:00
Shahar Naveh
2c30e01ae2 Update test_deque from 3.13.5 (#5939) 2025-07-11 08:36:34 +09:00
Shahar Naveh
01f15065fa Use raise_if_stop! macro where possible (#5938) 2025-07-11 08:36:08 +09:00
Shahar Naveh
38837e587b Make take issue comment to use curl (#5937)
* Revert "Add missing `@` for the "take" comment command (#5933)"

This reverts commit ef385a9efa.

* Fix `take`
2025-07-11 08:35:21 +09:00
Shahar Naveh
089c39f741 Update test_string_literals.py from 3.13.5 (#5934) 2025-07-10 22:47:55 +09:00
Jiseok CHOI
4c7523080a fix(format): isolate special grouping rule to sign-aware zero-padding (#5924) 2025-07-10 22:47:24 +09:00
Shahar Naveh
ef385a9efa Add missing @ for the "take" comment command (#5933) 2025-07-10 22:46:29 +09:00
Shahar Naveh
b2013cddc9 Add "take" comment command (#5932) 2025-07-10 19:55:38 +09:00
Jiseok CHOI
8c4c63673e fix(itertools): add re-entrancy guard to tee object (#5931)
* fix(itertools): add re-entrancy guard to tee object

* apply feedback PyRwLock -> PyMutex & remove AtomicCell<bool> lock field
2025-07-10 18:11:24 +09:00
Jeong, YunWon
18d7c1baf1 codeobj.qualname (#5929) 2025-07-10 10:27:03 +09:00
yt2b
f608df4a23 Formatting with width and separator doesn't work correctly (#5927)
* Fix add_magnitude_separators

* Add extra tests
2025-07-10 09:10:52 +09:00
Jeong, YunWon
54ff198409 Upgrade Lib/types.py from Python 3.13.5 (#5928) 2025-07-10 08:57:08 +09:00
Shahar Naveh
cbd9b30bd1 Update compileall from 3.13.5 (#5914) 2025-07-10 08:36:37 +09:00
Shahar Naveh
5985ec8be0 sys.platform android & ios (#5921)
* Make sys.platform to return 'android'

* Added missing 'ios' platform
2025-07-10 00:47:24 +09:00
Jiseok CHOI
3a6a766a03 fix(sqlite): implement PARSE_COLNAMES column name parsing (#5923) 2025-07-10 00:18:40 +09:00
Jiseok CHOI
e6fdef43dc fix(sqlite): autocommit mode transaction handling to match CPython (#5918) 2025-07-09 20:13:26 +09:00
Shahar Naveh
f0cf9e6492 Update cmd from 3.13.5 (#5920)
* Update cmd from 3.13.5

* Add `test.support.pty_helepr` from 3.13.5
2025-07-09 19:03:53 +09:00
Jiseok CHOI
2f9459cf02 Enable match statements sqlite cli (#5919) 2025-07-09 19:03:17 +09:00
Jiseok CHOI
341341520e Fix SQLite large integer overflow error handling (#5916) 2025-07-09 17:14:45 +09:00
Shahar Naveh
c195473a29 Update copy from 3.13.5 (#5913) 2025-07-08 23:49:57 +09:00
Shahar Naveh
d58c500129 Update gzip from 3.13.5 (#5912) 2025-07-08 20:13:52 +09:00
Shahar Naveh
5c8b027af4 Update test_datetime from 3.13.5 (#5911) 2025-07-08 19:46:26 +09:00
Jeong, YunWon
ec577e556d Merge pull request #5909 from youknowone/typing-parameters
typing __parameters__ __type_params__
2025-07-08 00:08:45 +09:00
Jeong YunWon
bd54e537fd Fix __parameters__, __type_params__ 2025-07-07 23:23:24 +09:00
Jeong YunWon
481e03abe4 Replace old anndata to new from CPython 3.13.5 2025-07-07 21:18:48 +09:00
Jeong YunWon
999976a76c fix __parametesr__ 2025-07-07 19:05:04 +09:00
Jeong YunWon
7ebe0182e4 More eval typecheck 2025-07-07 19:02:37 +09:00
Jeong YunWon
a576569a02 update instructions 2025-07-07 19:02:37 +09:00
Jiseok CHOI
240f87a911 Handle negative time.sleep values (#5906)
* fix(time): Handle negative sleep values
2025-07-07 13:49:12 +09:00
yt2b
23a5c82a3a Add separator validation (#5904)
* Add separator validation

* Remove @unittest.expectedFailure
2025-07-06 23:08:07 +09:00
Shahar Naveh
9336507be6 Fix clippy::inconsistent_struct_constructor (#5905) 2025-07-06 09:24:05 +09:00
Shahar Naveh
3c7ec04285 Update tomllib from 3.13.5 (#5902) 2025-07-04 23:47:34 +09:00
Shahar Naveh
f57f6d7443 Make gemini ignore Lib/** (#5903) 2025-07-04 23:47:05 +09:00
Shahar Naveh
94a55eb479 Update uuid from 3.13.5 (#5901)
* Update uuid from 3.13.5

* Mark failing test
2025-07-04 22:37:12 +09:00
yt2b
0a59c1cad3 Implement PyComplex's __format__ function (#5900)
* Add num-complex in rustpython-common

* Implement PyComplex's __format__ function

* Remove @unittest.expectedFailure

* Fix PyComplex's __format__ function

* Remove @unittest.expectedFailure

* Add extra tests

* Rename to ZeroPadding and AlignmentFlag
2025-07-04 22:35:28 +09:00
Shahar Naveh
694fe50241 Use const fn where possible (#5894) 2025-07-04 22:26:20 +09:00
coderabbitai[bot]
5b20bb851e Remove conflicting AsRef<Self> implementation for PyObject in core.rs (#5899)
* 📝 CodeRabbit Chat: Remove conflicting AsRef<Self> implementation for PyObject in core.rs

* Update vm/src/object/core.rs

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-07-04 11:40:30 +09:00
Shahar Naveh
4bd328906e Update resource from 3.13.5 (#5893) 2025-07-04 10:09:06 +09:00
Shahar Naveh
69545c0798 Use Self where possible (#5892) 2025-07-04 10:08:43 +09:00
Shahar Naveh
05013e3d0b macro for pyast code depulication (#5887) 2025-07-04 08:45:44 +09:00
Jeong, YunWon
8a2a6af91b __type_params__ in __build_class__ (#5883)
* remove future __classs_getitem__

* __type_params__ in __build_class__
2025-07-03 14:08:42 +09:00
Jeong, YunWon
c529c247bb PyRef::into_ref() (#3744) 2025-07-03 14:07:30 +09:00
Jeong, YunWon
49422c5819 relocate Generic under typevar.rs (#5889) 2025-07-03 12:05:03 +09:00
Jeong, YunWon
d40cbbb451 Fix cspell warning (#5890)
* Fix cspell warning

* cspell: -> spell-checker:
2025-07-03 12:04:43 +09:00
Jeong, YunWon
fffa735868 __class_getitem__ (#5888) 2025-07-03 11:01:53 +09:00
Shahar Naveh
b6acfe0f9d Add raise_if_stop! macro for protocol/iter.rs (#5885) 2025-07-03 08:37:54 +09:00
Shahar Naveh
43be4e48ad nitpicks (#5886)
* Use `Self` instead of struct name

* General fixes

* General

* General fixes

* More nitpicks

* Added newlines

* More nitpicks

* Use Self where possible

* Use Self where possible

* Use Self

* Use Self more

* Use Self
2025-07-02 21:27:47 +09:00
Shahar Naveh
18fdf85510 Fix itertools.pairwise (#5884)
* Fix pairwise hangs

* Don't skip failing tests;)

* Drop lock of read, not write
2025-07-02 21:10:24 +09:00
Jeong YunWon
fa7af0e5ea type.__type_params__ 2025-07-01 19:05:29 +09:00
Jeong YunWon
e25c2856ad cspell ignore target/** 2025-07-01 19:05:29 +09:00
Jeong, YunWon
3d951a883a Compile starred annotations (#5881)
* Fix starred annotation

* uncomment starred annotation
2025-07-01 17:20:42 +09:00
Jeong, YunWon
4ebd485694 typing _Py_subs_paramters (#5880) 2025-07-01 16:09:59 +09:00
Shahar Naveh
9f3c34a705 Update ipaddress (#5878) 2025-07-01 10:59:41 +09:00
Jeong, YunWon
119e209ffd fix coderabbit (#5877) 2025-07-01 04:40:58 +09:00
Jeong, YunWon
334a5a7c3c Iterable for PyGenericAlias (#5876)
* Iterable for PyGenericAlias

* GenericAlias works

* typevar.rs
2025-07-01 04:35:28 +09:00
Jeong, YunWon
e7c18f19ab Merge pull request #5850 from youknowone/typing
Upgrade typing to 3.13.5
2025-07-01 02:31:58 +09:00
Jeong YunWon
3f5566da53 Fix _typing.override 2025-07-01 00:10:16 +09:00
Jeong YunWon
c0b9694cda Patch typing.py to let _py_abc fallback 2025-07-01 00:10:15 +09:00
Jeong YunWon
5a2007fd46 renames 2025-07-01 00:10:15 +09:00
Jeong YunWon
39d091f01c Fix typing 2025-07-01 00:10:15 +09:00
Jeong YunWon
d5946d496d Update typing.py from CPython 3.13.5 2025-07-01 00:10:15 +09:00
Jeong, YunWon
c7641260dd Make coderabbit ignore CPython files (#5875) 2025-07-01 00:02:11 +09:00
Shahar Naveh
01117f4a30 Update argparse to 3.13.5 (#5874)
* Update argparse from 3.13.5

* Mark failing test
2025-06-30 23:56:34 +09:00
Jeong, YunWon
d5d3507921 Add sys._getframemodulename (#5873) 2025-06-30 22:50:27 +09:00
Shahar Naveh
3bde2ddac3 Update base64 3.13.5 (#5872) 2025-06-30 19:09:05 +09:00
Lee Dogeon
5953a938bd chore: test testcases with @unittest.skip decorator (#5871)
Signed-off-by: Lee Dogeon <dev.moreal@gmail.com>
2025-06-30 19:07:58 +09:00
Jeong, YunWon
b59a6666fe __repr__ in typing (#5870)
* ParamSpec.__repr__

* Fix more repr
2025-06-30 10:36:10 +09:00
Jeong, YunWon
66a1138c66 Fix isinstance (#5869)
* lookup_special

* Fix abstract_issubclass

* Fix real_is_instance
2025-06-30 10:35:52 +09:00
Shahar Naveh
b6ff541260 Create ContentItem with a macro (#5859)
* Create ContentItem with a macro

* Set struct docs via metadata
2025-06-30 00:22:52 +09:00
Jeong, YunWon
7c6d0632cc Update isintance (#5868)
* PyUnion::get_args

* issubclass

* isinstance
2025-06-29 15:15:09 +09:00
Jeong, YunWon
4cca8b0d32 Callable __or__ patch (#5753)
* callable __or__ patch

* add test
2025-06-29 14:43:58 +09:00
Ashwin Naren
159769876f add test 2025-06-29 14:42:09 +09:00
Jeong, YunWon
47a7a00fbf Rework issubclass (#5867)
* check_exact

* check_class

* Type compatibility tools

* abstract_issubclass

* recursive_issubclass
2025-06-29 14:28:29 +09:00
Ashwin Naren
0a1c8c3c7e callable __or__ patch 2025-06-29 14:04:00 +09:00
Jeong, YunWon
7a6e5c465f Upgrade abc.py _py_abc.py to 3.13.5 (#5865) 2025-06-29 12:49:14 +09:00
Jeong, YunWon
28dff8af6c Fix TypeParams, TypeAlias compile (#5862) 2025-06-29 11:24:15 +09:00
Jeong, YunWon
0ef22ab6f2 Fix type.__subclasscheck__ (#5864) 2025-06-29 11:21:07 +09:00
Jeong, YunWon
4ebecc0f5e Remove PyTuple::fast_getitem (#5863) 2025-06-29 05:31:21 +09:00
Jeong, YunWon
07a04acfaa Allow heap getset creation (#5854)
* Update _threading_local.py

* allow heap-getset
2025-06-29 03:03:19 +09:00
Ashwin Naren
3a85499b11 Display logo on windows executable (#5790) 2025-06-29 02:50:05 +09:00
Lee Dogeon
8589b55203 Avoid set changed size during iteration (#5860) 2025-06-29 02:14:22 +09:00
Shahar Naveh
8cac4335b4 Constify functions & General nitpicks (#5858)
* General cleanups

* Add some newlines

* Use bitlag match

* More constify

* Don't convert to str twice

* constify more

* Use match directly instead of if & match!

* Constify more

* Constify more

* more consts

* Constify more

* Constify more

* Don't use bitflags_match macro
2025-06-28 23:08:30 +09:00
Wildan M
e41d7f523a Fix stat module compilation for Redox OS 2025-06-28 19:38:26 +09:00
Jeong, YunWon
2bd52121bb Align is_instance (#5855)
* Align is_instance

* Upgrade test_isinstance to 3.13.5

* patch test_isinstance
2025-06-28 11:59:48 +09:00
Lee Dogeon
910077d7ae Implement _stat module (#5847)
* Implement _stat module

* Allow 'FIRMLINK' term
2025-06-28 03:15:46 +09:00
Jeong, YunWon
ac26be7fd7 Fix getset.__objclass__ (#5853) 2025-06-28 00:35:05 +09:00
Jeong, YunWon
b9b1c8580f slot_repr for structseq (#5852) 2025-06-27 23:14:24 +09:00
Jeong, YunWon
43302cec4d Fix boundmethod not to have __dict__ + immutable type (#5851) 2025-06-27 22:50:58 +09:00
Jeong, YunWon
f5ccd4faed Fix __annotation__ (#5849) 2025-06-27 20:36:19 +09:00
Jeong, YunWon
5504f6d9e8 heaptype __qualname__ (#5848) 2025-06-27 19:58:48 +09:00
Jeong, YunWon
f0c7cb26f7 fn class #[inline] (#5846) 2025-06-27 16:02:44 +09:00
Jeong, YunWon
0095941fb7 ruff format (#5845) 2025-06-27 15:06:35 +09:00
Jeong, YunWon
6b6534508f Fix type_params lifetime in symboltable (#5844)
* fix cspell

* Fix type_params lifetime in symboltable
2025-06-27 14:32:54 +09:00
Narawit Rakket
2ea77b4442 Implement true hash for tuple (#3460) 2025-06-27 14:27:27 +09:00
Ashwin Naren
5a81533f61 stdlib compatability checking scripts (#5697)
* stdlib compat checking scripts

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* update output

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-06-27 13:49:53 +09:00
Jeong, YunWon
a18029ee89 [BREAKING CHANGE] Merge pull request #5842 from youknowone/magic-method-names
[BREAKING CHANGE] Writing magic method names as full name
2025-06-27 13:36:55 +09:00
Jeong YunWon
3673372d3d Fix cspell warnings 2025-06-27 12:32:59 +09:00
Jeong YunWon
993ea8923c Rename members 2025-06-27 12:32:59 +09:00
Jeong YunWon
ef3cf70e30 Remove magic from macro 2025-06-27 12:32:59 +09:00
Jeong YunWon
4378a61c8b Fix 1.80 build 2025-06-27 12:32:59 +09:00
Jeong, YunWon
fe2c9bf361 Fix stable clippy (#5843) 2025-06-27 12:12:21 +09:00
Jeong, YunWon
0d492a6b02 Fix genericalias parameters (#5841)
* genericalias

* Fix attr_exceptions list

* impl TypeVarTuple iter

* Update _collections_abc.py to Python 3.13

* genericalias.__unpack__
2025-06-27 10:32:26 +09:00
Jeong, YunWon
3031d5ba45 more typing (#5840)
* rename typing

* No test code modification rules

* remove orphan TODOs

* mro_entires

* typing module name

* typing_subst

* typing.override

* Comparable for typing

* remove to_owned() from typing
2025-06-26 21:51:30 +09:00
Jeong, YunWon
6905d4375b typing ParamSpec (#5837)
* Add cspell

* TypeVar

* ParamSpec

* refactor

* TypeVarTuple repr

* Remove expectedFailure
2025-06-26 20:31:17 +09:00
Shahar Naveh
1ae07813ee Remove redundent to_owned() and to_string() calls (#5836)
* Remove redundent String conversion for errors

* cargo fmt
2025-06-25 23:42:26 +09:00
Jeong, YunWon
f9d9307503 typing.TypeVar (#5834)
* copilot instruction

* typing.TypeVar

* typing.NoDefault
2025-06-25 08:37:40 +09:00
Shahar Naveh
ab09de8542 Remove unnecessary string conversions in error message construction (#5826)
* Make `new_X_error` recv `impl Into<String>`

* Maks the rest of the methods to be generic

* Remove `.to_owned()` from more files
2025-06-25 01:43:41 +09:00
Jeong, YunWon
6a992d4fa2 Add hashlib hasher repr (#5833) 2025-06-24 20:09:24 +09:00
Jeong, YunWon
3734f32e42 Exception.set_traceback_typed (#5832) 2025-06-24 18:56:10 +09:00
Jeong, YunWon
a8c9703cbc classmethod copy attrs (#5831) 2025-06-24 17:23:37 +09:00
Jeong, YunWon
9c2a4695c1 Fix excepthook (#5830) 2025-06-24 16:58:27 +09:00
Jeong, YunWon
638d2183dc Fix builtins.dir (#5829) 2025-06-24 13:31:50 +09:00
Jeong, YunWon
86d8d23ad8 implement more property features (#5828)
* property getter_doc

* Fix property.isabstractmethod

* Fix property error messages

* refactor getter/setter/deleter

* fix property
2025-06-24 13:31:31 +09:00
Jeong, YunWon
3566dcab28 Pyfunction builtins and constructor (#5823)
* func builtins

* PyFunction constructor
2025-06-24 10:23:14 +09:00
Jeong, YunWon
0624ca622b functools.partial (#5825)
* functools.partial

* apply review
2025-06-23 23:53:57 +09:00
Ashwin Naren
70bcd78e85 Bump libffi (#5779)
Also remove system feature from jit libffi, as that forces libffi to be installed on the system
2025-06-23 23:28:33 +09:00
Jeong, YunWon
52301ddbe5 Fix PyFunction doc behavior (#5827) 2025-06-23 22:37:51 +09:00
Jeong, YunWon
9952c97edf BaseException.__setstate__ (#5821)
* docs

* BaseException.__setstate__
2025-06-23 13:49:59 +09:00
Jeong, YunWon
33af632914 fix maketrans (#5824) 2025-06-23 11:43:18 +09:00
Jeong YunWon
a288b77c4f BaseException.__setstate__ 2025-06-23 09:41:21 +09:00
Jeong, YunWon
0728da51fc binascii.hexlify (#5820) 2025-06-23 08:59:36 +09:00
Jeong, YunWon
b0b39194dd Fix cell_contents (#5822) 2025-06-23 08:59:07 +09:00
Jeong, YunWon
b1ecdf38b8 Fix bz2 pickle (#5819) 2025-06-23 08:55:59 +09:00
Lee Dogeon
dfc8fe018f Unmark fixed tests (#5818) 2025-06-23 08:55:28 +09:00
Jeong YunWon
0a6e1e80d7 docs 2025-06-23 01:05:54 +09:00
Jeong, YunWon
5d68313f91 sys.setswitchinterval (#5817) 2025-06-22 22:36:13 +09:00
Shahar Naveh
e27263aebd Convert new_X_error to use a macro (#5814) 2025-06-22 21:33:14 +09:00
Jeong YunWon
4cdb8d18b7 unicodedata.is_mirrored 2025-06-22 21:32:12 +09:00
Jeong YunWon
c824016301 Fix UnpackIterator constructor 2025-06-22 18:11:30 +09:00
Jeong YunWon
44d312419a Fix bytes constructor 2025-06-22 17:40:04 +09:00
Jeong, YunWon
3a54105e2c Fix struct tests (#5813) 2025-06-22 09:58:43 +09:00
Jeong, YunWon
7473a43fab Fix posix tests (#5811) 2025-06-22 09:58:29 +09:00
ShaharNaveh
f31ebf83ac Use raw string where appropriate. add newlines 2025-06-22 09:33:10 +09:00
ShaharNaveh
e6f5b6ad1a constify a bunch of methods 2025-06-22 09:33:10 +09:00
ShaharNaveh
55740b2277 Use any instead of loop 2025-06-22 09:33:10 +09:00
ShaharNaveh
e03f762b20 Make new method const 2025-06-22 09:33:10 +09:00
Jeong, YunWon
efc6b5dbaf Merge pull request #5809 from youknowone/fix-dict-unpack
Fix dict unpack
2025-06-22 09:08:06 +09:00
Jeong YunWon
d973e6da10 Apply copilot review 2025-06-22 00:01:22 +09:00
Jeong YunWon
3f1d39e5db Fix DictUpdate validation 2025-06-22 00:00:07 +09:00
Jeong YunWon
9467632e1b Fix dict unpacking order preservation 2025-06-21 23:51:37 +09:00
Jeong YunWon
829388b7b5 Edit only Rust files 2025-06-21 22:00:42 +09:00
Jeong, YunWon
f0e742714a Merge pull request #5808 from ShaharNaveh/cln-general 2025-06-21 13:25:33 +09:00
ShaharNaveh
fc68da7f6c newlines between functions 2025-06-21 00:50:40 +03:00
ShaharNaveh
eea33df6b1 Replace 255 with u8::MAX 2025-06-21 00:50:09 +03:00
ShaharNaveh
9574e14c0f Use .take instead of slicing a vec 2025-06-20 16:47:28 +03:00
ShaharNaveh
f2a6c09007 CLN: Loop with idx check location_tup len fields 2025-06-20 16:26:11 +03:00
Jeong YunWon
e4c8f2bb43 Fix ImportError 2025-06-20 16:12:30 +09:00
Jeong YunWon
d78ed67c26 fix instruction 2025-06-20 16:12:30 +09:00
Jeong YunWon
17bc8455aa Fix UnicodeDecodeError 2025-06-20 16:12:30 +09:00
Jeong YunWon
44d66dcdac Fix SyntaxError 2025-06-20 16:12:30 +09:00
Jeong YunWon
a186a5a9f5 Impl PyAttributeError args 2025-06-18 15:53:17 +09:00
Jeong YunWon
75531402e5 disable redox test to enable CI 2025-06-18 15:53:05 +09:00
largemouth
0dac02f443 chore: fix some typos in comment
Signed-off-by: largemouth <largemouth@aliyun.com>
2025-06-17 21:59:25 +09:00
Ashwin Naren
c968fe0fd9 remove macos skips 2025-06-15 17:36:13 +09:00
Ashwin Naren
125f14190a Remove unnecessary uv runin README (#5792)
* Update README.md

Remove unnecessary `uv run`

* uv comment

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2025-06-15 16:10:27 +09:00
Jeong YunWon
a6dd2d805b Skip test_local_unknown_cert to avoid CI failure 2025-06-15 16:04:37 +09:00
Jeong YunWon
6723bf30a7 Fix deque module name for test_repr 2025-06-15 16:04:37 +09:00
Jeong YunWon
2c61a12bed Apply coderabbit reviews 2025-06-15 16:03:46 +09:00
Jeong YunWon
f560b4cbfb Fix nightly clippy warnings 2025-06-15 16:03:46 +09:00
dependabot[bot]
4e094eaa55 Bump webpack-dev-server from 5.2.0 to 5.2.1 in /wasm/demo (#5801)
Bumps [webpack-dev-server](https://github.com/webpack/webpack-dev-server) from 5.2.0 to 5.2.1.
- [Release notes](https://github.com/webpack/webpack-dev-server/releases)
- [Changelog](https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-dev-server/compare/v5.2.0...v5.2.1)

---
updated-dependencies:
- dependency-name: webpack-dev-server
  dependency-version: 5.2.1
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-06 23:17:32 +09:00
Jeong, YunWon
2e368baf2a Fix Nightly clippy (#5798) 2025-06-06 22:00:07 +09:00
Aneesh Durg
323ea3b96b Support incomplete parsing (#5764)
* continue accepting REPL input for multiline strings

* Match cpython behavior for all multi-line statements (execute when complete)

* Emit _IncompleteInputError when compiling with incomplete flag

* Refine when _IncompleteInputError is emitted

* Support multiline strings emitting _IncompleteInputError

* lint

* Undo accidental change to PyTabError

* match -> if let

* Fix test_baseexception and test_codeop

* fix spelling

* fix exception name

* Skip pickle test of _IncompleteInputError

* Use py3.15's codeop implementation

* Update Lib/test/test_baseexception.py

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-06-05 14:41:56 +09:00
Noa
e27d03179f Remove getrandom 0.2 from dependencies 2025-05-21 12:12:14 +09:00
Jeong YunWon
81a9002ef2 Rename Dockerfile 2025-05-20 11:10:13 +09:00
Noa
18521290bf Update dependencies 2025-05-19 14:41:24 +09:00
Noa
5e682e3f17 Merge pull request #5788 from coolreader18/fix-prec
Fix panic with high precision
2025-05-16 20:28:25 -05:00
Noa
163296d306 Fix test_memoryio 2025-05-16 15:20:10 -05:00
Noa
1ae98ee177 Fix panic with high precision 2025-05-16 14:17:25 -05:00
Noa
2c02e2776b Fix warnings for rust 1.87 2025-05-16 18:52:14 +09:00
Ashwin Naren
72dc4954ad dev container update 2025-05-16 18:25:08 +09:00
Rex Ledesma
b696e56c5f chore: rely on the default inclusions for ruff 2025-05-15 19:15:51 +09:00
dependabot[bot]
d11d5c65e6 Bump streetsidesoftware/cspell-action in the github-actions group
Bumps the github-actions group with 1 update: [streetsidesoftware/cspell-action](https://github.com/streetsidesoftware/cspell-action).


Updates `streetsidesoftware/cspell-action` from 6 to 7
- [Release notes](https://github.com/streetsidesoftware/cspell-action/releases)
- [Changelog](https://github.com/streetsidesoftware/cspell-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/streetsidesoftware/cspell-action/compare/v6...v7)

---
updated-dependencies:
- dependency-name: streetsidesoftware/cspell-action
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-13 04:08:12 +09:00
Ashwin Naren
5c0f70c361 add instructions 2025-05-12 14:24:10 +09:00
Rex Ledesma
4e2e0b41c6 chore: add ruff format --check (#5774)
* chore: add `ruff format --check`

* fix tests
2025-05-12 14:20:01 +09:00
Ashwin Naren
df380bca96 lzma FORMAT_ALONE implementation (#5777)
* implement init_alone

* error if format is raw and there is a memlimit
2025-05-09 13:26:28 +09:00
Ashwin Naren
9bd7f1810b Update README.md
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-05-08 14:59:46 +09:00
Ashwin Naren
31e6cca916 Update README.md 2025-05-08 14:59:46 +09:00
Rex Ledesma
b8095b84ff chore: allow uv run python -I ./whats_left.py 2025-05-08 14:51:52 +09:00
Rex Ledesma
908386091b feat: implement zlib.__version__ 2025-05-08 14:48:11 +09:00
Rex Ledesma
aee4c7ac69 chore: migrate settings to ruff.toml (#5773) 2025-05-08 14:46:57 +09:00
Rex Ledesma
dc75d203ff chore: upgrade to ruff==0.11.8 2025-05-08 14:11:43 +09:00
Jeong, YunWon
ce5524d72a Merge pull request #5769 from youknowone/radium-patch 2025-05-08 13:42:38 +09:00
Jeong YunWon
06c4b151d6 Add radium patch to fix CI 2025-05-07 18:21:36 +09:00
Jeong, YunWon
79646fd222 Merge pull request #5717 from arihant2math/lzma
lzma implementation
2025-05-07 18:00:06 +09:00
Jeong YunWon
d9c18c5593 flatten compression modules 2025-05-07 15:42:31 +09:00
Jeong YunWon
acae154f1b more diff-friendly disabling xz 2025-05-07 15:01:23 +09:00
Ashwin Naren
a5016446f4 _lzma implementation and test marking
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-05-07 15:01:23 +09:00
Ashwin Naren
2042d877f9 add lzma.py and test_lzma.py at 3.13.2
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-05-07 15:01:23 +09:00
Ashwin Naren
2a1ea45659 add _lzma module with new dependency
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-05-07 15:01:23 +09:00
Jeong YunWon
48b08a2b7f Revert "Split out common compression routines into separate file (#5728)"
This reverts commit 9c88475b31.
2025-05-07 15:01:09 +09:00
Noa
9c88475b31 Split out common compression routines into separate file (#5728) 2025-05-06 15:26:54 +09:00
Undersk0re
6aa80aa596 Update .gitignore, folder fix (#5762) 2025-05-06 14:07:12 +09:00
Karel Král
85f7ba51f4 Enable test_mtestfile 2025-05-02 03:39:46 +09:00
Jeong, YunWon
94b38a51c4 Fix build (#5765) 2025-05-01 15:38:50 +09:00
Hanif Ariffin
253cc4e846 Fix usize not using the same hash as PyInt when used as key into a di… (#5756)
* Fix usize not using the same hash as PyInt when used as key into a dictionary

* Fix test that unexpectedly succeed!

* Update extra_tests/snippets/builtin_object.py
2025-05-01 14:55:19 +09:00
Noa
431b900084 Merge pull request #5716 from arihant2math/codegen-panic-reduction
Cleaner panic output for codegen errors
2025-04-30 09:25:57 -05:00
Karel Král
301c32dba0 Increase numerical precision of log1p
Use Rust native ln_1p to increase numerical precision matching what is
expected by `test_mtestfile`.
2025-04-30 16:35:04 +09:00
Jeong YunWon
cd1c9be0e1 Fix Cargo.lock 2025-04-30 15:04:26 +09:00
Jeong, YunWon
6461a91933 More stdlib updates (#5737)
* update getopt to 3.13.3

* update getpass to 3.13.3

* update timeit to 3.13.3

* update reprlib to 3.13.3

* update fileinput to 3.13.3
2025-04-30 14:59:01 +09:00
Aneesh Durg
e49e743669 Support multiline function/class definitions in REPL and InteractiveConsole (#5743)
* Support multiline function/class definitions in REPL and InteractiveConsole
2025-04-30 14:53:37 +09:00
Ashwin Naren
e8df06582e bump dependencies 2025-04-30 14:49:21 +09:00
Jeong YunWon
02f120aaf4 copilot-instructions 2025-04-30 14:43:17 +09:00
Ashwin Naren
b84d6a36a6 update fileinput to 3.13.3 2025-04-30 14:33:52 +09:00
Ashwin Naren
d73f03b9ba update reprlib to 3.13.3 2025-04-30 14:33:52 +09:00
Ashwin Naren
1a4b035dac update timeit to 3.13.3 2025-04-30 14:33:52 +09:00
Ashwin Naren
dd40bf7566 update getpass to 3.13.3 2025-04-30 14:33:52 +09:00
Ashwin Naren
5e770e9c9e update getopt to 3.13.3 2025-04-30 14:33:52 +09:00
Jeong YunWon
d1b7dc551c skip flaky test_weakref 2025-04-30 14:32:43 +09:00
Jeong YunWon
b0991e28a2 Replace puruspe to pymath
Might be lower quality, but better compatibility
2025-04-29 17:39:50 +09:00
Noa
180746467e Merge pull request #5744 from coolreader18/upd-malachite
Update to malachite 0.6
2025-04-27 23:24:26 -05:00
Ashwin Naren
f55bf8f83b fix openssl error reasons (#5739) 2025-04-28 12:30:14 +09:00
Jeong, YunWon
ff10a64727 Fix test_poll::test_poll3 (#5718)
* test_poll3

* Refactor EventMask
2025-04-28 12:29:21 +09:00
Ashwin Naren
5561b6ead4 Re-add ssl feature to cron-ci.yaml for whats-left (#5750) 2025-04-28 12:20:42 +09:00
Ashwin Naren
392d1c04f6 More overlapped implementation (#5748) 2025-04-27 19:48:06 +09:00
Ashwin Naren
d46bcd9291 typing upgrade to 3.13.2 (#5590) 2025-04-27 15:26:37 +09:00
Ashwin Naren
ca496fb3b1 Collect whats_left data with sqlite feature
This fixes the output on the website, and correctly shows `_sqlite3` as implemented
2025-04-27 15:24:18 +09:00
Noa
7aad6e03e3 Update to malachite 0.6 2025-04-25 00:22:26 -05:00
Ashwin Naren
c97f4d1daf Failure marker (#5695)
* initial auto-upgrader

* platform support

* use ast walking

* detect testname automatically

* handle classes properly

* add instructions to fix_test.py
2025-04-24 13:28:38 +09:00
Jeong, YunWon
7d2a7a0e35 Merge pull request #5731 from arihant2math/pprint-313 2025-04-22 14:18:35 +09:00
Ashwin Naren
92e72aabdc update graphlib to 3.13.3 2025-04-21 21:21:10 -07:00
Ashwin Naren
8603cd9387 update heapq to 3.13.3 2025-04-21 21:12:12 -07:00
Ashwin Naren
1c64bde0ee update sched to 3.13.3 2025-04-21 21:11:42 -07:00
Ashwin Naren
70f3aec552 update linecache to 3.13.3 2025-04-21 21:11:42 -07:00
Ashwin Naren
6567d1d6ec update queue to 3.13.3 2025-04-21 20:48:13 -07:00
Ashwin Naren
a5214a0de7 update colorsys to 3.13.3 2025-04-21 20:45:06 -07:00
Ashwin Naren
a85a84330f update pprint to 3.13.3 2025-04-21 20:43:43 -07:00
Noa
494918d9fe Remove cfg_attr features for redox 2025-04-22 12:00:57 +09:00
Noa
3bfafb0ecb Merge pull request #5720 from youknowone/wasip2-build
basic wasip2 support
2025-04-21 13:39:41 -05:00
Reagan Bohan
ecbc6f7044 Fix mmap aborting with invalid fd in debug mode 2025-04-21 20:40:44 +09:00
Ashwin Naren
5ce860443c implement nt.getlogin
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-21 16:56:04 +09:00
Ashwin Naren
320d74527f update webbrowser and test_webbrowser to 3.13.3
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-21 16:54:00 +09:00
Ashwin Naren
82a62382d0 add wave at 3.13.2
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-21 08:48:38 +09:00
Noa
fbaeecc6a1 Merge pull request #5709 from coolreader18/bz2
Switch to `libbz2-rs-sys` and finish bz2 impl
2025-04-20 17:53:07 -05:00
Jeong YunWon
e434ff5f6e basic wasip2 support 2025-04-20 19:47:35 +09:00
Noa
f0d46bfeaa Finish _bz2 implementation 2025-04-19 23:13:37 -05:00
Noa
e377e43f05 Remove bz2 feature 2025-04-19 23:13:37 -05:00
Noa
e640487572 Use libbz2-rs-sys for bzip2 implementation
Co-authored-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-19 23:13:27 -05:00
Ashwin Naren
397a1968c8 fix clippy
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-19 11:15:01 -07:00
Ashwin Naren
783e45f8ac Apply review
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-04-19 09:48:20 -07:00
Ashwin Naren
fc331a154f fix errors and formatting
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-18 22:41:48 -07:00
Ashwin Naren
12ceb9695c cleaner panic output
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-18 22:31:29 -07:00
Hanif Ariffin
974c54ede2 Updated test_baseexception from 3.13.2 (#5638)
Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
2025-04-19 11:08:50 +09:00
Noa
a4d1bba74e Update tarfile to 3.12.3 (#5714)
* Update tarfile to 3.12.3

* Unmark tests
2025-04-19 11:03:15 +09:00
Noa
960954eba5 Fix CI 2025-04-18 14:15:10 -05:00
Daniel Stuart
dabd93c255 Make stdio a feature (#5420) 2025-04-18 14:10:25 -05:00
Noa
0d4faa00a7 Merge pull request #5700 from arihant2math/match-cleanup
Cleanup match statement codegen
2025-04-18 13:56:57 -05:00
Ashwin Naren
fd665f6bb2 fix _suggestions module init
renames the module init from suggestions to _suggestions

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-18 12:19:40 +09:00
Noa
ecdb7d3229 Merge pull request #5706 from coolreader18/constant_time_eq
Use the `constant_time_eq` crate instead of our bespoke implementation
2025-04-17 11:55:34 -05:00
Noa
10fd02e42e Use constant_time_eq instead of our bespoke implementation 2025-04-17 11:05:57 -05:00
Noa
c53908fe9e Merge pull request #5657 from arihant2math/fix-readme
Remove broken badge from readme
2025-04-17 10:26:14 -05:00
dependabot[bot]
b72f3a4928 Bump http-proxy-middleware from 2.0.7 to 2.0.9 in /wasm/demo (#5708)
Bumps [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) from 2.0.7 to 2.0.9.
- [Release notes](https://github.com/chimurai/http-proxy-middleware/releases)
- [Changelog](https://github.com/chimurai/http-proxy-middleware/blob/v2.0.9/CHANGELOG.md)
- [Commits](https://github.com/chimurai/http-proxy-middleware/compare/v2.0.7...v2.0.9)

---
updated-dependencies:
- dependency-name: http-proxy-middleware
  dependency-version: 2.0.9
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-17 20:23:32 +09:00
Ashwin Naren
55998c9e3b Merge pull request #5701 from arihant2math/more-tests
Add more independent tests at 3.13.3
2025-04-17 20:01:43 +09:00
Jeong, YunWon
e73b4e9734 Merge pull request #5705 from coolreader18/deps 2025-04-17 20:00:56 +09:00
Noa
2e14b7b5e8 Upgrade system-configuration and libz-rs-sys 2025-04-16 17:14:18 -05:00
Noa
7eb361c92f Upgrade which and rustix 2025-04-16 17:14:16 -05:00
Noa
2ca52bf3ba Merge pull request #5702 from arihant2math/struct-313
Update struct to 3.13.3 and update parts of test.support
2025-04-16 17:09:41 -05:00
Noa
2e260761ae Upgrade criterion 2025-04-16 17:09:07 -05:00
Noa
99a384a3c7 Upgrade radium 2025-04-16 17:08:52 -05:00
Ashwin Naren
662d3a1b4a fix test_zlib 2025-04-15 16:16:06 -07:00
Ashwin Naren
3a1a5d3cd0 fix test_unicode 2025-04-15 16:12:37 -07:00
Ashwin Naren
a0226df166 fix test_csv 2025-04-15 16:11:32 -07:00
Ashwin Naren
4336b9e787 fix test_decimal 2025-04-15 15:55:09 -07:00
Ashwin Naren
844090b0b8 update test_struct to 3.13.3 2025-04-15 14:48:20 -07:00
Ashwin Naren
213506d9ae update part of test.support.__init__ to 3.13.2 2025-04-15 14:48:09 -07:00
Ashwin Naren
4d53f5925c remove match test 2025-04-15 11:56:29 -07:00
Ashwin Naren
21272025c2 improve error handling 2025-04-15 11:54:46 -07:00
Ashwin Naren
d44324d4d0 clippy 2025-04-15 11:44:04 -07:00
Ashwin Naren
628287c14e update snapshot 2025-04-15 11:42:13 -07:00
Ashwin Naren
e949c9aa3f rename 2025-04-15 11:41:27 -07:00
Ashwin Naren
09c199a1ba match cleanup 2025-04-15 10:03:29 -07:00
Ashwin Naren
d47944b2fd error handling 2025-04-15 10:02:32 -07:00
Ashwin Naren
456e555e8b better error 2025-04-15 09:25:06 -07:00
Ashwin Naren
c7042fd847 remove unneeded validation 2025-04-15 08:39:58 -07:00
Ashwin Naren
a917da3b1a update test_float to 3.13.3 2025-04-15 16:24:10 +09:00
Ashwin Naren
fb0c4b6b3c add test_winapi 2025-04-15 16:24:10 +09:00
Ashwin Naren
49b348cc7e Remove Instruction::IsOperation 2025-04-14 22:33:55 -07:00
Ashwin Naren
a7ad848270 Rust dependency updates (#5651) 2025-04-15 08:50:29 +09:00
Ashwin Naren
c2c20758c9 Remove imp (#5693) 2025-04-14 16:56:22 +09:00
Ashwin Naren
c7df344805 update calendar and test_calendar to 3.13.2 2025-04-14 16:55:00 +09:00
Ashwin Naren
4094c5bfc9 minor mark 2025-04-14 16:54:06 +09:00
Jeong, YunWon
4ae2936a45 fix more cspell warnings (#5689) 2025-04-11 12:08:07 +09:00
Ashwin Naren
fd2764c7c7 Remove asynchat and asyncore (#5688)
* try to remove asynchat and asyncore

* remove associated tests

* temp patch of test_ftplib
2025-04-11 11:11:12 +09:00
Ashwin Naren
b81ae9b954 More cspell fixes (#5670) 2025-04-11 09:37:20 +09:00
Ashwin Naren
d96374faba Add _pyrepl (#5540)
---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-04-11 09:30:58 +09:00
Ashwin Naren
02533ace81 remove nntplib 2025-04-11 09:28:43 +09:00
Ashwin Naren
22333e755b remove svg 2025-04-11 09:27:00 +09:00
Ashwin Naren
8dc1718002 Match statements rewrite (#5628) 2025-04-10 14:00:54 +09:00
Ashwin Naren
ad5ffb648f Remove packaging from release (#5680) 2025-04-08 13:37:47 +09:00
Ashwin Naren
861055f558 Add nt constants (#5676) 2025-04-06 17:23:56 +09:00
Ashwin Naren
3c6bc2cf9f Add _suggestions module (#5675) 2025-04-06 17:22:26 +09:00
Ashwin Naren
be56911598 _tkinter pt. 2 (#5640) 2025-04-06 17:21:28 +09:00
Noa
98137eb79c Switch to const-initialized thread_local variables where appropriate 2025-04-05 19:59:43 +09:00
Hanif Ariffin
2230d6c751 Fix not throwing the same error as CPython in test_pathlib.test_expanduser (#5578)
* Fix not throwing the same error as CPython when trying to expanduser of a non-existent user

Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>

* add pwd test

* Skip pwd test on windows

---------

Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
Co-authored-by: Jeong YunWon <jeong@youknowone.org>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-04-05 15:33:33 +09:00
Hanif Ariffin
d800a6bb98 Update test_math from CPython 3.13.2 (#5610)
Implemnted fma in math module.
2025-04-05 14:53:40 +09:00
Jeong, YunWon
e0a35e4322 Merge pull request #5661 from arihant2math/doc
Fix doc warnings
2025-04-05 14:49:41 +09:00
dependabot[bot]
c2665e38ba Bump openssl from 0.10.71 to 0.10.72
Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.71 to 0.10.72.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.71...openssl-v0.10.72)

---
updated-dependencies:
- dependency-name: openssl
  dependency-version: 0.10.72
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-05 14:48:08 +09:00
Ashwin Naren
ab4dffb53c this should just fail if warnings happen because of RUSTFLAGS 2025-04-04 11:37:40 -07:00
Jeong YunWon
36cce6b174 run fmt 2025-04-05 00:14:03 +09:00
Ashwin Naren
5c854fc690 clear out warnings 2025-04-04 21:46:28 +09:00
Ashwin Naren
883e0cab29 build docs on CI and deny warnings 2025-04-04 21:46:09 +09:00
Jeong YunWon
d7113e11db Fix more cspell warnings 2025-04-04 21:45:03 +09:00
Jeong, YunWon
66cf905e8b Merge pull request #5668 from youknowone/cspell
update  cspell dicts and ci order
2025-04-04 16:41:40 +09:00
Jeong YunWon
7ac61f3840 fix cspell warnings 2025-04-04 16:15:54 +09:00
Jeong YunWon
2c94b809ae move cspell to last step 2025-04-04 16:09:51 +09:00
Jeong, YunWon
d52081fe41 Merge pull request #5663 from arihant2math/remove-dep-modules 2025-04-04 16:04:58 +09:00
Ashwin Naren
e7f04612f6 remove chunk.py 2025-04-04 16:03:48 +09:00
Ashwin Naren
fd4ad3e4d1 Remove smtpd 2025-04-04 16:03:31 +09:00
Ashwin Naren
f1d45ee5a7 remove unused deprecated libraries 2025-04-03 22:12:54 -07:00
Ashwin Naren
6620aa07af update email to 3.13.2 2025-04-03 22:12:54 -07:00
Ashwin Naren
8063148598 Fix clippy lints from rust 1.86 update (#5665)
* handle rust 1.86 update

* fix windows clippy lint

* disable cspell under jit/instruction

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2025-04-04 14:04:13 +09:00
Ashwin Naren
2bf2332806 Cleanup whats_left.py (#5654)
* cleanup whats_left.py

* add features flag
2025-04-02 16:31:25 +09:00
Ashwin Naren
64a0721616 Remove broken badge from readme 2025-04-01 08:08:16 -07:00
dependabot[bot]
c3ed002b12 Bump streetsidesoftware/cspell-action from 2 to 6 in the github-actions group (#5646)
* Bump streetsidesoftware/cspell-action in the github-actions group

Bumps the github-actions group with 1 update: [streetsidesoftware/cspell-action](https://github.com/streetsidesoftware/cspell-action).


Updates `streetsidesoftware/cspell-action` from 2 to 6
- [Release notes](https://github.com/streetsidesoftware/cspell-action/releases)
- [Changelog](https://github.com/streetsidesoftware/cspell-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/streetsidesoftware/cspell-action/compare/v2...v6)

---
updated-dependencies:
- dependency-name: streetsidesoftware/cspell-action
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update .github/workflows/ci.yaml

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-04-01 10:31:07 +09:00
Ashwin Naren
f6a9754b4e Remove telnetlib deprecated in 3.13 (#5649) 2025-04-01 10:19:39 +09:00
Ashwin Naren
264f3d792a remove xdrlib deprecated in 3.13 (#5648) 2025-04-01 10:18:42 +09:00
Ashwin Naren
cb967c697b Fix release CI (#5647) 2025-04-01 10:17:29 +09:00
Noa
e21a04cf4b Merge pull request #5635 from hbina/hbina-fix-py313-test-bool
Fixed an expected failure in the behavior of negating a bool argument
2025-03-31 11:04:07 -05:00
Hanif Ariffin
f0bcad7116 Added test_audit
This test is currently noop because RustPython does not have sys.audit?

Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
2025-03-31 18:49:08 +09:00
Jeong YunWon
57a83db69d try IncrementalNewlineDecoder in doctest 2025-03-31 18:00:36 +09:00
ivan-shrimp
3ad8fd711f fix expression list order
don't emit a no-op when unpacking a single element

assume positional args stored as tuple in extended call
2025-03-31 18:00:19 +09:00
Noa
160363fa46 Fix float parsing (#5643)
* Fix float parsing

* Add rustpython_literal::complex

* Don't call .to_string() on a constant
2025-03-31 14:37:47 +09:00
Noa
0b35946972 Make FromArgs default field take an expression, not a string literal 2025-03-31 11:48:06 +09:00
Noa
24d995678f Remove some unncessary dependencies 2025-03-31 11:28:15 +09:00
Hanif Ariffin
8e7039405e Fix some clippy issues
Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
2025-03-30 23:53:20 +08:00
Hanif Ariffin
8f989e4a67 Fixed an expected failure in the behavior of negating a bool argument
Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
2025-03-30 23:01:20 +08:00
Jeong, YunWon
696dceacdc Merge pull request #5255 from youknowone/lib-socket
Update socket and test from CPython 3.12.2
2025-03-30 14:47:30 +09:00
Jeong YunWon
9e2f6bd187 mark failing tests of test_socket 2025-03-30 14:20:17 +09:00
Jeong YunWon
b620f03728 Update socket from CPython 3.12.2 2025-03-30 13:55:55 +09:00
Jeong, YunWon
ade45c2312 Merge pull request #5391 from JazzGlobal/4982-AddMissingFieldsToPyStructTime 2025-03-30 13:44:37 +09:00
Noa
b067986576 Bump cranelift to 0.118 2025-03-30 13:40:24 +09:00
Jeong YunWon
763ba9fd6a edit test_time 2025-03-29 09:46:47 +09:00
Jeong YunWon
fd270775a3 time._STRUCT_TM_ITEMS 2025-03-29 09:46:47 +09:00
Jeong YunWon
b99e7f62b2 Add pystruct(skip) 2025-03-29 09:46:47 +09:00
Christopher Gambrell
bb8606dbed implement tm_gmtoff and tm_zone 2025-03-29 09:46:47 +09:00
Jeong YunWon
0abd8b1d87 Fix pystructseq 2025-03-29 09:46:47 +09:00
Jeong, YunWon
58a17f337d Merge pull request #5633 from coolreader18/compiler-deps 2025-03-28 13:45:00 +09:00
Noa
d3d92bbb6f Update unparse to work with ruff & remove ruff_python_codegen 2025-03-27 22:14:58 -05:00
Noa
8081e0d281 Copy unparse.rs from rustpython-parser 2025-03-27 22:09:00 -05:00
Noa
f398321b1f Remove parser dependency from codegen 2025-03-27 22:09:00 -05:00
Noa
7d05f881c4 Have rustpython_literal::escape support wtf8 2025-03-28 11:26:29 +09:00
Noa
030243a6f9 Split out wtf8 into its own crate 2025-03-28 11:26:29 +09:00
Noa
6b72d2ef5d Check+lint examples, tests, and benches in CI 2025-03-28 11:26:12 +09:00
Noa
b6aacbf401 Merge pull request #5629 from coolreader18/surrogate-literals
Parse surrogates in string literals properly
2025-03-27 10:15:41 -05:00
Noa
dd467f6c73 Update common/src/wtf8/mod.rs
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-03-27 10:15:18 -05:00
Jeong, YunWon
cd89aa51f0 Fix _ctypes.Array base and metaclass (#5620) 2025-03-27 19:45:04 +09:00
Jeong, YunWon
f27c1f7ea3 Merge pull request #5624 from youknowone/libffi-workspace
common dependency in workspace
2025-03-27 14:51:47 +09:00
Jeong, YunWon
c7ca173c90 Merge pull request #5254 from youknowone/exception-group
ExceptionGroup
2025-03-27 14:51:12 +09:00
Noa
c9161c02b6 Merge pull request #5625 from youknowone/clippy
Apply nightly clippy suggestions
2025-03-26 23:40:42 -05:00
Noa
6e79a2aa8a Merge pull request #5626 from youknowone/remove-unused-deps
Remove unused dependency
2025-03-26 23:37:52 -05:00
Noa
bea25a0285 Merge pull request #5627 from youknowone/once-cell
Replace direct use of once_cell to std
2025-03-26 23:36:31 -05:00
Jeong, YunWon
c96fd3d900 Merge pull request #4700 from youknowone/cspell
Activate cspell lint
2025-03-27 13:25:08 +09:00
Noa
0a07cd931f Fix more surrogate crashes 2025-03-26 23:12:21 -05:00
Noa
c6cab4c43a Parse surrogates in string literals properly 2025-03-26 22:44:42 -05:00
Noa
2ab8716c95 Merge pull request #5623 from coolreader18/refactor-codecs
Refactor codecs
2025-03-26 14:01:26 -05:00
Noa
e3d96aa3ca Remove commented-out code
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-03-26 12:42:03 -05:00
Jeong YunWon
10d2837041 rework dicts 2025-03-27 02:15:03 +09:00
Jeong YunWon
372e683063 disable cspell from files with a bunch of OS jargons 2025-03-27 01:47:17 +09:00
Jeong YunWon
5f6f6cce92 add cspell to CI 2025-03-27 01:30:09 +09:00
Jeong YunWon
27bcba3027 wasm test prints more info 2025-03-27 01:28:36 +09:00
Jeong YunWon
053583f5a0 Add wasm/demo/.envrc 2025-03-27 01:28:36 +09:00
Jeong YunWon
5e0eace8d9 test_exception_group from CPython 3.12.2 2025-03-27 01:28:36 +09:00
Jeong YunWon
e7fdfca5f5 Add python-implemented ExceptionGroup 2025-03-27 01:28:36 +09:00
Jeong YunWon
2d4eec88d3 better webdriver error printing 2025-03-27 01:28:34 +09:00
Jeong YunWon
7f94c10be7 patch typing not to reqiure contextlib
This will be correctly fixed in future CPython
2025-03-27 01:20:23 +09:00
Jeong YunWon
549cce24c8 Add #[pystruct(skip)] 2025-03-26 22:40:43 +09:00
Jeong YunWon
97fa11d526 Remove unused dependency 2025-03-26 20:18:29 +09:00
Jeong YunWon
ad5788589b Remove more direct use of OnceCell 2025-03-26 18:22:23 +09:00
Jeong YunWon
ec09599d84 Remoce once_cell::Lazy usage 2025-03-26 18:22:23 +09:00
Noa
f323d14ed3 Refactor codecs 2025-03-26 02:24:01 -05:00
Jeong YunWon
bc38e9dedd Apply nightly clippy suggestions 2025-03-26 14:52:23 +09:00
Noa
7ac90f5cbc Merge pull request #5587 from coolreader18/wtf8
Allow surrogates in str
2025-03-25 21:08:01 -05:00
Noa
f3b8d5515a Address comments 2025-03-25 21:06:56 -05:00
Noa
bd55baefa6 Optimize Wtf8Codepoints::count 2025-03-25 19:05:12 -05:00
Noa
a86126419c Fix remaining tests 2025-03-25 19:05:12 -05:00
Noa
5c22697344 Implement fsencode/fsdecode for FsPath 2025-03-25 19:05:12 -05:00
Noa
cc6f3d3051 Make TextIOWrapper wtf8-compatible 2025-03-25 19:05:12 -05:00
Noa
b36b32bfe8 Make re wtf8-compatible 2025-03-25 19:05:12 -05:00
Noa
3945d3b2fe Make format wtf8-compatible 2025-03-25 19:05:12 -05:00
Noa
ba1b5811ee Update encoding to use wtf8 2025-03-25 19:05:11 -05:00
Noa
7f4582bb23 Make cformat wtf8-compatible 2025-03-25 19:05:11 -05:00
Noa
cace112b1a Allow surrogates in str 2025-03-25 19:05:11 -05:00
Noa
e3a1031081 Refactor cformat in prep for wtf8 2025-03-26 08:36:16 +09:00
Jeong, YunWon
2a41072b44 Windows installer via cargo-packager (#5549)
* cargo-packager config

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* add templates

* update release.yml

* update wix installer config

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-03-25 10:27:45 +09:00
Ashwin Naren
01d470ff77 _ctypes pt. 4 (#5582)
* correct error type when symbol is not found

* restype get/set

* base of PyCSimple for PyCArray

* PyCSimple::to_arg

* par down ctypes

* nt._LOAD_LIBRARY_SEARCH_DEFAULT_DIRS

* arguments for ctypes function

* force failure to import ctypes
2025-03-25 09:09:29 +09:00
Ashwin Naren
9779de98b8 _tkinter pt. 1 (#5583)
* Add _tkinter module and gate

* add tkinter module

* add tcl_error

* fix tk setup and add demo

* fix TK_VERSION

* create and TkApp
2025-03-23 12:25:52 +09:00
Noa
c585678ec9 Merge format and literal back into this repo (and update malachite) (#5618)
* Merge format and literal back into this repo

* Update format and literal to work

* Update malachite

* Remove RustPython/Parser from Cargo.toml
2025-03-23 09:27:13 +09:00
Jeong, YunWon
eaf4cdf5e1 Update to ruff_python_parser 0.11 (#5615)
* Update to ruff_python_parser 0.11

* Try fix windows long paths error
2025-03-23 08:28:29 +09:00
Noa
948368fdb4 Try fix windows long paths error 2025-03-20 11:29:49 -05:00
0717d5a331 remove wrong cpython_only tag 2025-03-20 14:35:04 +09:00
a9bfaa96c5 remove unnecessary cpython_only 2025-03-20 14:35:04 +09:00
70a5774737 Update CPYTHON_SPECIFIC_MODS to include '_testlimitedcapi' 2025-03-20 14:35:04 +09:00
2d3b125d51 Add expectedFailure and skip decorators for RUSTPYTHON tests in test_class.py 2025-03-20 14:35:04 +09:00
4081c08b5a add cpython_only tag for tests required _testlimitedcapi 2025-03-20 14:35:04 +09:00
70c36a48a8 Copy test_class.py from cpython v3.13.2 2025-03-20 14:35:04 +09:00
Ashwin Naren
37bd49cf38 add _pylong.py at 3.13.2 2025-03-20 14:33:54 +09:00
Ashwin Naren
081dc4e8ca removed cgib (#5609) 2025-03-20 14:28:53 +09:00
Ashwin Naren
a4466adf8b add _aix_support 2025-03-20 14:28:26 +09:00
Noa
bfe72689fc Remove -merge from Cargo.lock gitattributes 2025-03-20 14:28:03 +09:00
Noa
950a8d5694 Update to ruff_python_parser 0.11 2025-03-19 22:45:57 -05:00
Stefan Lukas
a6b4ef7f5d Replace Python parser with ruff parser (#5494)
* stage1

* compiler pass build

* introduce rustpython-compiler-source

* stage2

* fixup

* pass compile

* Fix hello world compiler test

* Fix code generation for if-elif-else statement

* Fix code generation for lambda expression

* Fix code generation for integers

* Fix code generation for fstrings

* Fix code generation for if statement

* Fix code generation for if statement

* Fix code generation for if statement

* Fix code generation for fstring

* Fix code generation for class definition

* Replace feature flags

* Initialize frozen core modules

* Allow __future__ import after module doc comment

* Disable ast module

* Commit remaining fixes for compile errors in examples

* Fix some warnings

* Update ast stdlib module

* Update ast stdlib module

* Update ast stdlib module

* Update ast stdlib module

* Update ast stdlib module

* Split ast stdlib module into files

* Fix codegen for positional arguments with defaults

* Update ast stdlib module

* Update ast stdlib module

* Extract string and constant handling from expression.rs

* Always add required fields to AST nodes

* Compile doc strings correctly again

* Enable "ast" Cargo feature by default

* Refactor compilation of big integer literal

* Update ast stdlib module

* Update ast stdlib module

* Update ast stdlib module

* Reset barebones example

* Fix some left-over warnings

* Undo accidential change

* Adapt shell to ruff parser

* Pin parser to v0.4.10

* fix clippy

* Add TODO about interactive mode

* Fix compilation of complex number expression

* Remove moved code

* Update test case to ruff v0.4.10

* Apply suggestion

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

* Apply suggestion

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

* Fix compilation of fstring expression

* Fix compilation of fstring expression

* Fix wasm compile errors

* Attach correct source locations to ast objects

* Fix some more wasm compile errors

* Consider compile mode and enable AST stdlib module again

* Fix incorrect AST source location end column

* Fix compile error if "compiler" feature is not enabled

* Fix regrtests

* Fix some test_ast tests

* Add source range to type ignore

* Fix incompatibility with Rust 2024 edition

* Fix todos by implementing missing ast conversions and deleting unused code

* Appease clippy

* Fix remaining ast tests

* Fix remaining ast tests

* Mark/fix remaining tests

* Fix more

* Hacky windows fix

---------

Co-authored-by: Kangzhi Shi <shikangzhi@gmail.com>
Co-authored-by: Jeong YunWon <jeong@youknowone.org>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
Co-authored-by: Noa <coolreader18@gmail.com>
2025-03-19 21:06:03 -05:00
Nicholas Paulick
45c0fa0e77 Floating Point Power and While Loop JIT (#5614)
* Initial commit for power function

* Float power jit developed

* Addded support for Floats and Ints

* Integration Testing for JITPower implementation.

* Update instructions.rs

* Update int_tests.rs

* Update float_tests.rs

* Updated cranelift and power function to use magic bs

* Updated the compile_fpow accuracy

* updating while loop test

* Update instructions.rs

cranelift more like painlift

* Update instructions.rs

* Update instructions.rs

* initial commit for making stable PR ready features

* fixed final edge case for compile_ipow

* fixed final edge case for compile_ipow

* commenting out compile_ipow

* fixed spelling errors

* removed unused tests

* forgot to run clippy

* Cleaned the branch

* While loop implementation for Cranelift 0.116.1

* Floating Point

* Removed testing print statement

* Resolved some formatting

* Fixed cargo fmt warning

* Fixed int div and int exp issues

* Fixed formatting

---------

Co-authored-by: Nick <nick@Samanthas-MBP.wi.rr.com>
Co-authored-by: JoeLoparco <loparcojoseph@gmail.com>
Co-authored-by: Daniel O'Hear <149127239+dohear@users.noreply.github.com>
Co-authored-by: Joseph Loparco <149088810+JoeLoparco@users.noreply.github.com>
Co-authored-by: Nick <nick@pcp090057pcs.mu.edu>
Co-authored-by: dohear <daniel.ohear@marquette.edu>
Co-authored-by: Nathan Rusch <nathan.rusch@icloud.com>
Co-authored-by: Nick <nick@pcp093574pcs.mu.edu>
Co-authored-by: Joseph Loparco <--global loparcoJoseph@gmail.com>
Co-authored-by: Nick <nick@Samanthas-MacBook-Pro.local>
2025-03-19 13:50:42 -05:00
Noa
a596568151 Use lexopt for argument parsing (#5602) 2025-03-19 12:28:58 -05:00
Jeong, YunWon
bd94d8d50c Remove uu.py and test_uu.py (#5607)
* Remove uu.py and test_uu.py

* patch email.message
2025-03-14 11:42:26 +09:00
Ashwin Naren
7fab64ed9c Revert "Update statistics to 3.13.2 (#5592)" (#5606)
This reverts commit ff970b0e1c.
2025-03-14 11:41:14 +09:00
Ashwin Naren
8e22c399df partially fix sys.getwindowsversion() (#5595) 2025-03-14 11:38:35 +09:00
Ashwin Naren
7546ea91a9 patch email.message 2025-03-13 10:16:51 -07:00
Ashwin Naren
8da66978bf Remove uu.py and test_uu.py 2025-03-13 09:49:10 -07:00
Ashwin Naren
8484bfa2e0 Remove cgi module (#5597)
* no cgi

* mark failing test
2025-03-12 09:47:34 +09:00
Ashwin Naren
ff970b0e1c Update statistics to 3.13.2 (#5592)
* statistics to 3.13.2

* set flaky test
2025-03-11 22:37:26 +09:00
Jeong, YunWon
8be7e4327d Merge pull request #5596 from arihant2math/osx-support-313
_osx_support update to 3.13.2
2025-03-11 15:58:19 +09:00
Jeong, YunWon
82eeb237dc Merge pull request #5598 from arihant2math/fix-whats-left-again
Fixed whats left
2025-03-11 15:57:57 +09:00
Ashwin Naren
cbbadf562f Fixed whats left 2025-03-10 23:27:05 -07:00
Ashwin Naren
4308321f39 _osx_support update to 3.13 2025-03-10 23:13:32 -07:00
Jeong, YunWon
985eebf9b0 Merge pull request #5589 from youknowone/pyattr-const
Replace pyattr(once) to constant
2025-03-11 10:12:50 +09:00
Ashwin Naren
bf28152a32 add os support modules 2025-03-10 11:43:53 +09:00
Ashwin Naren
bae0ad3aeb Fix extra newline in module.csv generation in cron ci (#5591) 2025-03-10 11:43:26 +09:00
Jeong YunWon
87fae150da Replace pyattr(once) to constant 2025-03-09 12:39:12 +09:00
Ashwin Naren
97853bf0f1 Fix module.csv generation in cron ci (#5586) 2025-03-06 13:20:04 +09:00
Noa
cc0a1ce9e2 Update webpack (#5585)
* Update webpack

* Build demo before notebook

* Use with instead of env for actions-gh-pages
2025-03-05 16:15:14 -06:00
Daniel O'Hear
58ebf04bac Add JIT compilation support for integer multiplication, division, and exponents (#5561)
* Initial commit for power function

* Float power jit developed

* Addded support for Floats and Ints

* Integration Testing for JITPower implementation.

* Update instructions.rs

cranelift more like painlift

* Update instructions.rs

* Update instructions.rs

* initial commit for making stable PR ready features

* fixed final edge case for compile_ipow

* fixed final edge case for compile_ipow

* commenting out compile_ipow

* fixed spelling errors

* removed unused tests

* forgot to run clippy

---------

Co-authored-by: Nicholas Paulick <paulicknicholas@gmail.com>
Co-authored-by: Nick <nick@Samanthas-MBP.wi.rr.com>
Co-authored-by: JoeLoparco <loparcojoseph@gmail.com>
Co-authored-by: Nathan Rusch <nathan.rusch@icloud.com>
Co-authored-by: dohear <daniel.ohear@marquette.edu>
2025-03-05 14:41:45 -06:00
Ashwin Naren
7fea1e1b4a fix what is left data upload to website and trigger cron-ci on workflow update 2025-03-05 13:50:52 -06:00
Ashwin Naren
d2bf31724f fix clippy 2025-03-05 13:49:37 -06:00
Ashwin Naren
b4929d258d formatting 2025-03-05 13:49:37 -06:00
Ashwin Naren
ddf2e591c6 resolve comments 2025-03-05 13:49:37 -06:00
Ashwin Naren
33940726a8 upgrade to windows-sys 0.59.0 2025-03-05 13:49:37 -06:00
Ashwin Naren
05cb8c0b73 Update socket.rs
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2025-03-05 13:49:37 -06:00
Ashwin Naren
8d2c6807d2 fix non-windows build 2025-03-05 13:49:37 -06:00
Ashwin Naren
4d9804f188 formatting 2025-03-05 13:49:37 -06:00
Ashwin Naren
3ae1160868 Remove winapi dependency 2025-03-05 13:49:37 -06:00
Ashwin Naren
6804dd4363 use rust-toolchain targets options instead of using rustup 2025-03-05 13:45:31 -06:00
Ashwin Naren
defcadafbb publish demo on weekly release 2025-03-05 13:45:31 -06:00
Ashwin Naren
40e3f49ab7 _ctypes pt. 3 (#5530)
* Initial CFuncPtr implementation

* function calling via libffi

* working no-arg function call

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-03-03 15:53:04 +09:00
Ashwin Naren
56196890f5 Actions caching for nodejs (#5575)
* caching for nodejs and various CI dependency updates

* commit the package-lock.json
2025-03-02 18:18:17 +09:00
Noa
6daee1b00e Warn on elided_lifetimes_in_paths 2025-03-01 13:49:33 +09:00
Ashwin Naren
8ff856d7ce _ctypes addressof and Structure (#5573)
* _ctypes.addressof

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* ctypes.Structure implementation

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* clippy fix

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

* formatting

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-03-01 13:48:28 +09:00
Ashwin Naren
6731c4b1ab fix devcontainer.json 2025-02-28 13:50:10 -06:00
Ashwin Naren
544182ebfc update license dates 2025-02-27 19:10:56 -06:00
Ashwin Naren
12c3fa0b87 update wix installer config 2025-02-27 08:48:22 -08:00
Ashwin Naren
aa4774fe32 update release.yml 2025-02-27 08:44:42 -08:00
Ashwin Naren
26bc4ba3dd add templates 2025-02-26 22:39:00 -08:00
Noa
b2abb1af84 Remove redundant lints now that we're on edition2024 2025-02-26 23:46:57 -06:00
Ashwin Naren
cebbca9e63 cargo-packager config
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-26 20:59:10 -08:00
Jeong, YunWon
1a2dda502a Merge pull request #5560 from arihant2math/2024-migrate
Migrate to the 2024 edition
2025-02-27 12:22:03 +09:00
Ashwin Naren
b870b0e1b5 2024 edition formatting
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-26 11:48:22 -08:00
Ashwin Naren
df2354fdb7 migrate to the 2024 edition
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-26 11:47:32 -08:00
Jeong, YunWon
c20c90fbc4 Merge pull request #5563 from coolreader18/fix-zlib-tests
Fix a bunch of zlib tests & update gzip.py to Python 3.13
2025-02-26 15:47:52 +09:00
CPython Developers
aba3d5c082 Update gzip,test_gzip from CPython 3.13 2025-02-26 00:10:24 -06:00
Noa
8c5602f2fb Fix a bunch of zlib tests 2025-02-26 00:10:24 -06:00
Noa
4468dcbe34 Switch to libz-rs-sys for zlib implementation 2025-02-25 23:19:19 -06:00
Ashwin Naren
235adafa0b tests
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-25 17:19:53 +09:00
Noa
864e8598f8 Enable rust2024-incompatible pat and keyword-ident lints 2025-02-25 00:32:02 -06:00
Jeong, YunWon
f426348a94 Merge pull request #5558 from coolreader18/openssl-probe-no-env
Use non-env-var methods from openssl_probe
2025-02-25 14:54:19 +09:00
Noa
085ac88438 Use non-env-var methods from openssl_probe 2025-02-24 23:10:07 -06:00
Noa
4881f61be6 Mark env::{set,remove}_var() unsafe 2025-02-24 23:02:54 -06:00
Jeong, YunWon
ff9947ff14 Enable unsafe_op_in_unsafe_fn and missing_unsafe_on_extern lints (#5557)
* Enable unsafe_op_in_unsafe_fn lint

* Enable missing_unsafe_on_extern lint

* Make PyObjectRef::{from,into}_raw() use NonNull
2025-02-25 13:42:25 +09:00
Noa
92e02a7f79 Make PyObjectRef::{from,into}_raw() use NonNull 2025-02-24 21:25:23 -06:00
Noa
0a8b0406f5 Enable missing_unsafe_on_extern lint 2025-02-24 21:25:23 -06:00
Noa
1c3b198a17 Enable unsafe_op_in_unsafe_fn lint 2025-02-24 21:25:23 -06:00
Noa
52208b3c90 Update to syn2 (#5556) 2025-02-25 11:54:13 +09:00
Noa
2721f2de3f Fix a bunch of random tests (#5533) 2025-02-25 08:41:54 +09:00
Ashwin Naren
b55a55afc7 update the csv with the temp data for website what's left
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-24 11:30:27 -06:00
Ashwin Naren
d7a72b5755 add constants and implement functions
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-24 16:16:34 +09:00
Ashwin Naren
1f3a9672c3 Add _winapi.GetACP and enable test_unicode on windows (#5547)
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-24 13:21:02 +09:00
Axect
31c5c3eb9d Update puruspe version to 0.4.0
To resolve the issue (#5496)
2025-02-24 11:15:33 +09:00
Ashwin Naren
7fada8b97e fix _ctypes error names
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-23 16:07:52 +09:00
Ashwin Naren
429754fd33 Fix unicode decode bug on surrogate error mode (#5546)
* subtract with overflow to check for whether to use surrogate

* enable test_argparse for windows on ci

------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-23 16:07:22 +09:00
Ashwin Naren
b4f0a589ed platform-dependent Windows testing (#5536)
* disable test_argparse on windows

* fix test_exceptions and mark it as platform dependent

* test importlib on windows

* explain why windows tests fail

* mark test_argparse as non platform-independent

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-23 09:48:02 +09:00
Noa
331a3c108f Switch to criterion in sre_engine benchmarks 2025-02-23 09:44:57 +09:00
Ashwin Naren
d698b28ce5 Ensure pymethod cannot be both magic and named simultaneously + macro documentation (#5538)
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-22 17:22:31 +09:00
Ashwin Naren
23236aa8c7 test_datetime now works on windows
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-21 15:09:40 +09:00
Noa
a9331bb34d Fix warnings for rust 1.85 2025-02-20 14:58:59 -06:00
Hanif Ariffin
65dcf1ce1c Updating test_math.py to CPython 3.12.9 (#5507)
* Fixed implementation against CPython 3.12.9 Lib/test/test_math.py tests
---------

Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2025-02-20 11:21:12 +09:00
Ashwin Naren
e2b0fe4266 _ctypes pt. 2 (#5524)
* add __version__

* add more types/constants

* shared library and ExternalLibs implementation

* FreeLibrary for windows

* fixed PyCSimple

* LoadLibrary and FreeLibrary for non-windows

* fault-tolerant float equality

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-20 10:50:10 +09:00
Noa
fa2acd7cde Update rand to 0.9 2025-02-18 17:07:26 +09:00
Ashwin Naren
a71c16f8cb test colorize on ci
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-18 16:52:04 +09:00
Ashwin Naren
f466971312 clippy
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-18 15:50:27 +09:00
Ashwin Naren
69b1a9910f formatting
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-18 15:50:27 +09:00
Ashwin Naren
4ed735b424 time.daylight for windows
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-18 15:50:27 +09:00
Ashwin Naren
175afd97d8 time.timezone for windows
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-18 15:50:27 +09:00
Ashwin Naren
72338d578b tzname on windows
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-18 15:50:27 +09:00
Ashwin Naren
9856d94f2d function to retrieve tz info on windows
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-18 15:50:27 +09:00
Ashwin Naren
517ffed401 fix clippy lint
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-17 14:15:57 -06:00
Ashwin Naren
38a6a8d984 duplicate windows-sys
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-17 14:15:57 -06:00
Ashwin Naren
630c1ff8d1 simple part of the bump
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-17 14:15:57 -06:00
Ashwin Naren
7e1568a1ff Revert "windows-rs upgrade to 0.59"
This reverts commit 547530724e.
2025-02-17 14:15:57 -06:00
Ashwin Naren
6788010f7d windows-rs upgrade to 0.59 2025-02-17 14:15:57 -06:00
Ashwin Naren
9e310934d3 fix panic
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-17 12:00:39 -06:00
Ashwin Naren
e8a3406624 itertools upgrade 2025-02-16 10:20:56 +09:00
Ashwin Naren
fde87a340c Initial _ctypes implementation (#5519)
* initial _ctypes implementation with _CData, get_errno, and set_errno

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-15 16:03:58 +09:00
Jeong, YunWon
19050afc3f Merge pull request #5520 from arihant2math/colorize
Add _colorize at 3.13.2
2025-02-14 15:34:26 +09:00
Ashwin Naren
e96557b3e1 add _colorize.py at 3.13.2
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-13 20:11:36 -08:00
Ashwin Naren
a5364973d9 implement nt._supports_virtual_terminal
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-13 20:11:05 -08:00
Ashwin Naren
a46ce8ec3a Mark version 3.13.0 (#5495)
* bump to 3.13.1
* fix some tests
* strip left whitespace from doc
* remove specific difflib test that was causing issues
* fix test_enum

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-13 14:11:01 +09:00
Ashwin Naren
6e35e20e49 dependency bump
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-02-12 18:16:45 +09:00
Noa
2d5e4d89b0 Update openssl to fix possible vulnerability 2025-02-12 15:57:41 +09:00
Hanif Ariffin
c9e62002ec Fixed the implementation of some math functions to match CPython closer. (#5510)
Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
2025-02-11 17:09:38 +09:00
Lee Dogeon
465627f104 Implement vm logics related with ParamSpec, TypeVarTuple 2025-02-10 21:21:38 +09:00
Ashwin Naren
3de1c2ab56 Update malachite-q and base to 0.4.22 (#5499)
* update malachite-q and base to 0.4.22

* Update malachite-bigint from parser

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2025-02-10 15:55:08 +09:00
Jeong, YunWon
8f5cc6174c fix windows sleep 2025-02-07 07:53:28 +09:00
Jeong YunWon
29d014a0e1 Pin malachite versions to avoid API incompatibility 2025-02-03 11:57:30 +09:00
Ashwin Naren
396a0ca563 Basic Match statements (#5485)
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-01-25 23:14:15 +09:00
Jeong YunWon
a500178b3c update parser to fix match crash 2025-01-22 13:41:01 +09:00
Jeong YunWon
7d770f55fb more assertions in switch_to_block 2025-01-21 23:53:23 +09:00
Jeong, YunWon
db283a66e8 Merge pull request #5477 from youknowone/better-downcast-error
Add better panic for abnormal downcast error
2025-01-21 13:54:45 +09:00
Jeong, YunWon
c642aef8ca Merge pull request #5481 from arihant2math/builtins-312
Update tests for builtin objects to python 3.12.8
2025-01-20 14:04:28 +09:00
Ashwin Naren
396df1a506 update test_listcomps.py to 3.12.8 2025-01-19 20:05:35 -08:00
Ashwin Naren
9c9fa7e537 update test_list to 3.12.8 2025-01-19 20:05:35 -08:00
Ashwin Naren
86e2eb0648 update test_float to 3.12.8 2025-01-19 20:05:34 -08:00
Ashwin Naren
491db2f0c6 update test_unary to 3.12.8 2025-01-17 18:04:25 -08:00
Ashwin Naren
f0fb375028 update numbers tests 2025-01-17 15:48:59 -08:00
Ashwin Naren
16d8bab61a Update Logging to 3.12.7 (#5478)
* updated logging to 3.12, added logging tests, and added smtplib and tests

* fix expected failures on test_smtplib.py

* mark all rustpython fails on test_logging.py
2025-01-17 19:44:06 +09:00
Ashwin Naren
2d83a67bd6 Update zlib from 3.12.6 and _ZlibDecompressor implementation (#5476)
* add is_s390x and skip_on_s390x to test support

* update zlib tests to 3.12

* _ZlibDecompressor implementation
2025-01-16 13:28:09 +09:00
Jeong YunWon
5ad7e97e05 Add better panic for abnormal downcast error 2025-01-16 00:57:09 +09:00
Jeong YunWon
b7a7b6b923 remove warnings from wasm build 2025-01-13 15:06:29 +09:00
Jeong YunWon
0e00d2328d wasm32-wasi -> wasm32-wasip1 2025-01-13 15:06:29 +09:00
Shubham Patil
53db70e784 Support recursion in JIT-ed functions (#5473) 2025-01-13 14:55:27 +09:00
Sacha Dupuydauby
76c699b4ba Update contextlib from CPython 3.12 2025-01-12 00:40:41 +09:00
Noa
c901bc07a4 Upgrade wasm deps + fix demo 2025-01-11 18:48:27 +09:00
Noa
b7db23bbae Fix warnings for Rust 1.84 2025-01-11 18:48:27 +09:00
Jeong, YunWon
389b20d977 Merge pull request #5444 from key262yek/update_fstring_from_v3.12.7
Update fstring from v3.12.7
2025-01-10 10:44:31 +09:00
Bob McWhirter
d06459fa49 guard signal-handling init more broadly
If `install_signal_handlers` is false (due to embedding),
the VM still inits the signal stdlib and installs a lot
of signal-handling, including touching *ever* signal,
including SIGINT.

When running multiple concurrent interpreters with
varying inits at varying times, this can break the
hosting application's signal-handling so lovingly
set up before starting anything with RustPython.
2025-01-09 16:21:25 -06:00
Shubham Patil
e2a55cbf34 Handle pre-release flag being empty for schedule triggers in release workflow
GitHub workflow_dispatch input variables are always empty for other triggers
2025-01-09 17:31:02 +09:00
Jeong, YunWon
a5e6ade9cb Merge pull request #5454 from coolreader18/rust-1.83
Bump MSRV to 1.83
2025-01-07 13:13:42 +09:00
Jeong, YunWon
a1e32566d3 Merge pull request #5469 from fu050409/patch-1 2025-01-07 12:38:08 +09:00
Noa
8c7bfb3e1a Fix redox 2025-01-06 13:09:49 -06:00
苏向夜
bb0480e978 docs(readme): fix installation command for cargo 2025-01-07 00:52:16 +08:00
Jeong, YunWon
2ccc745513 Merge pull request #5465 from crazymerlyn/caseless-bump 2025-01-04 11:43:30 +09:00
Jeong, YunWon
bea83fe94d Merge pull request #5466 from theshubhamp/gh-release 2025-01-04 11:43:10 +09:00
Shubham Patil
3feaf689d8 Re-enable Release Notes Generation 2025-01-03 21:49:17 +05:30
Shubham Patil
bd627b58af Schedule Pre-Release on Monday 9AM UTC 2025-01-03 21:49:17 +05:30
Shubham Patil
c561d33cb2 Support both Release & Pre-Release in Release Workflow
On Push "main" is removed
2025-01-03 21:49:17 +05:30
Ashwin Naren
c8fd3bd683 Build wasm on release 2025-01-03 14:56:58 +09:00
Ankit Goel
fef1e31634 Bump rust-caseless to 0.2.2 2024-12-31 12:26:29 +00:00
Shubham Patil
1abaf87abe Temporarily disable release notes generation
Release creation fails with this error:
```
HTTP 422: Validation Failed (https://api.github.com/repos/RustPython/RustPython/releases)
body is too long (maximum is 125000 characters)
Error: Process completed with exit code 1.
```

Most likely because there's no previous release to diff of from.

Disabling, getting a green release & enabling back might fix this.
2024-12-30 16:44:55 +09:00
Shubham Patil
38593fbd85 Check operand types in bool or, and, xor to be PyInt (#5461)
* Added Tests for Bitwise or, and, xor type error

* Sync binary operator order comment with actual implementation

* Check operand types in bool or, and, xor to be PyInt

PyNumber methods are expected to type check both arguments.

Dispatch is not done by inverting parameter order for __r<op>__ (example __ror__) when calls are handled via PyNumberMethods
2024-12-30 16:44:27 +09:00
Ankit Goel
8d187fd275 Bump result-like to 0.5.0 2024-12-28 11:38:00 +09:00
Shubham Patil
646cc81656 Add GitHub Binary Release Pipeline for RustPython (#5456) 2024-12-28 11:34:53 +09:00
carsonzhu
01f7536b36 expose run_shell 2024-12-11 17:33:36 +09:00
Jeong, YunWon
97e5ec02f8 Merge pull request #5449 from key262yek/update_test_float_from_CPython_v3.12.7
Update test float from c python v3.12.7
2024-12-06 12:50:55 +09:00
Oskar Skog
3dced01af0 Move os.system from posix.rs to os.rs
Fixes #5100
2024-12-06 12:19:34 +09:00
0cf4534c5c copy new file "Lib/test/support/testcase.py" for test_float.py 2024-12-05 15:29:35 +09:00
044f66fba3 copy from cpython v3.12.7 2024-12-05 15:29:35 +09:00
40a9ddad4e update test_fstring.py from cpython 3.12.7
add expectedFailure to tag what should rustpython do
add comment for some syntaxerror which make test run broken
2024-12-05 15:04:56 +09:00
Noa
848db340da Merge pull request #5442 from coolreader18/cli-fixes
Miscellaneous cli-related parity fixes
2024-12-03 23:57:57 -06:00
Noa
c6da4ffcdd Try to fix universal write on windows 2024-12-03 18:01:44 -06:00
Noa
8ac7e34be2 Updates for Rust 1.83 2024-12-03 17:05:24 -06:00
Noa
e4be882994 Miscellaneous cli-related parity fixes 2024-12-03 16:28:32 -06:00
Noa
adc05e663f Merge pull request #5443 from coolreader18/incremental-newline-decoder
Implement IncrementalNewlineDecoder in rust
2024-12-03 16:28:00 -06:00
Jeong, YunWon
0bc236ac98 Merge pull request #5450 from key262yek/resolve_lint_fails_w_rust_1.83_clippy
Resolve lint fails w rust 1.83 clippy
2024-12-02 12:42:37 +09:00
da3d3d9296 allow manual c string literal 2024-11-29 11:57:42 +09:00
6a6af6a952 change to use c str literal 2024-11-29 11:19:10 +09:00
582a4ab267 delete elided lifetime 2024-11-29 11:18:53 +09:00
ebde8546c9 remove elided lifetime 2024-11-29 11:05:44 +09:00
fffd0f5465 new clippy lint update Rust v1.83.0 2024-11-29 09:53:54 +09:00
dependabot[bot]
3b6db8e21a Bump the github-actions group with 7 updates
Bumps the github-actions group with 7 updates:

| Package | From | To |
| --- | --- | --- |
| [actions/checkout](https://github.com/actions/checkout) | `3` | `4` |
| [actions/setup-python](https://github.com/actions/setup-python) | `4` | `5` |
| [actions/setup-node](https://github.com/actions/setup-node) | `3` | `4` |
| [mwilliamson/setup-wabt-action](https://github.com/mwilliamson/setup-wabt-action) | `1` | `3` |
| [peaceiris/actions-gh-pages](https://github.com/peaceiris/actions-gh-pages) | `2` | `4` |
| [wasmerio/setup-wasmer](https://github.com/wasmerio/setup-wasmer) | `2` | `3` |
| [codecov/codecov-action](https://github.com/codecov/codecov-action) | `3` | `5` |


Updates `actions/checkout` from 3 to 4
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

Updates `actions/setup-python` from 4 to 5
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4...v5)

Updates `actions/setup-node` from 3 to 4
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v3...v4)

Updates `mwilliamson/setup-wabt-action` from 1 to 3
- [Release notes](https://github.com/mwilliamson/setup-wabt-action/releases)
- [Commits](https://github.com/mwilliamson/setup-wabt-action/compare/v1...v3)

Updates `peaceiris/actions-gh-pages` from 2 to 4
- [Release notes](https://github.com/peaceiris/actions-gh-pages/releases)
- [Changelog](https://github.com/peaceiris/actions-gh-pages/blob/main/CHANGELOG.md)
- [Commits](https://github.com/peaceiris/actions-gh-pages/compare/v2...v4)

Updates `wasmerio/setup-wasmer` from 2 to 3
- [Release notes](https://github.com/wasmerio/setup-wasmer/releases)
- [Commits](https://github.com/wasmerio/setup-wasmer/compare/v2...v3)

Updates `codecov/codecov-action` from 3 to 5
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: mwilliamson/setup-wabt-action
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: peaceiris/actions-gh-pages
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: wasmerio/setup-wasmer
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-27 17:44:35 -07:00
Noa
19a0b7dd76 Merge pull request #5445 from cclauss/patch-2
Keep GitHub Actions up to date with GitHub's Dependabot
2024-11-27 13:21:11 -06:00
Noa
9647ebe206 Fix prettier formatting 2024-11-27 13:20:19 -06:00
Noa
0c726a1275 Merge pull request #5447 from isbm/isbm-move-exception-loglevel
Move log message to the debug level
2024-11-27 13:04:03 -06:00
Jeong, YunWon
f71eb55f1f Merge pull request #5438 from key262yek/update_random_from_v3.12.3
Update random from v3.12.7
2024-11-26 16:33:36 -07:00
Jeong, YunWon
edcc0b7dbc Merge pull request #5437 from key262yek/update_numbers_from_v3.12.3
Update numbers.py from v3.12.7
2024-11-26 16:30:37 -07:00
Buciu Theodor Marian
4910b308ee Fix compile error when using ``vm-tracing-logging`` 2024-11-26 16:26:00 -07:00
Bo Maryniuk
0cc1c323ed Move log message to the debug level 2024-11-26 21:29:08 +01:00
Christian Clauss
24fd19b35d Keep GitHub Actions up to date with GitHub's Dependabot
Fixes software supply chain safety warnings like at the bottom right of

https://github.com/RustPython/RustPython/actions/runs/11870777239
* [Keeping your actions up to date with Dependabot](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot)
* [Configuration options for the dependabot.yml file - package-ecosystem](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem)
2024-11-26 16:38:54 +01:00
Noa
fbd0c7a99e Implement IncrementalNewlineDecoder in rust 2024-11-14 23:06:53 -06:00
4f5b26698c skip test 'super' object has no attribute 'getstate' 2024-11-11 00:17:57 +09:00
d887e5c24c first copy from cpython v3.12.3 2024-11-11 00:17:30 +09:00
0c69391bbd Copy test for numbers.py from v3.12.3 2024-11-10 00:15:21 +09:00
91598f9121 change numbers.py from [v3.12.3](6293d00e72/Lib/numbers.py (L8)) 2024-11-10 00:13:13 +09:00
Jeong YunWon
98d09e7816 Remove time.daylight from freebsd 2024-10-31 16:13:52 +09:00
7ae9432524 Change deprecated type PanicInfo to PanicHookInfo 2024-10-31 01:45:59 +09:00
Noa
c883f0ad8a Updates for Rust 1.82 2024-10-17 16:32:47 -05:00
Noa
eae60113af Update some stuff for inline const & associated type bounds 2024-10-17 16:32:17 -05:00
Noa
1aab5240cf Update for rust 1.77 2024-10-17 16:32:17 -05:00
dependabot[bot]
edb7abde5a Bump pyo3 from 0.22.3 to 0.22.4
Bumps [pyo3](https://github.com/pyo3/pyo3) from 0.22.3 to 0.22.4.
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pyo3/pyo3/compare/v0.22.3...v0.22.4)

---
updated-dependencies:
- dependency-name: pyo3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-16 05:37:46 +09:00
Noa
29d95340b0 Merge pull request #5418 from crazymerlyn/memoryerror
Handle MemoryError for sequences
2024-09-29 10:50:01 -05:00
Ankit Goel
6fb19ac74f Handle MemoryError for sequences 2024-09-29 16:24:30 +01:00
Noa
37dc28a69d Update deps (#5417)
* Upgrade nix

* Update deps

* Upgrade pyo3, winreg

* Fix errors from upgrading
2024-09-27 13:11:00 +09:00
Ankit Goel
7623668256 Raise TypeError if BaseException receives Keyword arguments 2024-09-24 11:57:37 +09:00
Noa
bbf7aacd4d Merge pull request #5409 from crazymerlyn/cache-frozenset-hash
Cache hash value for FrozenSets
2024-09-23 17:43:55 -05:00
Noa
d6c1e08ef4 Merge pull request #5413 from crazymerlyn/remove-proc-macro-crate
Remove dependency on proc-macro-crate
2024-09-23 17:42:40 -05:00
Ankit Goel
d1f95f04a7 Remove dependency on proc-macro-crate
This dependency is only useful when modifying the crate name of
`num_enum` crate. RustPython doesn't do that so it's unnecessary.
2024-09-23 16:54:21 +01:00
Ankit Goel
0dacf8a326 Remove dependency on uuid-macro-internal
`uuid-macro-internal` is only relevant when using `uuid!` macro to parse
uuids at compile time. RustPython doesn't do that so it's unnecessary.
2024-09-23 15:07:57 +09:00
Noa
e534b10722 Fix build with ossl1 2024-09-22 17:38:26 +09:00
Jeong, YunWon
0785cc5aa9 Merge pull request #5406 from coolreader18/improve-posixsubprocess
Improve posixsubprocess
2024-09-22 17:37:34 +09:00
Ankit Goel
48025e0102 Cache hash value for FrozenSets
Adds a hash field to the `PyFrozenSet` data type in order to avoid
recomputing the hash of an immutable object.
2024-09-22 06:15:54 +01:00
Noa
eeb719e8f7 Merge pull request #5411 from crazymerlyn/decimal-from-float
Fix inconsistent behavior of Decimal.from_float
2024-09-21 22:58:23 -05:00
Noa
7933edad43 Add missing functionality to posixsubprocess 2024-09-21 22:40:15 -05:00
Ankit Goel
5f75728ede Fix inconsistent behavior of Decimal.from_float 2024-09-22 01:42:28 +01:00
Ankit Goel
8cff0ed6c2 Avoid allocating a vector of elements when hashing frozenset (#5408)
Adds a `try_fold_keys` method to Dict which allows performing common
operations on all elements without needing to create a Vec first.
2024-09-21 23:18:26 +09:00
Noa
a8964f4108 Add select.epoll 2024-09-20 11:46:01 +09:00
Noa
740aeedca3 Merge pull request #5405 from crazymerlyn/fix-set-intersection-update
Fix set intersection_update implementation
2024-09-19 21:21:16 -05:00
Noa
8152e7e62c Make Gid/Uid less janky 2024-09-19 17:50:52 -05:00
Ankit Goel
b36c95b91e Fix set intersection_update implementation 2024-09-19 20:59:12 +01:00
Ricardo Robles
b5c1fd95dc Add zoneinfo from Python 3.12.6 (#5400) 2024-09-19 11:18:48 +09:00
Noa
23f7cbf1c3 Make sqlite optional 2024-09-19 11:13:51 +09:00
hongmengning
ae78ecc2c5 Add missing symbols in exceptions.rs 2024-09-17 16:07:30 +09:00
Ankit Goel
dd06516d1c Deprecate delegating int() to __trunc__ 2024-09-17 16:06:09 +09:00
Ankit Goel
8066f36a4e Fix copysign behavior for NaNs (#5396) 2024-09-11 15:19:21 +09:00
Jeong YunWon
3bbf6b9d53 less strict time bound for test_re.test_search_anchor_at_beginning 2024-09-10 16:31:43 +09:00
dependabot[bot]
8bc5944178 Bump webpack from 4.28.2 to 5.94.0 in /wasm/example
Bumps [webpack](https://github.com/webpack/webpack) from 4.28.2 to 5.94.0.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v4.28.2...v5.94.0)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-28 14:14:51 +09:00
Niels Buwen
a13b99642b Add get/set methods for function module/annotations (#5392)
---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2024-08-19 00:59:51 +09:00
Jeong, YunWon
060db5983c Merge pull request #5390 from youknowone/wasmbind
recreating wasmbind patch
2024-08-09 09:37:49 +09:00
Jeong YunWon
42bba6920e apply suggestion 2024-08-09 02:23:49 +09:00
Noa
ea11d78995 Fix compilation without compiler feature 2024-08-09 02:23:49 +09:00
Jeong YunWon
fe63ca762f separate wasm-unknown-test 2024-08-09 02:23:49 +09:00
Jeong YunWon
a82982725e fix getrandom 2024-08-09 02:23:49 +09:00
Noa
7dfb760421 Make rustpython-vm compatible with non-js wasm32-unknown & add tests 2024-08-09 02:04:25 +09:00
Jeong YunWon
b6e9a3f37e rustpython_wasm uses the new feature 2024-08-09 00:59:29 +09:00
Jeong YunWon
3f28309b7b revert unnecessary change 2024-08-09 00:58:53 +09:00
Jeong YunWon
d2a4a330f9 following chrono/wasmbind convention 2024-08-09 00:58:11 +09:00
Benjamin DeMann
d8c35770ab enable js feature of getrandom only for wasmbind 2024-08-09 00:29:47 +09:00
Benjamin DeMann
dbb6794a41 add cfg for not wasmbind for time 2024-08-09 00:29:25 +09:00
Benjamin DeMann
63c9909aa0 run the first block if wasmbind is not present 2024-08-09 00:29:25 +09:00
Benjamin DeMann
f1dac5087e address pr notes 2024-08-09 00:29:25 +09:00
Benjamin DeMann
4f80d7013e add wasmbind feature 2024-08-09 00:29:25 +09:00
Jeong YunWon
2919df1df5 Mark rust-version 1.78 2024-08-08 23:20:17 +09:00
Jeong YunWon
a2df2f014b Fix dis.dis without compiler feature 2024-08-07 09:48:09 +09:00
Jeong YunWon
8673169ee7 0.4.0 2024-08-07 08:38:21 +09:00
Jeong YunWon
2c2e0fb172 pyperf bench script 2024-08-07 08:38:21 +09:00
Jeong YunWon
d45c5de906 ignore local config files 2024-08-07 08:38:21 +09:00
Jeong YunWon
eb985beed6 freeze-stdlib imply stdlib 2024-08-07 07:48:42 +09:00
Jeong YunWon
ff9aa0fc54 Add example projects 2024-08-07 07:48:42 +09:00
Jeong YunWon
0bd1a3efb2 vm.print 2024-08-07 07:06:27 +09:00
Jeong YunWon
08e7ec948b Don't let Interpreter::run silently ignore result value 2024-08-07 07:06:15 +09:00
Jeong YunWon
6092c07eb5 better error message for freeze-stdlib 2024-08-07 07:05:28 +09:00
CPython Developers
09d74336fa Update fraction,test_numeric_tower from CPython 3.12.4 2024-07-29 19:53:44 +09:00
Jeong YunWon
694354e5e6 temp fix slot member_count 2024-07-29 16:45:35 +09:00
Andrew Bowen
55f04db6b8 Update codecs and test_codecs from cpython v3.12.4 (#5372)
* updated test_codecs.py from cpython v3.12.4

* updated codecs.py from cpython v3.12.4
2024-07-29 14:55:32 +09:00
Jeong YunWon
6f8360a878 sys.exception 2024-07-29 14:30:59 +09:00
Jeong YunWon
6ca4685fee __objclass__ 2024-07-29 14:30:46 +09:00
Jeong, YunWon
d86b592add Merge pull request #5370 from youknowone/update-io
Update io, _pyio, test_io from CPython 3.12
2024-07-28 21:12:13 +09:00
Jeong YunWon
9944b3dac1 Mark failing tests 2024-07-28 20:24:15 +09:00
Jeong YunWon
8ed79bd1af add a dummy parameter for support.skip_if_sanitizer 2024-07-28 20:24:15 +09:00
CPython Developers
0600ae6213 Update io, pyio, test_io from CPython 2024-07-28 20:24:15 +09:00
Jeong YunWon
623415d843 IncrementalNewlineDecoder from pyio 2024-07-28 20:23:53 +09:00
Jeong YunWon
87b84a83cc Fix TextIOWrapper.reconfigure coder 2024-07-28 20:23:53 +09:00
Jeong YunWon
aa5eba9723 fix BufferedMixin::tell 2024-07-28 20:23:53 +09:00
Jeong YunWon
c2cd883f93 TextIOWrapper.reconfigure 2024-07-28 16:24:32 +09:00
Jeong YunWon
43e20a8cd9 Fix os.putenv & test_os.test_envronb 2024-07-28 16:24:17 +09:00
Jeong YunWon
48299cdd7f Add faulthandler to wasm32 2024-07-28 12:11:56 +09:00
Dan Näsman
2335ca0f72 Add proper underscore handling to float and complex types. (#5356) 2024-07-28 12:11:34 +09:00
Jeong YunWon
e42c1a33b5 upgrade unicode_names2 2024-07-28 11:43:00 +09:00
Jeong, YunWon
b1a38c2d50 Fix rust 1.80 warnings (#5363)
* Fix rust 1.80 warnings

* Fix nightly clippy warnings
2024-07-28 10:43:40 +09:00
dependabot[bot]
f1f05303db Bump openssl from 0.10.62 to 0.10.66
Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.62 to 0.10.66.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.62...openssl-v0.10.66)

---
updated-dependencies:
- dependency-name: openssl
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-23 11:14:45 +09:00
Jeong YunWon
8424a733a2 type constructor 2024-07-14 22:08:09 +09:00
Jeong YunWon
2bf7a4a08c FuncArgs::is_empty() 2024-07-14 22:08:09 +09:00
Jeong, YunWon
b4bae8173b Merge pull request #5348 from JamesClarke7283/developer-experiance-tweaks
DX improvements: Updated MSRV, added cargo deny toml file, and added lints to workspace
2024-07-01 21:09:49 +09:00
James Clarke
3c10888e3a Disabled some uneeded lits 2024-06-30 13:41:40 +01:00
James Clarke
1bd143027a Switched to system implementation of libffi and fixed minor lint errors 2024-06-30 13:29:04 +01:00
James Clarke
18d31f2d5b Merge branch 'RustPython:main' into developer-experiance-tweaks 2024-06-30 12:34:12 +01:00
James Clarke
e142d655b9 changed int_max_str_digits from -1 to 4300 to be more cpython complient (#5343)
* changed int_max_str_digits from -1 to 4300 to be more cpython complient, fixes #5139
2024-06-27 15:27:54 +09:00
James Clarke
e1ce1f66cd Updated MSRV 2024-06-25 04:56:22 +01:00
James Clarke
08c9a4d86b Added lints and deny.toml 2024-06-25 03:59:40 +01:00
Kirill Podoprigora
a620b38ba0 Add test_copyreg.py from 3.12 2024-06-24 19:00:54 +09:00
Jeong, YunWon
8e3c0cd658 Merge pull request #5314 from youknowone/datetime
Update datetime from CPython v3.12.3
2024-06-22 17:38:59 +09:00
Jeong YunWon
f709a2805d mark failing tests 2024-06-22 16:18:34 +09:00
Jeong, YunWon
adbadfc4f5 Merge pull request #5342 from youknowone/getstate
object.__getstate__
2024-06-22 15:49:23 +09:00
CPython Developers
9c7a9cbace Update datetime from CPython v3.12.3 2024-06-22 15:27:19 +09:00
CPython Developers
1333688a4e update copyreg from CPython 3.12.3 2024-06-22 15:24:42 +09:00
Jeong YunWon
17852b78d5 mark hanging test 2024-06-22 15:24:42 +09:00
Jeong YunWon
dd15ae5560 Unmark successful tests 2024-06-22 15:24:42 +09:00
Jeong YunWon
9d33990199 object.__getstate__ 2024-06-22 15:15:49 +09:00
Cherry
866e7cf371 Make a shared run function in ThreadedVirtualMachine (#5337) 2024-06-22 14:43:07 +09:00
Jeong YunWon
f5c1596ddf PyCFunction_GET_SELF 2024-06-22 00:40:30 +09:00
Jeong YunWon
64cff172a1 pymethod(raw) 2024-06-22 00:40:13 +09:00
kingler
c10b99b29a Update keyword.py and test_keyword.py from CPython v3.12.0 2024-06-21 22:37:15 +09:00
Snowapril
bca90f191c Fix missing_transmute_annotations, legacy_numeric_constants added in Rust 1.79.0 clippy (#5339) 2024-06-16 20:26:22 +09:00
Jonathan Rotter
7996a10116 await in list comprehension (#5334)
* check if comprehension element contains await

* force execution to pause in async gen
2024-05-27 16:54:56 +09:00
Dmitry Mottl
db4562f67d Fixes a typo 2024-05-22 10:07:44 +09:00
Noa
3fd0382a51 Use RPITIT where applicable 2024-05-21 14:47:10 +09:00
Noa
3e98e5e86c Bump libsqlite3-sys 2024-05-21 09:05:49 +09:00
Jeong YunWon
7b17965b26 Enable macOS SSL 2024-05-21 09:05:26 +09:00
Jeong YunWon
5c050d5779 feature ssl-vendor implies ssl 2024-05-20 19:41:51 +09:00
Jeong, YunWon
5d6d1a6da7 OpenSSL3 in README 2024-05-20 13:07:36 +09:00
Daniel Chiquito
b59d876e76 Make __bases__ mutable (#5325)
* Make PyType.bases and PyType.mro mutable

* Add a set function for __bases__

* Re-enable fixed test_descr tests
2024-05-20 12:28:07 +09:00
Jeong YunWon
9028aede6e Reduce rc ops from best_base 2024-05-19 19:24:52 +09:00
Snowapril
aa0353a501 Fix best_base to select proper base class (#5324)
* add __basicsize__ getter

* modify best_base function to get proper base

* inherit basicsize from the base type

---------

Signed-off-by: snowapril <sinjihng@gmail.com>
2024-05-19 15:48:56 +09:00
Jeong YunWon
63c3f31c99 skip flaky test in test_context 2024-05-17 14:02:40 +09:00
Jeong YunWon
2fe44af8ba time.{tzname,timezone,daylight} 2024-05-14 11:17:58 +09:00
matheusfgoncalves95
515f0bf9c2 Adding generator_stop to compile_future_features (#5320)
* Adding generator_stop to compile_future_features.

* Removing expected failure from PEP 479 unit test.
2024-05-13 23:18:55 +09:00
hydrogen602
27a52a7962 test_class.py: testTypeAttributeAccessErrorMessages fix 2024-05-13 16:25:37 +09:00
hydrogen602
61feb43aba test_builtin.py: test_type_qualname fix 2024-05-13 14:18:18 +09:00
Jonathan Rotter
07fdcb6160 Fix for test future.py test annotations (#5319)
* enable test fixed in parser

* update parser dependency
2024-05-13 08:40:14 +09:00
Daniel Chiquito
ac08f4447f Add 3.12 typing features to the compiler (#5302) 2024-05-10 20:09:04 +09:00
Jeong, YunWon
d243c90d0a Update site from CPython v3.12.3 (#5313)
* Update site from CPython v3.12.3

* mark failing test

---------

Co-authored-by: CPython Developers <>
2024-05-09 23:04:31 +09:00
Jeong, YunWon
72033ab689 Update ipaddress from CPython v3.12.3 (#5312)
Co-authored-by: CPython Developers <>
2024-05-09 15:56:11 +09:00
Jeong, YunWon
3f63501fa8 Merge pull request #5311 from youknowone/pathlib
Update pathlib from CPython v3.12.3
2024-05-09 15:46:25 +09:00
Jeong YunWon
019496e3a8 Instruction::ReturnConst 2024-05-09 15:26:16 +09:00
Jeong YunWon
52695a9ece Skip tests to avoid slot bug 2024-05-09 15:20:38 +09:00
CPython Developers
a20ce951e7 Update pathlib from CPython v3.12.3 2024-05-09 15:20:25 +09:00
Jeong YunWon
85fa157d5a Update test_os from CPython v3.12.3 2024-05-09 11:51:05 +09:00
Jeong, YunWon
1068219c56 Update Lib/asyncio from CPython v3.12.3 (#3858)
Co-authored-by: CPython Developers <>
2024-05-09 05:02:46 +09:00
Jeong, YunWon
427ec50624 _overlapped 2024-05-09 04:41:39 +09:00
Jeong, YunWon
52ce1509a5 optimize range.__contains__ and iter_search 2024-05-09 01:26:09 +09:00
Jeong YunWon
fe06583643 posix.sysconf 2024-05-08 18:46:17 +09:00
Jeong YunWon
3e3c69b5bc Fix non-msvc build 2024-05-08 16:30:41 +09:00
Jeong YunWon
3b0802535d _winapi.NULL 2024-05-08 16:30:41 +09:00
Jeong YunWon
75415090bd ConfName -> PathConfName 2024-05-08 14:50:51 +09:00
Jeong YunWon
6f664cb05a Fix initgroups nul error 2024-05-08 14:50:51 +09:00
Jonathan Rotter
a8ea67178d adjusted SyntaxError args and __str__() to match CPython (#5294) 2024-05-08 12:57:03 +09:00
Jeong, YunWon
64a464aefb Update audiotests from CPython 3.12.3 (#5304)
Co-authored-by: moonlightaria <edch66@gmail.com>
2024-05-08 12:52:33 +09:00
jparag
67885ad9fa Update gettext.py and related test to 3.12 version (#5287)
Co-authored-by: Parag Jain <parag.jain2@capitalone.com>
2024-05-08 00:02:59 +09:00
Jeong YunWon
e5bf72e897 contextvars 2024-05-07 22:43:21 +09:00
Jeong YunWon
1f62190eef Use Sequence protocol for in operation 2024-05-07 21:33:14 +09:00
Jeong YunWon
f839e6cc79 more #[pyclass(Py, PyRef)] 2024-05-06 01:32:46 +09:00
Jeong YunWon
52aad1ec08 DefaultConstructor impls Constructor; Unconstructible is not anymore 2024-05-06 00:54:39 +09:00
Jeong YunWon
5f0d1252b6 suppress empty-doc warning 2024-05-04 02:00:18 +09:00
Jeong YunWon
3370f0f23d Update wasm-bindgen 2024-05-04 02:00:18 +09:00
Jeong YunWon
e1574b1485 sys.{get,set}_asyncgen_hooks 2024-05-02 13:45:03 +09:00
Jeong YunWon
78fae736f9 sys.get_coroutine_origin_tracking_depth 2024-05-01 21:32:14 +09:00
Jeong YunWon
ed3811a65c wasi select module 2024-05-01 17:54:24 +09:00
Jeong, YunWon
4e915de35d Merge pull request #5290 from youknowone/subprocess
Update subprocess from CPython 3.12.3
2024-05-01 16:24:35 +09:00
CPython Developers
94e6648ee5 Update selectors from CPython v3.12.3 2024-05-01 15:59:23 +09:00
Jeong YunWon
75a985e63e mark failng tests 2024-05-01 15:59:23 +09:00
CPython Developers
5714558785 Update subprocess from CPython 3.12.3 2024-05-01 04:23:14 +09:00
Jeong, YunWon
c3ccb5b7bf Merge pull request #5289 from youknowone/fixes
Align Settings to CPython PyConfig
2024-04-30 23:18:43 +09:00
Jeong YunWon
87849cda4f fix grammar 2024-04-30 23:18:14 +09:00
Jeong YunWon
f62114c7eb zlib-ng as default 2024-04-30 23:18:14 +09:00
Jeong YunWon
24f57dde2f Align Settings to PyConfig 2024-04-30 23:18:14 +09:00
Jeong, YunWon
cdfcd8a4c9 Merge pull request #5288 from youknowone/enable-wasi-unittest
Enable wasi unittest
2024-04-30 23:13:07 +09:00
Jeong YunWon
1bc1370701 Add wasi unittest CI 2024-04-30 22:21:56 +09:00
Jeong YunWon
6b7b080827 Add sys._stdlib_dir when freeze-stdlib 2024-04-30 22:21:56 +09:00
Jeong YunWon
3556e1320d wasm os.getpid 2024-04-29 14:42:02 +09:00
Jeong YunWon
621640ca71 Add const-only signals for wasm32 2024-04-28 10:31:38 +09:00
Jeong YunWon
2c0e439d0d Disable jit for macos from CI to avoid arm64 CI failure 2024-04-28 00:07:55 +09:00
Jeong YunWon
a392d8425e Fix wasmer example 2024-04-26 20:57:32 +09:00
Jeong YunWon
0273d78de9 Update signal from CPython 3.12.3 2024-04-26 01:39:02 +09:00
Jeong YunWon
ed51d8dcf6 upgrade geckodriver 2024-04-25 23:11:56 +09:00
Jeong, YunWon
3d78ca8b09 Merge pull request #5263 from youknowone/multiprocessing
Update multiprocessing from CPython 3.12.3
2024-04-25 22:05:11 +09:00
Jeong YunWon
1cec856c63 skip flaky test_socket sendmsg tests in macos 2024-04-25 22:04:40 +09:00
Jeong, YunWon
6212c81ec6 Merge pull request #5276 from youknowone/async-for-comprehension
Async for comprehension
2024-04-25 21:00:22 +09:00
Jeong YunWon
408459b883 vm runtime debug prints 2024-04-25 20:34:53 +09:00
Jeong YunWon
f6d88042b5 Uncomment test_grammar tests 2024-04-25 20:23:34 +09:00
Jeong YunWon
b58bdc9e32 Uncomment async for tests 2024-04-25 20:23:34 +09:00
Jeong YunWon
f3501f44cb Basic async for comprehension support 2024-04-25 20:23:25 +09:00
HyeockJinKim
61f37b10e2 implement async for function in compiler 2024-04-25 20:20:58 +09:00
Aaron Long
2856aff757 Begin async list comprehension implementation 2024-04-25 20:20:22 +09:00
Jeong YunWon
3949ecc054 implement more GetANext 2024-04-25 19:16:48 +09:00
Jeong YunWon
acd9ea57d7 Fix async for block 2024-04-25 17:40:15 +09:00
Jeong YunWon
794a2a1892 remove pop-push 2024-04-25 17:40:15 +09:00
hydrogen602
af8bed6d3f filter out doc strings with opt level 2 2024-04-25 16:11:04 +09:00
Jeong YunWon
462f54f906 Fix with __exit__ error handling 2024-04-25 15:17:50 +09:00
Jeong YunWon
1c4e99cf2c popblock debug 2024-04-25 15:17:50 +09:00
Jeong YunWon
a349b9bdfe frame debug codes 2024-04-24 21:46:14 +09:00
Jeong YunWon
75e790836a debuggable 2024-04-24 20:44:17 +09:00
hardlydearly
5ba677cd36 chore: fix some typos in comments
Signed-off-by: hardlydearly <799511800@qq.com>
2024-04-24 17:52:58 +09:00
Jeong, YunWon
a7b761a89c windows symlink flag 2024-04-24 02:43:01 +09:00
Jeong, YunWon
6e0b00d60c Merge pull request #5262 from youknowone/ntpath
Update ntpath from CPython 3.12.3
2024-04-24 01:46:49 +09:00
Jeong YunWon
c107a938be remove -u all from mac/windows 2024-04-24 01:46:27 +09:00
Jeong YunWon
c6fc9cee8e Update filecmp from CPython 3.12.2 2024-04-24 01:46:27 +09:00
Jeong YunWon
99a4bf5eb5 remove import dummp_os 2024-04-24 01:46:27 +09:00
CPython Developers
46410ff933 Add test_multiprocessing from CPython 3.12.3 2024-04-24 01:15:34 +09:00
CPython Developers
75e868e71e Update multiprocessing from CPython 3.12.3 2024-04-24 01:15:08 +09:00
Jeong, YunWon
53b1b4d682 Mark failing tests in test_ntpath 2024-04-24 00:54:12 +09:00
CPython Developers
566d9bee5c Update ntpath from CPython 3.12.3 2024-04-24 00:54:12 +09:00
Jeong, YunWon
b8bf65d68e os.listdrives 2024-04-24 00:54:09 +09:00
Jeong YunWon
075c69a3cd Skip setattr(__doc__) if not given 2024-04-23 22:44:22 +09:00
Jeong, YunWon
ada10067dd Merge pull request #5260 from youknowone/update-pickle
Update pickle from CPython 3.12.3
2024-04-23 21:37:32 +09:00
CPython Developers
d0f680b379 Update pickletools from CPython 3.12.3 2024-04-23 18:05:50 +09:00
Jeong YunWon
ca2c1d0b48 Update pickle from CPython 3.12.2 2024-04-23 16:46:16 +09:00
Jeong YunWon
5fd5939395 skip flaky socket test in macOS 2024-04-23 16:24:15 +09:00
Jeong, YunWon
e5ca631b52 Add bare ExceptionGroup (#5259) 2024-04-23 16:23:31 +09:00
Jonathan Rotter
3313fdeb32 test_builtin.py test_compile unit test fix (#5251)
* compile accepts memoryview now

* Update test_compile to what it is in CPython3.12

* compile optimize flag

* added undocumented flags to flag validator
2024-04-23 14:07:02 +09:00
Jeong, YunWon
2bd8ff0b6c Merge pull request #5257 from youknowone/os-posix
Update os/posix/posixpath from CPython 3.12.2
2024-04-23 13:33:40 +09:00
CPython Developers
5c9d6d455d Update genericpath/posixpath from CPython 3.12.2 2024-04-23 12:56:43 +09:00
CPython Developers
8f6cf6fef7 Update test_posix from CPython 3.12.2 2024-04-23 12:56:43 +09:00
CPython Developers
a5f8d42d34 Update os from CPython 3.12.2 2024-04-23 12:56:32 +09:00
CPython Developers
153ec2823d Update __future__ from CPython 3.12.2 2024-04-23 11:57:46 +09:00
CPython Developers
9f65a30504 Update encodings from CPyhton 3.12.2 2024-04-22 12:46:32 +09:00
CPython Developers
b018123f19 Update getopt from CPython 3.12.2 2024-04-22 12:46:32 +09:00
CPython Developers
97e3e969e4 Update glob from CPython 3.12.2 2024-04-22 12:46:32 +09:00
Noa
84099514e6 Implement socket.socket.sendmsg (#5205)
* Implement socket.socket.sendmsg

* debugger-friendly newlines

* Fix control_buf error on macOS

---------

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
2024-04-22 11:21:10 +09:00
Jeong, YunWon
3286e683e6 win32_xstat (#5247)
* win32_xstat

* vm::windows

* Add file_id
2024-04-21 22:02:09 +09:00
hydrogen602
be6ea2a7b8 fix for test test_bool.BoolTest.test_subclass 2024-04-21 07:09:08 +09:00
Jeong, YunWon
4a939141f6 Fix macos shutil (#5248)
* Fix macos shutil

* chmod+follow_symlinks=False calls lchmod
2024-04-21 07:07:58 +09:00
Jonathan Rotter
1034477f1e unit test fix - only allow catching exceptions - test_catch_non_BaseException (#5249)
* test_baseexception.test_catch_non_BaseException

* enabling test_except_star_invalid_exception_type
2024-04-21 01:30:20 +09:00
Jeong, YunWon
49cfcd817d remove some skipIf and enable shutil CI for windows (#5235)
* mark failing shtuil tests in windows

* unsetenv raise more informed error

* Remove a few skipIf for windows
2024-04-20 03:00:27 +09:00
Jeong, YunWon
39822d7e57 use less vm.new_os_error (#5245)
* vm.new_errno_error

* replace new_os_error in mmap

* replace posix new_os_error to new_errno_error
2024-04-20 01:32:33 +09:00
Jeong YunWon
142d333c5c Fix os.unsetenv 2024-04-20 00:36:00 +09:00
Jeong YunWon
13c491712b add six install to CI 2024-04-19 22:45:25 +09:00
Jeong, YunWon
5c527c2a28 Fix shutil test_copy_dir 2024-04-19 22:04:22 +09:00
toofooboo
41979f0823 chore: fix some typos in comments (#5243)
Signed-off-by: toofooboo <cmaker@foxmail.com>
2024-04-19 21:10:22 +09:00
Jeong, YunWon
192b0a8fb5 fileutils and fstat (#5242) 2024-04-19 19:21:35 +09:00
Jonathan Rotter
6a7be1e142 compat fix for testHashStuff in test_class.py (#5240)
* compat fix for testHashStuff in test_class.py

* accidently fixed 3 more tests
2024-04-19 16:44:23 +09:00
Jeong, YunWon
b3666060d4 better OSError.filename (#5239)
* Fix OSError message

* IOError with filename

* more filenames
2024-04-19 15:53:11 +09:00
Jeong, YunWon
c9c07a6bbc vm/ospath module 2024-04-19 13:25:19 +09:00
Jeong, YunWon
d57287b89b Fix OSError.winerror and errno/winerror converions 2024-04-19 04:56:25 +09:00
Jeong, YunWon
79e7015a32 CreateJunction 2024-04-19 03:00:33 +09:00
Jeong, YunWon
6c4ee951e0 fix windows OSError 2024-04-18 10:23:12 +09:00
Jeong YunWon
f0f4633346 Fix nightly clippy 2024-04-18 03:37:29 +09:00
hydrogen602
6c37e8f4e7 compat fix for test_field_metadata_custom_mapping in test_dataclasses.py 2024-04-17 21:52:10 +09:00
CPython Developers
4d05416ce3 Update ensurepip from CPython 3.12 2024-04-17 12:03:31 +09:00
Lee Dogeon
60993b9d23 Bump shutil to 3.12.3 (#5228)
* Bump shutil to 3.12.3

* Implement windows platform target `is_junction` with junction library

* Add _winapi.NeedCurrentDirectoryForExePath

---------

Co-authored-by: Jeong, YunWon <jeong@youknowone.org>
2024-04-17 01:33:14 +09:00
Moreal
959e7c11ce Unmark fixed tests 2024-04-15 16:22:53 +09:00
Moreal
21ae739eec Check downcast to type first 2024-04-15 16:22:53 +09:00
Moreal
b1c3c9a9d6 Bump CPython version to 3.12.3 in CI 2024-04-14 13:07:13 +09:00
Moreal
bf985c8ac6 Fix None.__ne__ bug 2024-04-14 13:07:13 +09:00
Moreal
21c5eae717 Add testcase for __ne__ method 2024-04-14 13:07:13 +09:00
Lee Dogeon
4d5cf249a0 Allow update __class__ for mutable types or module subclasses (#5225)
* Allow update `__class__` for module subclasses

* Set `IMMUTABLETYPE` flag for static classes

* Unmark fixed tests
2024-04-14 13:03:48 +09:00
Jeong YunWon
8c7b811135 Fix _sha512 support 2024-04-11 21:17:53 +09:00
Jeong, YunWon
940b879950 Merge pull request #5222 from youknowone/vm-build
Fix rustpython-vm --no-default-features build
2024-04-11 15:29:43 +09:00
Jeong YunWon
ccf650d4ca Fix rustpython-vm --no-default-features build 2024-04-10 19:15:22 +09:00
Jeong, YunWon
6342f16eb5 Merge pull request #5219 from youknowone/0.3.1
0.3.1
2024-04-10 17:41:28 +09:00
2549 changed files with 680011 additions and 170453 deletions

View File

@@ -3,3 +3,6 @@ rustflags = "-C link-arg=/STACK:8000000"
[target.'cfg(all(target_os = "windows", not(target_env = "msvc")))']
rustflags = "-C link-args=-Wl,--stack,8000000"
[target.wasm32-unknown-unknown]
rustflags = ["--cfg=getrandom_backend=\"wasm_js\""]

View File

@@ -0,0 +1,46 @@
---
allowed-tools: Bash(container *), Bash(cargo *), Read, Grep, Glob
---
# Run Tests in Linux Container (Apple `container` CLI)
Run RustPython tests inside a Linux container using Apple's `container` CLI.
**NEVER use Docker, Podman, or any other container runtime.** Only use the `container` command.
## Arguments
- `$ARGUMENTS`: Test command to run (e.g., `test_io`, `test_codecs -v`, `test_io -v -m "test_errors"`)
## Prerequisites
The `container` CLI is installed via `brew install container`.
The dev image `rustpython-dev` is already built.
## Steps
1. **Check if the container is already running**
```shell
container list 2>/dev/null | grep rustpython-test
```
2. **Start the container if not running**
```shell
container run -d --name rustpython-test -m 8G -c 4 \
--mount type=bind,source=/Users/al03219714/Projects/RustPython3,target=/workspace \
-w /workspace rustpython-dev sleep infinity
```
3. **Run the test inside the container**
```shell
container exec rustpython-test sh -c "cargo run --release -- -m test $ARGUMENTS"
```
4. **Report results**
- Show test summary (pass/fail counts, expected failures, unexpected successes)
- Highlight any new failures compared to macOS results if available
- Do NOT stop or remove the container after testing (keep it for reuse)
## Notes
- The workspace is bind-mounted, so local code changes are immediately available
- Use `container exec rustpython-test sh -c "..."` for any command inside the container
- To rebuild after code changes, run: `container exec rustpython-test sh -c "cargo build --release"`
- To stop the container when done: `container rm -f rustpython-test`

View File

@@ -0,0 +1,49 @@
---
allowed-tools: Bash(python3:*), Bash(cargo run:*), Read, Grep, Glob, Bash(git add:*), Bash(git commit:*), Bash(cargo fmt:*), Bash(git diff:*), Task
---
# Investigate Test Failure
Investigate why a specific test is failing and determine if it can be fixed or needs an issue.
## Arguments
- `$ARGUMENTS`: Failed test identifier (e.g., `test_inspect.TestGetSourceBase.test_getsource_reload`)
## Steps
1. **Analyze failure cause**
- Read the test code
- Analyze failure message/traceback
- Check related RustPython code
2. **Verify behavior in CPython**
- Run the test with `python3 -m unittest` to confirm expected behavior
- Document the expected output
3. **Determine fix feasibility**
- **Simple fix** (import issues, small logic bugs): Fix code → Run `cargo fmt --all` → Pre-commit review → Commit
- **Complex fix** (major unimplemented features): Collect issue info and report to user
**Pre-commit review process**:
- Run `git diff` to see the changes
- Use Task tool with `general-purpose` subagent to review:
- Compare implementation against cpython/ source code
- Verify the fix aligns with CPython behavior
- Check for any missed edge cases
- Proceed to commit only after review passes
4. **For complex issues - Collect issue information**
Following `.github/ISSUE_TEMPLATE/report-incompatibility.md` format:
- **Feature**: Description of missing/broken Python feature
- **Minimal reproduction code**: Smallest code that reproduces the issue
- **CPython behavior**: Result when running with python3
- **RustPython behavior**: Result when running with cargo run
- **Python Documentation link**: Link to relevant CPython docs
Report collected information to the user. Issue creation is done only upon user request.
Example issue creation command:
```
gh issue create --template report-incompatibility.md --title "..." --body "..."
```

View File

@@ -0,0 +1,33 @@
---
allowed-tools: Skill(upgrade-pylib), Bash(gh pr list:*)
---
# Upgrade Next Python Library
Find the next Python library module ready for upgrade and run `/upgrade-pylib` for it.
## Current TODO Status
!`cargo run --release -- scripts/update_lib todo 2>/dev/null`
## Open Upgrade PRs
!`gh pr list --search "Update in:title" --json number,title --template '{{range .}}#{{.number}} {{.title}}{{"\n"}}{{end}}'`
## Instructions
From the TODO list above, find modules matching these patterns (in priority order):
1. `[ ] [no deps]` - Modules with no dependencies (can be upgraded immediately)
2. `[ ] [0/n]` - Modules where all dependencies are already upgraded (e.g., `[0/3]`, `[0/5]`)
These patterns indicate modules that are ready to upgrade without blocking dependencies.
**Important**: Skip any modules that already have an open PR in the "Open Upgrade PRs" list above.
**After identifying a suitable module**, run:
```
/upgrade-pylib <module_name>
```
If no modules match these criteria, inform the user that all eligible modules have dependencies that need to be upgraded first.

View File

@@ -0,0 +1,157 @@
---
allowed-tools: Bash(git add:*), Bash(git commit:*), Bash(python3 scripts/update_lib quick:*), Bash(python3 scripts/update_lib auto-mark:*)
---
# Upgrade Python Library from CPython
Upgrade a Python standard library module from CPython to RustPython.
## Arguments
- `$ARGUMENTS`: Library name to upgrade (e.g., `inspect`, `asyncio`, `json`)
## Important: Report Tool Issues First
If during the upgrade process you encounter any of the following issues with `scripts/update_lib`:
- A feature that should be automated but isn't supported
- A bug or unexpected behavior in the tool
- Missing functionality that would make the upgrade easier
**STOP the upgrade and report the issue first.** Describe:
1. What you were trying to do
- Library name
- The full command executed (e.g. python scripts/update_lib quick cpython/Lib/$ARGUMENTS.py)
2. What went wrong or what's missing
3. Expected vs actual behavior
This helps improve the tooling for future upgrades.
## Steps
1. **Run quick upgrade with update_lib**
- Run: `python3 scripts/update_lib quick $ARGUMENTS` (module name)
- Or: `python3 scripts/update_lib quick cpython/Lib/$ARGUMENTS.py` (library file path)
- Or: `python3 scripts/update_lib quick cpython/Lib/$ARGUMENTS/` (library directory path)
- This will:
- Copy library files (delete existing `Lib/$ARGUMENTS.py` or `Lib/$ARGUMENTS/`, then copy from `cpython/Lib/`)
- Patch test files preserving existing RustPython markers
- Run tests and auto-mark new test failures (not regressions)
- Remove `@unittest.expectedFailure` from tests that now pass
- Create a git commit with the changes
- **Handle warnings**: If you see warnings like `WARNING: TestCFoo does not exist in remote file`, it means the class structure changed and markers couldn't be transferred automatically. These need to be manually restored in step 2 or added in step 3.
2. **Review git diff and restore RUSTPYTHON-specific changes**
- Run `git diff Lib/test/test_$ARGUMENTS` to review all changes
- **Only restore changes that have explicit `RUSTPYTHON` comments**. Look for:
- `# XXX: RUSTPYTHON` or `# XXX RUSTPYTHON` - Comments marking RustPython-specific code modifications
- `# TODO: RUSTPYTHON` - Comments marking tests that need work
- Code changes with inline `# ... RUSTPYTHON` comments
- **Do NOT restore other diff changes** - these are likely upstream CPython changes, not RustPython-specific modifications
- When restoring, preserve the original context and formatting
3. **Investigate test failures with subagent**
- First, get dependent tests using the deps command:
```
cargo run --release -- scripts/update_lib deps $ARGUMENTS
```
- Look for the line `- [ ] $ARGUMENTS: test_xxx test_yyy ...` to get the direct dependent tests
- Run those tests to collect failures:
```
cargo run --release -- -m test test_xxx test_yyy ... 2>&1 | grep -E "^(FAIL|ERROR):"
```
- For example, if deps output shows `- [ ] linecache: test_bdb test_inspect test_linecache test_traceback test_zipimport`, run:
```
cargo run --release -- -m test test_bdb test_inspect test_linecache test_traceback test_zipimport 2>&1 | grep -E "^(FAIL|ERROR):"
```
- For each failure, use the Task tool with `general-purpose` subagent to investigate:
- Subagent should follow the `/investigate-test-failure` skill workflow
- Pass the failed test identifier as the argument (e.g., `test_inspect.TestGetSourceBase.test_getsource_reload`)
- If subagent can fix the issue easily: fix and commit
- If complex issue: subagent collects issue info and reports back (issue creation on user request only)
- Using subagent prevents context pollution in the main conversation
4. **Mark remaining test failures with auto-mark**
- Run: `python3 scripts/update_lib auto-mark Lib/test/test_$ARGUMENTS.py --mark-failure`
- Or for directory: `python3 scripts/update_lib auto-mark Lib/test/test_$ARGUMENTS/ --mark-failure`
- This will:
- Run tests and mark ALL failing tests with `@unittest.expectedFailure`
- Remove `@unittest.expectedFailure` from tests that now pass
- **Note**: The `--mark-failure` flag marks all failures including regressions. Review the changes before committing.
5. **Handle panics manually**
- If any tests cause panics/crashes (not just assertion failures), they need `@unittest.skip` instead:
```python
@unittest.skip("TODO: RUSTPYTHON; panics with 'index out of bounds'")
def test_crashes(self):
...
```
- auto-mark cannot detect panics automatically - check the test output for crash messages
6. **Handle class-specific failures**
- If a test fails only in the C implementation (TestCFoo) but passes in the Python implementation (TestPyFoo), or vice versa, move the marker to the specific subclass:
```python
# Base class - no marker here
class TestFoo:
def test_something(self):
...
class TestPyFoo(TestFoo, PyTest): pass
class TestCFoo(TestFoo, CTest):
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_something(self):
return super().test_something()
```
7. **Commit the test fixes**
- Run: `git add -u && git commit -m "Mark failing tests"`
- This creates a separate commit for the test markers added in steps 2-6
## Example Usage
```
# Using module names (recommended)
/upgrade-pylib inspect
/upgrade-pylib json
/upgrade-pylib asyncio
# Using library paths (alternative)
/upgrade-pylib cpython/Lib/inspect.py
/upgrade-pylib cpython/Lib/json/
```
## Example: Restoring RUSTPYTHON changes
When git diff shows removed RUSTPYTHON-specific code like:
```diff
-# XXX RUSTPYTHON: we don't import _json as fresh since...
-cjson = import_helper.import_fresh_module('json') #, fresh=['_json'])
+cjson = import_helper.import_fresh_module('json', fresh=['_json'])
```
You should restore the RustPython version:
```python
# XXX RUSTPYTHON: we don't import _json as fresh since...
cjson = import_helper.import_fresh_module('json') #, fresh=['_json'])
```
## Notes
- The cpython/ directory should contain the CPython source that we're syncing from
- `scripts/update_lib` package handles patching and auto-marking:
- `quick` - Combined patch + auto-mark (recommended)
- `migrate` - Only migrate (patch), no test running
- `auto-mark` - Only run tests and mark failures
- `copy-lib` - Copy library files (not tests)
- The patching:
- Transfers `@unittest.expectedFailure` and `@unittest.skip` decorators with `TODO: RUSTPYTHON` markers
- Adds `import unittest # XXX: RUSTPYTHON` if needed for the decorators
- **Limitation**: If a class was restructured (e.g., method overrides removed), update_lib will warn and skip those markers
- The smart auto-mark:
- Marks NEW test failures automatically (tests that didn't exist before)
- Does NOT mark regressions (existing tests that now fail) - these are warnings
- Removes `@unittest.expectedFailure` from tests that now pass
- The script does NOT preserve all RustPython-specific changes - you must review `git diff` and restore them
- Common RustPython markers to look for:
- `# XXX: RUSTPYTHON` or `# XXX RUSTPYTHON` - Inline comments for code modifications
- `# TODO: RUSTPYTHON` - Test skip/failure markers
- Any code with `RUSTPYTHON` in comments that was removed in the diff
- **Important**: Not all changes in the git diff need to be restored. Only restore changes that have explicit `RUSTPYTHON` comments. Other changes are upstream CPython updates.

50
.claude/scripts/setup-env.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
# Claude Code web session startup script
# Sets up the development environment for RustPython
set -e
cd /home/user/RustPython
echo "=== RustPython dev environment setup ==="
# 1. Ensure python3 points to 3.13+ (needed for scripts/update_lib)
# /usr/local/bin takes precedence over /usr/bin in PATH,
# so we update the symlink there directly.
CURRENT_PY=$(python3 --version 2>&1 | grep -oP '\d+\.\d+')
if [ "$(printf '%s\n' "3.13" "$CURRENT_PY" | sort -V | head -1)" != "3.13" ]; then
echo "Upgrading python3 default to 3.13..."
# Find best available Python >= 3.13
TARGET=""
for ver in python3.14 python3.13; do
if command -v "$ver" &>/dev/null; then
TARGET=$(command -v "$ver")
break
fi
done
if [ -n "$TARGET" ]; then
# Override /usr/local/bin/python3 if it exists and is outdated
if [ -e /usr/local/bin/python3 ]; then
sudo ln -sf "$TARGET" /usr/local/bin/python3
fi
# Also set /usr/bin via update-alternatives
sudo update-alternatives --install /usr/bin/python3 python3 "$TARGET" 3 2>/dev/null || true
sudo update-alternatives --set python3 "$TARGET" 2>/dev/null || true
echo "python3 now: $(python3 --version)"
else
echo "WARNING: No Python 3.13+ found. scripts/update_lib may not work."
fi
else
echo "python3 already >= 3.13: $(python3 --version)"
fi
# 2. Clone CPython source if not present (needed for scripts/update_lib)
if [ ! -d "cpython" ]; then
echo "Cloning CPython v3.14.3 (shallow)..."
git clone --depth 1 --branch v3.14.3 https://github.com/python/cpython.git cpython
echo "CPython source ready."
else
echo "CPython source already present."
fi
echo "=== Setup complete ==="

15
.claude/settings.json Normal file
View File

@@ -0,0 +1,15 @@
{
"hooks": {
"SessionStart": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "bash .claude/scripts/setup-env.sh"
}
]
}
]
}
}

3
.coderabbit.yml Normal file
View File

@@ -0,0 +1,3 @@
reviews:
path_filters:
- "!Lib/**"

273
.cspell.dict/cpython.txt Normal file
View File

@@ -0,0 +1,273 @@
ADDOP
aftersign
argdefs
argtypes
asdl
asname
atopen
atext
attro
augassign
badcert
badsyntax
baseinfo
basetype
binop
bltin
boolop
BUFMAX
BUILDSTDLIB
bxor
byteswap
cached_tsver
cadata
cafile
calldepth
callinfo
callproc
capath
carg
cellarg
cellvar
cellvars
ceval
cfield
cfws
CFWS
CLASSDEREF
classdict
cmpop
CNOTAB
codedepth
CODEUNIT
CONIN
CONOUT
constevaluator
consti
CONVFUNC
convparam
copyslot
cpucount
datastack
defaultdict
denom
deopt
deopts
dictbytype
DICTFLAG
dictoffset
distpoint
dynload
elts
eooh
eofs
EOOH
evalloop
excepthandler
exceptiontable
fastlocal
fastlocals
fblock
fblocks
fdescr
fdst
ffi_argtypes
fielddesc
fieldlist
fileutils
finalbody
finalizers
firsttraceable
flowgraph
formatfloat
freelist
freevar
freevars
fromlist
fsrc
getdict
getfunc
getiter
getsets
getslice
globalgetvar
HASARRAY
HASBITFIELD
HASPOINTER
HASSTRUCT
HASUNION
heaptype
hexdigit
HIGHRES
ialloc
IFUNC
IMMUTABLETYPE
INCREF
inlinedepth
inplace
inpos
ioffset
isbytecode
ishidden
ismine
ISPOINTER
isoctal
iteminfo
Itertool
iused
keeped
kwnames
kwonlyarg
kwonlyargs
kwonlydefaults
lasti
libffi
linearise
lineful
lineiterator
linetable
LNOTAB
loadfast
localsplus
localspluskinds
Lshift
lslpp
lsprof
MAXBLOCKS
maxdepth
metavars
miscompiles
mult
multibytecodec
nameobj
nameop
nargsf
nblocks
ncells
ncellsused
ncellvars
nconsts
newargs
newfree
NEWLOCALS
newsemlockobject
nextop
nfrees
nkwargs
nkwelts
nlocalsplus
nointerrupt
noffsets
Nondescriptor
noninteger
nops
noraise
nseen
NSIGNALS
numer
nvars
opname
opnames
orelse
outparam
outparm
paramfunc
parg
pathconfig
patma
peepholer
phcount
platstdlib
ploc
posonlyarg
posonlyargs
prec
preds
preinitialized
pybuilddir
pycore
pyinner
pydecimal
pyerrors
Pyfunc
pylifecycle
pymain
pyrepl
pystate
PYTHONTRACEMALLOC
PYTHONUTF8
pythonw
PYTHREAD_NAME
releasebuffer
repr
resinfo
retarget
Rshift
SA_ONSTACK
saveall
scls
setdict
setfunc
setprofileallthreads
SETREF
setresult
setslice
settraceallthreads
sget
SLOTDEFINED
SMALLBUF
SOABI
SSLEOF
stackdepth
stackref
staticbase
stginfo
storefast
stringlib
stringized
structseq
subkwargs
subparams
subscr
sval
swappedbytes
swaptimize
sysdict
tbstderr
templatelib
testconsole
threadstate
ticketer
tmptype
tok_oldval
tstate
tvars
typeobject
typeparam
Typeparam
typeparams
typeslots
unaryop
uncollectable
Unhandle
unparse
unparser
untargeted
untracking
VARKEYWORDS
varkwarg
venvlauncher
venvlaunchert
venvw
venvwlauncher
venvwlaunchert
wbits
weakreflist
weakrefobject
webpki
winconsoleio
withitem
withs
worklist
xstat
XXPRIME

View File

@@ -0,0 +1,307 @@
abiflags
abstractmethods
addcompare
aenter
aexit
aiter
altzone
anext
anextawaitable
annotationlib
appendleft
argcount
arrayiterator
arraytype
asend
asyncgen
athrow
backslashreplace
baserepl
basicsize
bdfl
bigcharset
bignum
bivariant
breakpointhook
cformat
chunksize
classcell
classmethods
closefd
closesocket
codepoint
codepoints
codesize
contextvar
cpython
cratio
ctype
ctypes
dealloc
debugbuild
decompressor
defaultaction
descr
dictcomp
dictitems
dictkeys
dictview
digestmod
dllhandle
docstring
docstrings
dunder
endianness
endpos
eventmask
excepthook
exceptiongroup
exitfuncs
extendleft
fastlocals
fdel
fedcba
fget
fileencoding
fillchar
fillvalue
finallyhandler
firstiter
fobj
firstlineno
fnctl
frombytes
fromhex
fromunicode
frozensets
fset
fspath
fstring
fstrings
ftruncate
genexpr
genexpressions
getargs
getattro
getcodesize
getdefaultencoding
getfilesystemencodeerrors
getfilesystemencoding
getformat
getframe
getframemodulename
getnewargs
getopt
getpip
getrandom
getrecursionlimit
getrefcount
getsizeof
getswitchinterval
getweakref
getweakrefcount
getweakrefs
getweakrefs
getwindowsversion
gmtoff
groupdict
groupindex
hamt
hostnames
idfunc
idiv
idxs
impls
infd
indexgroup
infj
inittab
Inittab
instancecheck
instanceof
instrs
interpchannels
interpqueues
irepeat
isabstractmethod
isbytes
iscased
isfinal
istext
itemiterator
itemsize
iternext
keepends
keyfunc
keyiterator
kwarg
kwargs
kwdefaults
kwonlyargcount
lastgroup
lastindex
linearization
linearize
listcomp
longrange
lvalue
mappingproxy
markupbase
maskpri
maxdigits
MAXGROUPS
MAXREPEAT
maxsplit
maxunicode
memoryview
memoryviewiterator
metaclass
metaclasses
metatype
mformat
mro
mros
multiarch
mymodule
namereplace
nanj
nbytes
ncallbacks
ndigits
ndim
needsfree
nldecoder
nlocals
NOARGS
nonbytes
Nonprintable
onceregistry
origname
ospath
outfd
pendingcr
phello
platlibdir
popleft
posixsubprocess
posonly
posonlyargcount
prepending
profilefunc
pycache
pycapsule
pycodecs
pycs
pydatetime
pyexpat
PYGILSTATE
pyio
pymain
PYTHONAPI
PYTHONBREAKPOINT
PYTHONDEBUG
PYTHONDONTWRITEBYTECODE
PYTHONFAULTHANDLER
PYTHONHASHSEED
PYTHONHOME
PYTHONINSPECT
PYTHONINTMAXSTRDIGITS
PYTHONIOENCODING
PYTHONNODEBUGRANGES
PYTHONNOUSERSITE
PYTHONOPTIMIZE
PYTHONPATH
PYTHONPATH
PYTHONSAFEPATH
PYTHONUNBUFFERED
PYTHONVERBOSE
PYTHONWARNDEFAULTENCODING
PYTHONWARNINGS
pytraverse
PYVENV
qualname
quotetabs
radd
rdiv
rdivmod
readall
readbuffer
reconstructor
refcnt
releaselevel
reraised
reverseitemiterator
reverseiterator
reversekeyiterator
reversevalueiterator
rfloordiv
rlshift
rmod
rpow
rrshift
rsub
rtruediv
rvalue
scproxy
seennl
setattro
setcomp
setprofileallthreads
setrecursionlimit
setswitchinterval
settraceallthreads
showwarnmsg
signum
sitebuiltins
slotnames
STACKLESS
stacklevel
stacksize
startpos
subclassable
subclasscheck
subclasshook
subclassing
suboffset
suboffsets
SUBPATTERN
subpatterns
sumprod
surrogateescape
surrogatepass
sysconf
sysconfigdata
sysdict
sysvars
teedata
thisclass
titlecased
tkapp
tobytes
tolist
toreadonly
TPFLAGS
tracefunc
unimportable
unionable
unraisablehook
unsliceable
urandom
valueiterator
vararg
varargs
varnames
warningregistry
warnmsg
warnoptions
warnopts
weaklist
weakproxy
weakrefs
weakrefset
winver
withdata
xmlcharrefreplace
xoptions
xopts
yieldfrom

View File

@@ -0,0 +1,94 @@
ahash
arrayvec
bidi
biguint
bindgen
bitand
bitflags
bitflagset
bitor
bitvec
bitxor
bstr
byteorder
byteset
caseless
chrono
consts
cranelift
cstring
datelike
deserializer
deserializers
fdiv
flamescope
flate2
fract
getres
hasher
hexf
hexversion
idents
illumos
ilog
indexmap
insta
keccak
lalrpop
lexopt
libc
libcall
libloading
libz
longlong
Manually
maplit
memmap
memmem
metas
modpow
msvc
muldiv
nanos
nonoverlapping
objclass
peekable
pemfile
powc
powf
powi
prepended
punct
replacen
retag
rmatch
rposition
rsplitn
rustc
rustfmt
rustls
rustyline
seedable
seekfrom
siphash
siphasher
splitn
subsec
thiserror
timelike
timsort
trai
ulonglong
unic
unistd
unraw
unsync
wasip1
wasip2
wasmbind
wasmer
wasmtime
widestring
winapi
winresource
winsock

View File

@@ -0,0 +1,32 @@
cfgs
miri
py
pyarg
pyargs
pyast
pyattr
pyclass
pyclassmethod
pyexception
pyfunction
pygetset
pyimpl
pylib
pymath
pymethod
pymodule
pyname
pyobj
pyobject
pypayload
pyref
pyslot
pystaticmethod
pystone
pystr
pystruct
pystructseq
pytype
rustix
struc
zelf

View File

@@ -1,287 +1,103 @@
// See: https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell
{
"version": "0.2",
"import": [
"@cspell/dict-en_us/cspell-ext.json",
// "@cspell/dict-cpp/cspell-ext.json",
"@cspell/dict-python/cspell-ext.json",
"@cspell/dict-rust/cspell-ext.json",
"@cspell/dict-win32/cspell-ext.json",
"@cspell/dict-shell/cspell-ext.json",
],
"allowCompoundWords": true,
// language - current active spelling language
"language": "en",
// dictionaries - list of the names of the dictionaries to use
"dictionaries": [
"cpython", // Sometimes keeping same terms with cpython is easy
"python-more", // Python API terms not listed in python
"rust-more", // Rust API terms not listed in rust
"rustpython", // RustPython derive macros and internal terms
"en_US",
"softwareTerms",
"c",
"cpp",
"python",
"python-custom",
"rust",
"unix",
"posix",
"winapi"
"shell",
"win32"
],
// dictionaryDefinitions - this list defines any custom dictionaries to use
"dictionaryDefinitions": [],
"dictionaryDefinitions": [
{
"name": "cpython",
"path": "./.cspell.dict/cpython.txt"
},
{
"name": "python-more",
"path": "./.cspell.dict/python-more.txt"
},
{
"name": "rust-more",
"path": "./.cspell.dict/rust-more.txt"
},
{
"name": "rustpython",
"path": "./.cspell.dict/rustpython.txt"
}
],
"ignorePaths": [
"**/__pycache__/**",
"Lib/**"
"target/**",
"Lib/**",
"crates/host_env/**"
],
// words - list of words to be always considered correct
// (compound words like pyarg, baseclass, microbenchmark are handled by allowCompoundWords)
"words": [
// Rust
"ahash",
"bidi",
"biguint",
"bindgen",
"bitflags",
"bstr",
"byteorder",
"chrono",
"consts",
"cstring",
"flate2",
"fract",
"hasher",
"idents",
"indexmap",
"insta",
"keccak",
"lalrpop",
"libc",
"libz",
"longlong",
"Manually",
"maplit",
"memmap",
"metas",
"modpow",
"nanos",
"peekable",
"powc",
"powf",
"prepended",
"punct",
"replacen",
"rsplitn",
"rustc",
"rustfmt",
"seekfrom",
"splitn",
"subsec",
"timsort",
"trai",
"ulonglong",
"unic",
"unistd",
"winapi",
"winsock",
// Python
"abstractmethods",
"aiter",
"anext",
"arrayiterator",
"arraytype",
"asend",
"athrow",
"basicsize",
"cformat",
"classcell",
"closesocket",
"codepoint",
"codepoints",
"cpython",
"decompressor",
"defaultaction",
"descr",
"dictcomp",
"dictitems",
"dictkeys",
"dictview",
"docstring",
"docstrings",
"dunder",
"eventmask",
"fdel",
"fget",
"fileencoding",
"fillchar",
"finallyhandler",
"frombytes",
"fromhex",
"fromunicode",
"fset",
"fspath",
"fstring",
"fstrings",
"genexpr",
"getattro",
"getformat",
"getnewargs",
"getweakrefcount",
"getweakrefs",
"hostnames",
"idiv",
"impls",
"infj",
"instancecheck",
"instanceof",
"isabstractmethod",
"itemiterator",
"itemsize",
"iternext",
"keyiterator",
"kwarg",
"kwargs",
"linearization",
"linearize",
"listcomp",
"mappingproxy",
"maxsplit",
"memoryview",
"memoryviewiterator",
"metaclass",
"metaclasses",
"metatype",
"mro",
"mros",
"nanj",
"ndigits",
"ndim",
"nonbytes",
"origname",
"posixsubprocess",
"pyexpat",
"PYTHONDEBUG",
"PYTHONHOME",
"PYTHONINSPECT",
"PYTHONOPTIMIZE",
"PYTHONPATH",
"PYTHONPATH",
"PYTHONVERBOSE",
"PYTHONWARNINGS",
"qualname",
"radd",
"rdiv",
"rdivmod",
"reconstructor",
"reversevalueiterator",
"rfloordiv",
"rlshift",
"rmod",
"rpow",
"rrshift",
"rsub",
"rtruediv",
"scproxy",
"setattro",
"setcomp",
"showwarnmsg",
"warnmsg",
"stacklevel",
"subclasscheck",
"subclasshook",
"unionable",
"unraisablehook",
"valueiterator",
"vararg",
"varargs",
"varnames",
"warningregistry",
"warnopts",
"weakproxy",
"xopts",
// RustPython
"baseclass",
"Bytecode",
"cfgs",
"codegen",
"aiterable",
"alnum",
"csock",
"coro",
"dedentations",
"dedents",
"deduped",
"downcasted",
"dumpable",
"GetSet",
"internable",
"makeunicodedata",
"miri",
"notrace",
"pyarg",
"pyarg",
"pyargs",
"PyAttr",
"deoptimized",
"deoptimize",
"emscripten",
"excs",
"fnfe",
"ifexp",
"interps",
"jitted",
"jitting",
"kwonly",
"lossily",
"mcache",
"oparg",
"opargs",
"pyc",
"PyClass",
"PyClassMethod",
"PyException",
"PyFunction",
"pygetset",
"pyimpl",
"pymember",
"PyMethod",
"PyModule",
"pyname",
"pyobj",
"PyObject",
"pypayload",
"PyProperty",
"pyref",
"PyResult",
"pyslot",
"PyStaticMethod",
"pystr",
"pystruct",
"pystructseq",
"pytrace",
"reducelib",
"richcompare",
"RustPython",
"struc",
"tracebacks",
"typealiases",
"Unconstructible",
"unhashable",
"uninit",
"reborrow",
"reraises",
"reraising",
"significand",
"summands",
"TESTFN",
"TZPATH",
"unraisable",
"wasi",
"zelf",
// cpython
"argtypes",
"asdl",
"asname",
"augassign",
"badsyntax",
"basetype",
"boolop",
"bxor",
"cellarg",
"cellvar",
"cellvars",
"cmpop",
"dictoffset",
"elts",
"excepthandler",
"finalbody",
"freevar",
"freevars",
"fromlist",
"heaptype",
"IMMUTABLETYPE",
"kwonlyarg",
"kwonlyargs",
"linearise",
"maxdepth",
"mult",
"nkwargs",
"orelse",
"patma",
"posonlyarg",
"posonlyargs",
"prec",
"stackdepth",
"unaryop",
"unparse",
"unparser",
"VARKEYWORDS",
"varkwarg",
"wbits",
"withitem",
"withs"
"weaked",
// unix
"posixshmem",
"shm",
"CLOEXEC",
"endgrent",
"gethrvtime",
"getrusage",
"sigaction",
"WRLCK",
// win32
"IFEXEC"
],
// flagWords - list of words to be always considered incorrect
"flagWords": [

6
.devcontainer/Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM rust:bullseye
# Install clang
RUN apt-get update \
&& apt-get install -y clang \
&& rm -rf /var/lib/apt/lists/*

View File

@@ -1,6 +1,25 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/devcontainers/features/rust:1": {}
}
"name": "Rust",
"build": {
"dockerfile": "Dockerfile"
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
"customizations": {
"vscode": {
"settings": {
"lldb.executable": "/usr/bin/lldb",
// VS Code don't watch files under ./target
"files.watcherExclude": {
"**/target/**": true
},
"extensions": [
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"vadimcn.vscode-lldb",
"mutantdino.resourcemonitor"
]
}
}
},
"remoteUser": "vscode"
}

2
.gemini/config.yaml Normal file
View File

@@ -0,0 +1,2 @@
ignore_patterns:
- "Lib/**"

67
.gitattributes vendored
View File

@@ -1,6 +1,71 @@
Lib/** linguist-vendored
Cargo.lock linguist-generated -merge
Cargo.lock linguist-generated
*.snap linguist-generated -merge
vm/src/stdlib/ast/gen.rs linguist-generated -merge
Lib/*.py text working-tree-encoding=UTF-8 eol=LF
**/*.rs text working-tree-encoding=UTF-8 eol=LF
crates/rustpython_doc_db/src/*.inc.rs linguist-generated=true
# Binary data types
*.aif binary
*.aifc binary
*.aiff binary
*.au binary
*.bmp binary
*.exe binary
*.icns binary
*.gif binary
*.ico binary
*.jpg binary
*.pck binary
*.pdf binary
*.png binary
*.psd binary
*.tar binary
*.wav binary
*.whl binary
*.zip binary
# Text files that should not be subject to eol conversion
[attr]noeol -text
Lib/test/cjkencodings/* noeol
Lib/test/tokenizedata/coding20731.py noeol
Lib/test/decimaltestdata/*.decTest noeol
Lib/test/test_email/data/*.txt noeol
Lib/test/xmltestdata/* noeol
# Shell scripts should have LF even on Windows because of Cygwin
Lib/venv/scripts/common/activate text eol=lf
Lib/venv/scripts/posix/* text eol=lf
# CRLF files
[attr]dos text eol=crlf
# Language aware diff headers
# https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more
# https://gist.github.com/tekin/12500956bd56784728e490d8cef9cb81
*.css diff=css
*.html diff=html
*.py diff=python
*.md diff=markdown
# Generated files
# https://github.com/github/linguist/blob/master/docs/overrides.md
#
# To always hide generated files in local diffs, mark them as binary:
# $ git config diff.generated.binary true
#
[attr]generated linguist-generated=true diff=generated
Lib/_opcode_metadata.py generated
Lib/keyword.py generated
Lib/idlelib/help.html generated
Lib/test/certdata/*.pem generated
Lib/test/certdata/*.0 generated
Lib/test/levenshtein_examples.json generated
Lib/test/test_stable_abi_ctypes.py generated
Lib/token.py generated
crates/compiler-core/src/bytecode/opcode_metadata.rs generated
.github/workflows/*.lock.yml linguist-generated=true merge=ours

View File

@@ -0,0 +1,49 @@
# This action installs a few dependencies necessary to build RustPython on Linux.
# It can be configured depending on which libraries are needed:
#
# ```
# - uses: ./.github/actions/install-linux-deps
# with:
# gcc-multilib: true
# musl-tools: false
# ```
#
# See the `inputs` section for all options and their defaults. Note that you must checkout the
# repository before you can use this action.
#
# This action will only install dependencies when the current operating system is Linux. It will do
# nothing on any other OS (macOS, Windows).
name: Install Linux dependencies
description: Installs the dependencies necessary to build RustPython on Linux.
inputs:
gcc-multilib:
description: Install gcc-multilib (gcc-multilib)
required: false
default: "false"
musl-tools:
description: Install musl-tools (musl-tools)
required: false
default: "false"
gcc-aarch64-linux-gnu:
description: Install gcc-aarch64-linux-gnu (gcc-aarch64-linux-gnu)
required: false
default: "false"
clang:
description: Install clang (clang)
required: false
default: "false"
runs:
using: composite
steps:
- name: Install Linux dependencies
shell: bash
if: ${{ runner.os == 'Linux' }}
run: >
sudo apt-get update
sudo apt-get install --no-install-recommends
${{ fromJSON(inputs.gcc-multilib) && 'gcc-multilib' || '' }}
${{ fromJSON(inputs.musl-tools) && 'musl-tools' || '' }}
${{ fromJSON(inputs.clang) && 'clang' || '' }}
${{ fromJSON(inputs.gcc-aarch64-linux-gnu) && 'gcc-aarch64-linux-gnu linux-libc-dev-arm64-cross libc6-dev-arm64-cross' || '' }}

View File

@@ -0,0 +1,47 @@
# This action installs a few dependencies necessary to build RustPython on macOS. By default it installs
# autoconf, automake and libtool, but can be configured depending on which libraries are needed:
#
# ```
# - uses: ./.github/actions/install-macos-deps
# with:
# openssl: true
# libtool: false
# ```
#
# See the `inputs` section for all options and their defaults. Note that you must checkout the
# repository before you can use this action.
#
# This action will only install dependencies when the current operating system is macOS. It will do
# nothing on any other OS (Linux, Windows).
name: Install macOS dependencies
description: Installs the dependencies necessary to build RustPython on macOS.
inputs:
autoconf:
description: Install autoconf (autoconf)
required: false
default: "true"
automake:
description: Install automake (automake)
required: false
default: "true"
libtool:
description: Install libtool (libtool)
required: false
default: "true"
openssl:
description: Install openssl (openssl@3)
required: false
default: "false"
runs:
using: composite
steps:
- name: Install macOS dependencies
shell: bash
if: ${{ runner.os == 'macOS' }}
run: >
brew install
${{ fromJSON(inputs.autoconf) && 'autoconf' || '' }}
${{ fromJSON(inputs.automake) && 'automake' || '' }}
${{ fromJSON(inputs.libtool) && 'libtool' || '' }}
${{ fromJSON(inputs.openssl) && 'openssl@3' || '' }}

14
.github/aw/actions-lock.json vendored Normal file
View File

@@ -0,0 +1,14 @@
{
"entries": {
"actions/github-script@v8": {
"repo": "actions/github-script",
"version": "v8",
"sha": "ed597411d8f924073f98dfc5c65a23a2325f34cd"
},
"github/gh-aw/actions/setup@v0.43.22": {
"repo": "github/gh-aw/actions/setup",
"version": "v0.43.22",
"sha": "fe858c3e14589bf396594a0b106e634d9065823e"
}
}
}

175
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,175 @@
# cspell:ignore manyhow tinyvec zeroize
version: 2
updates:
- package-ecosystem: cargo
directories:
- "/"
- "crates/*"
schedule:
interval: weekly
cooldown:
default-days: 7
semver-major-days: 30
semver-minor-days: 7
semver-patch-days: 3
groups:
criterion:
patterns:
- "criterion*"
crypto:
patterns:
- "digest"
- "md-5"
- "sha-1"
- "sha1"
- "sha2"
- "sha3"
- "blake2"
- "hmac"
- "pbkdf2"
futures:
patterns:
- "futures*"
get-size2:
patterns:
- "get-size*2"
iana-time-zone:
patterns:
- "iana-time-zone*"
jiff:
patterns:
- "jiff*"
lexical:
patterns:
- "lexical*"
libffi:
patterns:
- "libffi*"
malachite:
patterns:
- "malachite*"
manyhow:
patterns:
- "manyhow*"
num:
patterns:
- "num-bigint"
- "num-complex"
- "num-integer"
- "num-iter"
- "num-rational"
- "num-traits"
num_enum:
patterns:
- "num_enum*"
openssl:
patterns:
- "openssl*"
parking_lot:
patterns:
- "parking_lot*"
phf:
patterns:
- "phf*"
plotters:
patterns:
- "plotters*"
portable-atomic:
patterns:
- "portable-atomic*"
pyo3:
patterns:
- "pyo3*"
quote-use:
patterns:
- "quote-use*"
random:
patterns:
- "getrandom"
- "mt19937"
- "rand*"
rayon:
patterns:
- "rayon*"
regex:
patterns:
- "regex*"
result-like:
patterns:
- "result-like*"
security-framework:
patterns:
- "security-framework*"
serde:
patterns:
- "serde"
- "serde_core"
- "serde_derive"
system-configuration:
patterns:
- "system-configuration*"
thiserror:
patterns:
- "thiserror*"
time:
patterns:
- "time*"
tinyvec:
patterns:
- "tinyvec*"
tls_codec:
patterns:
- "tls_codec*"
toml:
patterns:
- "toml*"
unix:
patterns:
- "mac_address"
- "nix"
- "rustyline"
wasm-bindgen:
patterns:
- "wasm-bindgen*"
wasmtime:
patterns:
- "cranelift*"
- "wasmtime*"
webpki-root:
patterns:
- "webpki-root*"
windows:
patterns:
- "windows*"
zerocopy:
patterns:
- "zerocopy*"
zeroize:
patterns:
- "zeroize*"
ignore:
# TODO: Remove when we use ruff from crates.io
# for some reason dependabot only updates the Cargo.lock file when dealing
# with git dependencies. i.e. not updating the version in Cargo.toml
- dependency-name: "ruff_*"
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
semver-major-days: 30
semver-minor-days: 7
semver-patch-days: 3
- package-ecosystem: pre-commit
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7

File diff suppressed because it is too large Load Diff

23
.github/workflows/comment-commands.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: Comment Commands
on:
issue_comment:
types: created
jobs:
issue_assign:
if: (!github.event.issue.pull_request) && github.event.comment.body == 'take'
runs-on: ubuntu-slim
concurrency:
group: ${{ github.actor }}-issue-assign
permissions:
issues: write
steps:
# Using REST API and not `gh issue edit`. https://github.com/cli/cli/issues/6235#issuecomment-1243487651
- run: |
curl -H "Authorization: token ${{ github.token }}" -d '{"assignees": ["${{ env.USER }}"]}' https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees
env:
USER: ${{ github.event.comment.user.login }}

View File

@@ -1,13 +1,21 @@
on:
schedule:
- cron: '0 0 * * 6'
workflow_dispatch:
name: Periodic checks/tasks
on:
schedule:
- cron: "0 0 * * 6"
workflow_dispatch:
push:
paths:
- .github/workflows/cron-ci.yaml
branches:
- main
pull_request:
paths:
- .github/workflows/cron-ci.yaml
env:
CARGO_ARGS: --no-default-features --features stdlib,zlib,importlib,encodings,ssl,jit
PYTHON_VERSION: "3.12.0"
CARGO_ARGS: --no-default-features --features stdlib,importlib,stdio,encodings,ssl-rustls-aws-lc,jit,host_env
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true' # TODO: Remove on 2026/06/02
jobs:
# codecov collects code coverage data from the rust tests, python snippets and python test suite.
@@ -15,42 +23,65 @@ jobs:
codecov:
name: Collect code coverage data
runs-on: ubuntu-latest
# Disable this scheduled job when running on a fork.
if: ${{ github.repository == 'RustPython/RustPython' || github.event_name != 'schedule' }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: actions/setup-python@v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
python-version: ${{ env.PYTHON_VERSION }}
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@b550161ef8a7bc4f2a671c0b03a18ac9ccedea1e # v2.79.1
with:
tool: cargo-llvm-cov
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
- run: sudo apt-get update && sudo apt-get -y install lcov
- name: Run cargo-llvm-cov with Rust tests.
run: cargo llvm-cov --no-report --workspace --exclude rustpython_wasm --verbose --no-default-features --features stdlib,zlib,importlib,encodings,ssl,jit
run: cargo llvm-cov --no-report --workspace --exclude rustpython_wasm --exclude rustpython-compiler-source --exclude rustpython-venvlauncher --verbose --no-default-features --features stdlib,importlib,stdio,encodings,ssl-rustls-aws-lc,jit,host_env
- name: Run cargo-llvm-cov with Python snippets.
run: python scripts/cargo-llvm-cov.py
continue-on-error: true
- name: Run cargo-llvm-cov with Python test suite.
run: cargo llvm-cov --no-report run -- -m test -u all --slowest --fail-env-changed
run: cargo llvm-cov --no-report run -- -m test -u all --slowest --fail-env-changed
continue-on-error: true
- name: Prepare code coverage data
run: cargo llvm-cov report --lcov --output-path='codecov.lcov'
- name: Upload to Codecov
uses: codecov/codecov-action@v3
if: ${{ github.event_name != 'pull_request' }}
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
file: ./codecov.lcov
files: ./codecov.lcov
testdata:
name: Collect regression test data
runs-on: ubuntu-latest
# Disable this scheduled job when running on a fork.
if: ${{ github.repository == 'RustPython/RustPython' || github.event_name != 'schedule' }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: true
- uses: dtolnay/rust-toolchain@stable
- name: build rustpython
run: cargo build --release --verbose
- name: collect tests data
run: cargo run --release extra_tests/jsontests.py
env:
RUSTPYTHONPATH: ${{ github.workspace }}/Lib
- name: upload tests data to the website
if: ${{ github.event_name != 'pull_request' }}
env:
SSHKEY: ${{ secrets.ACTIONS_TESTS_DATA_DEPLOY_KEY }}
GITHUB_ACTOR: ${{ github.actor }}
@@ -70,21 +101,29 @@ jobs:
whatsleft:
name: Collect what is left data
runs-on: ubuntu-latest
# Disable this scheduled job when running on a fork.
if: ${{ github.repository == 'RustPython/RustPython' || github.event_name != 'schedule' }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-python@v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
python-version: ${{ env.PYTHON_VERSION }}
persist-credentials: true
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
- name: build rustpython
run: cargo build --release --verbose
- name: Collect what is left data
run: |
chmod +x ./whats_left.py
./whats_left.py > whats_left.temp
chmod +x ./scripts/whats_left.py
./scripts/whats_left.py --features "ssl,sqlite" > whats_left.temp
env:
RUSTPYTHONPATH: ${{ github.workspace }}/Lib
- name: Upload data to the website
if: ${{ github.event_name != 'pull_request' }}
env:
SSHKEY: ${{ secrets.ACTIONS_TESTS_DATA_DEPLOY_KEY }}
GITHUB_ACTOR: ${{ github.actor }}
@@ -97,6 +136,26 @@ jobs:
cd website
[ -f ./_data/whats_left.temp ] && cp ./_data/whats_left.temp ./_data/whats_left_lastrun.temp
cp ../whats_left.temp ./_data/whats_left.temp
rm ./_data/whats_left/modules.csv
echo -e "module" > ./_data/whats_left/modules.csv
cat ./_data/whats_left.temp | grep "(entire module)" | cut -d ' ' -f 1 | sort >> ./_data/whats_left/modules.csv
awk -f - ./_data/whats_left.temp > ./_data/whats_left/builtin_items.csv <<'EOF'
BEGIN {
OFS=","
print "builtin,name,is_inherited"
}
/^# builtin items/ { in_section=1; next }
/^$/ { if (in_section) exit }
in_section {
split($1, a, ".")
rest = ""
idx = index($0, " ")
if (idx > 0) {
rest = substr($0, idx+1)
}
print a[1], $1, rest
}
EOF
git add -A
if git -c user.name="Github Actions" -c user.email="actions@github.com" commit -m "Update what is left results" --author="$GITHUB_ACTOR"; then
git push
@@ -105,32 +164,43 @@ jobs:
benchmark:
name: Collect benchmark data
runs-on: ubuntu-latest
# Disable this scheduled job when running on a fork.
if: ${{ github.repository == 'RustPython/RustPython' || github.event_name != 'schedule' }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-python@v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
python-version: 3.9
persist-credentials: true
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
- run: cargo install cargo-criterion
- name: build benchmarks
run: cargo build --release --benches
- name: collect execution benchmark data
run: cargo criterion --bench execution
- name: collect microbenchmarks data
run: cargo criterion --bench microbenchmarks
- name: restructure generated files
run: |
cd ./target/criterion/reports
find -type d -name cpython | xargs rm -rf
find -type d -name rustpython | xargs rm -rf
find -mindepth 2 -maxdepth 2 -name violin.svg | xargs rm -rf
find -type f -not -name violin.svg | xargs rm -rf
for file in $(find -type f -name violin.svg); do mv $file $(echo $file | sed -E "s_\./([^/]+)/([^/]+)/violin\.svg_./\1/\2.svg_"); done
find -mindepth 2 -maxdepth 2 -type d | xargs rm -rf
find . -type d -name cpython -print0 | xargs -0 rm -rf
find . -type d -name rustpython -print0 | xargs -0 rm -rf
find . -mindepth 2 -maxdepth 2 -name violin.svg -print0 | xargs -0 rm -rf
find . -type f -not -name violin.svg -print0 | xargs -0 rm -rf
find . -type f -name violin.svg -exec sh -c 'for file; do mv "$file" "$(echo "$file" | sed -E "s_\./([^/]+)/([^/]+)/violin\.svg_./\1/\2.svg_")"; done' _ {} +
find . -mindepth 2 -maxdepth 2 -type d -print0 | xargs -0 rm -rf
cd ..
mv reports/* .
rmdir reports
- name: upload benchmark data to the website
if: ${{ github.event_name != 'pull_request' }}
env:
SSHKEY: ${{ secrets.ACTIONS_TESTS_DATA_DEPLOY_KEY }}
run: |
@@ -142,7 +212,11 @@ jobs:
cd website
rm -rf ./assets/criterion
cp -r ../target/criterion ./assets/criterion
git add ./assets/criterion
printf '{\n "generated_at": "%s",\n "rustpython_commit": "%s",\n "rustpython_ref": "%s"\n}\n' \
"$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
"${{ github.sha }}" \
"${{ github.ref_name }}" > ./_data/criterion-metadata.json
git add ./assets/criterion ./_data/criterion-metadata.json
if git -c user.name="Github Actions" -c user.email="actions@github.com" commit -m "Update benchmark results"; then
git push
fi

138
.github/workflows/lib-deps-check.yaml vendored Normal file
View File

@@ -0,0 +1,138 @@
name: Lib Dependencies Check
on:
pull_request_target:
types: [opened, synchronize, reopened]
paths:
- "Lib/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
check_deps:
permissions:
pull-requests: write
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout base branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# Use base branch for scripts (security: don't run PR code with elevated permissions)
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
persist-credentials: false
- name: Fetch PR head
run: |
git fetch origin ${{ github.event.pull_request.head.sha }}
- name: Checkout PR Lib files
run: |
# Checkout only Lib/ directory from PR head for accurate comparison
git checkout ${{ github.event.pull_request.head.sha }} -- Lib/
- name: Get target CPython version
id: cpython-version
run: |
version=$(cat .python-version)
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Checkout CPython
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: python/cpython
path: cpython
ref: "v${{ steps.cpython-version.outputs.version }}"
fetch-depth: 1
persist-credentials: false
- name: Get changed Lib files
id: all-changed-files
run: |
# Get the list of changed files under Lib/
{
echo 'changed<<EOF'
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- 'Lib/*.py' 'Lib/**/*.py'
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Parse changed files
id: changed-files
run: |
from os import environ
files = environ["FILES"]
modules = set()
for file in files.splitlines():
file = file.strip()
if file.startswith("Lib/test/"):
# Test files:
# Lib/test/test_pydoc.py -> test_pydoc
# Lib/test/test_pydoc/foo.py -> test_pydoc
module = file.removeprefix("Lib/test/").split("/")[0]
if not module.startswith("test_"):
continue
else:
# Lib files:
# Lib/foo.py -> foo
# Lib/foo/__init__.py -> foo
module = file.removeprefix("Lib/").split("/")[0]
module = module.split(".")[0]
modules.add(module)
print(f"{modules=}")
output = " ".join(sorted(modules))
output_file = environ["GITHUB_OUTPUT"]
with open(output_file, mode="a", encoding="utf-8") as fd:
fd.write(f"modules={output}\n")
env:
FILES: ${{ steps.all-changed-files.outputs.changed }}
shell: python
- name: Setup Python
if: steps.changed-files.outputs.modules != ''
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
- name: Run deps check
if: steps.changed-files.outputs.modules != ''
id: deps-check
run: |
# Run deps for all modules at once
echo "deps_output<<EOF" >> "$GITHUB_OUTPUT"
output=$(python scripts/update_lib deps "${MODULES}" --depth 2 2>&1 || true)
echo "$output" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
env:
MODULES: ${{ steps.changed-files.outputs.modules }}
- name: Post comment
if: steps.deps-check.outputs.deps_output != ''
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
with:
header: lib-deps-check
number: ${{ github.event.pull_request.number }}
message: |
## 📦 Library Dependencies
The following Lib/ modules were modified. Here are their dependencies:
${{ steps.deps-check.outputs.deps_output }}
**Legend:**
- `[+]` path exists in CPython
- `[x]` up-to-date, `[ ]` outdated
- name: Remove comment if no Lib changes
if: steps.changed-files.outputs.modules == ''
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
with:
header: lib-deps-check
number: ${{ github.event.pull_request.number }}
delete: true

201
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,201 @@
name: Release
on:
schedule:
# 9 AM UTC on every Monday
- cron: "0 9 * * Mon"
workflow_dispatch:
inputs:
pre-release:
type: boolean
description: Mark "Pre-Release"
required: false
default: true
env:
X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR: C:\Program Files\OpenSSL\lib\VC\x64\MD
X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR: C:\Program Files\OpenSSL\include
permissions: {}
jobs:
build:
runs-on: ${{ matrix.os }}
# Disable this scheduled job when running on a fork.
if: ${{ github.repository == 'RustPython/RustPython' || github.event_name != 'schedule' }}
permissions:
contents: read
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-2025
target: x86_64-pc-windows-msvc
# - os: ubuntu-latest
# target: i686-unknown-linux-gnu
# - os: ubuntu-latest
# target: aarch64-unknown-linux-gnu
# - os: ubuntu-latest
# target: armv7-unknown-linux-gnueabi
# - os: ubuntu-latest
# target: s390x-unknown-linux-gnu
# - os: ubuntu-latest
# target: powerpc64le-unknown-linux-gnu
# - os: macos-latest
# target: x86_64-apple-darwin
# - os: windows-2025
# target: i686-pc-windows-msvc
# - os: windows-2025
# target: aarch64-pc-windows-msvc
fail-fast: false
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
with:
target: ${{ matrix.target }}
- name: Install macOS dependencies
uses: ./.github/actions/install-macos-deps
with:
autoconf: true
automake: true
libtool: true
- name: Build RustPython
run: cargo build --release --target=${{ matrix.target }} --verbose --no-default-features --features stdlib,stdio,importlib,encodings,sqlite,host_env,ssl-rustls-aws-lc,threading,jit
- name: Rename Binary
run: cp target/${{ matrix.target }}/release/rustpython target/rustpython-release-${{ runner.os }}-${{ matrix.target }}
if: runner.os != 'Windows'
- name: Rename Binary
run: cp target/${{ matrix.target }}/release/rustpython.exe target/rustpython-release-${{ runner.os }}-${{ matrix.target }}.exe
if: runner.os == 'Windows'
- name: Upload Binary Artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: rustpython-release-${{ runner.os }}-${{ matrix.target }}
path: target/rustpython-release-${{ runner.os }}-${{ matrix.target }}*
build-wasm:
runs-on: ubuntu-latest
# Disable this scheduled job when running on a fork.
if: ${{ github.repository == 'RustPython/RustPython' || github.event_name != 'schedule' }}
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1
- name: Build RustPython
run: cargo build --target wasm32-wasip1 --no-default-features --features freeze-stdlib,stdlib --release
- name: Rename Binary
run: cp target/wasm32-wasip1/release/rustpython.wasm target/rustpython-release-wasm32-wasip1.wasm
- name: Upload Binary Artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: rustpython-release-wasm32-wasip1
path: target/rustpython-release-wasm32-wasip1.wasm
- name: install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
package-manager-cache: false
- uses: mwilliamson/setup-wabt-action@427f2fdd70bc4dbc2e53c2eb4f19f66162d71bd2 # v4.0.0
with:
wabt-version: "1.0.30"
- name: build demo
run: |
npm install
npm run dist
env:
NODE_OPTIONS: "--openssl-legacy-provider"
working-directory: ./wasm/demo
- name: build notebook demo
run: |
npm install
npm run dist
mv dist ../demo/dist/notebook
env:
NODE_OPTIONS: "--openssl-legacy-provider"
working-directory: ./wasm/notebook
- name: Deploy demo to Github Pages
if: ${{ github.repository == 'RustPython/RustPython' }}
uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4.1.0
with:
deploy_key: ${{ secrets.ACTIONS_DEMO_DEPLOY_KEY }}
publish_dir: ./wasm/demo/dist
external_repository: RustPython/demo
publish_branch: master
release:
runs-on: ubuntu-latest
# Disable this scheduled job when running on a fork.
if: ${{ github.repository == 'RustPython/RustPython' || github.event_name != 'schedule' }}
needs: [build, build-wasm]
permissions:
contents: write # for creating a release
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Download Binary Artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: bin
pattern: rustpython-*
merge-multiple: true
- name: Create Lib Archive
run: zip -r bin/rustpython-lib.zip Lib/
- name: List Binaries
run: |
ls -lah bin/
file bin/*
- name: Create Release
run: |
if [[ "${PRE_RELEASE_INPUT}" == "false" ]]; then
RELEASE_TYPE_NAME=Release
PRERELEASE_ARG=
else
RELEASE_TYPE_NAME=Pre-Release
PRERELEASE_ARG=--prerelease
fi
today=$(date '+%Y-%m-%d')
gh release create "$today-$tag-$run" \
--repo="$GITHUB_REPOSITORY" \
--title="RustPython $RELEASE_TYPE_NAME $today-$tag #$run" \
--target="$tag" \
--notes "⚠️ **Important**: To run RustPython, you must download both the binary for your platform AND the \`rustpython-lib.zip\` archive. Extract the Lib directory from the archive to the same location as the binary, or set the \`RUSTPYTHONPATH\` environment variable to point to the Lib directory." \
--generate-notes \
$PRERELEASE_ARG \
bin/rustpython-release-*
env:
GH_TOKEN: ${{ github.token }}
tag: ${{ github.ref_name }}
run: ${{ github.run_number }}
PRE_RELEASE_INPUT: ${{ github.event.inputs.pre-release }}

77
.github/workflows/update-caches.yml vendored Normal file
View File

@@ -0,0 +1,77 @@
name: Update Actions Caches
permissions:
contents: read
on:
workflow_dispatch:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
env:
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
CARGO_PROFILE_TEST_DEBUG: 0
CARGO_PROFILE_DEV_DEBUG: 0
CARGO_PROFILE_RELEASE_DEBUG: 0
CARGO_ARGS: --workspace --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env,threading,jit --exclude rustpython_wasm --exclude rustpython-compiler-source --exclude rustpython-venvlauncher
jobs:
build-caches:
name: Build Caches
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
toolchain: stable
target: ""
- os: ubuntu-latest
toolchain: stable
target: ""
- os: windows-latest
toolchain: stable
target: ""
steps:
- name: Checkout RustPython main branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: RustPython/RustPython
ref: main
persist-credentials: false
- name: Setup Rust
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
with:
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.target }}
- name: Install macos dependencies
uses: ./.github/actions/install-macos-deps
with:
openssl: true
- name: Build dev cache # dev profile used by check & doc
run: cargo build --profile dev ${{ env.CARGO_ARGS }}
- name: Build test cache
run: cargo build --profile test ${{ env.CARGO_ARGS }}
- name: Build release cache
run: cargo build --profile release ${{ env.CARGO_ARGS }}
- name: Save cache
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ matrix.toolchain }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('Cargo.lock') }}-${{ github.sha }}

125
.github/workflows/update-doc-db.yml vendored Normal file
View File

@@ -0,0 +1,125 @@
name: Update doc DB
permissions: {}
on:
workflow_dispatch:
inputs:
python-version:
description: Target python version to generate doc db for
type: string
default: "3.14.3"
base-ref:
description: Base branch to create the update branch from
type: string
default: "main"
defaults:
run:
shell: bash
jobs:
generate:
permissions:
contents: read
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
sparse-checkout: |
crates/doc
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ inputs.python-version }}
- name: Generate docs
run: python crates/doc/generate.py
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: doc-db-${{ inputs.python-version }}-${{ matrix.os }}
path: "crates/doc/generated/*.json"
if-no-files-found: error
retention-days: 7
overwrite: true
merge:
runs-on: ubuntu-latest
needs: generate
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: true
ref: ${{ inputs.base-ref }}
- name: Create update branch
run: git switch -c "update-doc-${PYTHON_VERSION}"
env:
PYTHON_VERSION: ${{ inputs.python-version }}
- name: Download generated doc DBs
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: "doc-db-${{ inputs.python-version }}-**"
path: crates/doc/generated/
merge-multiple: true
- name: Transform JSON
env:
PYTHON_VERSION: ${{ inputs.python-version }}
run: |
# Merge all artifacts
jq -s "add" --sort-keys crates/doc/generated/*.json > crates/doc/generated/merged.json
# Format merged json for the phf macro
jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' crates/doc/generated/merged.json > crates/doc/generated/raw_entries.txt
OUTPUT_FILE='crates/doc/src/data.inc.rs'
# shellcheck disable=SC2016
{
echo '// This file was auto-generated by `.github/workflows/update-doc-db.yml`.'
echo "// CPython version: ${PYTHON_VERSION}"
echo '// spell-checker: disable'
echo ''
echo "pub static DB: phf::Map<&'static str, &'static str> = phf::phf_map! {"
cat crates/doc/generated/raw_entries.txt
echo '};'
} > "$OUTPUT_FILE"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: doc-db-${{ inputs.python-version }}
path: "crates/doc/src/data.inc.rs"
if-no-files-found: error
retention-days: 7
overwrite: true
- name: Commit, push and create PR
env:
GH_TOKEN: ${{ github.token }}
PYTHON_VERSION: ${{ inputs.python-version }}
BASE_REF: ${{ inputs.base-ref }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if [ -n "$(git status --porcelain)" ]; then
git add crates/doc/src/data.inc.rs
git commit -m "Update doc DB for CPython ${PYTHON_VERSION}"
git push -u origin HEAD
gh pr create \
--base "${BASE_REF}" \
--title "Update doc DB for CPython ${PYTHON_VERSION}" \
--body "Auto-generated by update-doc-db workflow."
fi

View File

@@ -0,0 +1,96 @@
name: Updated libs status
on:
push:
branches:
- main
paths:
- "Lib/**"
workflow_dispatch:
permissions:
contents: read
issues: write
env:
ISSUE_ID: "6839"
jobs:
update-issue:
runs-on: ubuntu-latest
if: ${{ github.repository == 'RustPython/RustPython' }}
steps:
- name: Clone RustPython
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: rustpython
persist-credentials: false
sparse-checkout: |-
Lib
scripts/update_lib
.python-version
- name: Get target CPython version
id: cpython-version
run: |
version=$(cat rustpython/.python-version)
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Clone CPython
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: python/cpython
path: cpython
ref: "v${{ steps.cpython-version.outputs.version }}"
persist-credentials: false
sparse-checkout: |
Lib
- name: Get current date
id: current_date
run: |
now=$(date -u +"%Y-%m-%d %H:%M:%S")
echo "date=$now" >> "$GITHUB_OUTPUT"
- name: Write body prefix
run: |
cat > body.txt <<EOF
<!--
THIS BODY IS AUTO-GENERATED. DO NOT EDIT MANUALLY!
-->
## Summary
Check \`scripts/update_lib\` for tools. As a note, the current latest Python version is \`${{ steps.cpython-version.outputs.version }}\`.
Previous versions' issues as reference
- 3.13: #5529
<!--
Quick guideline for Copilot:
# Clone \`github.com/python/cpython\` \`${{ steps.cpython-version.outputs.version }}\` tag under RustPython working dir with depth 1 option; never 3.14.0 or 3.14.1 or 3.14.2
# Pick a library or test to update. Probably user give one.
# Run \`python3 scripts/update_lib quick <name>\`
# A commit is automatically created. push the commit.
# Do not include keywords that automatically close an issue (e.g., Fix, Close, Resolve) next to an issue link or issue number.
-->
## Details
${{ steps.current_date.outputs.date }} (UTC)
\`\`\`shell
$ python3 scripts/update_lib todo --done
\`\`\`
EOF
- name: Run todo
run: python3 rustpython/scripts/update_lib todo --cpython cpython --lib rustpython/Lib --done >> body.txt
- name: Update GH issue
run: gh issue edit ${{ env.ISSUE_ID }} --body-file ../body.txt
env:
GH_TOKEN: ${{ github.token }}
working-directory: rustpython

1095
.github/workflows/upgrade-pylib.lock.yml generated vendored Normal file

File diff suppressed because it is too large Load Diff

134
.github/workflows/upgrade-pylib.md vendored Normal file
View File

@@ -0,0 +1,134 @@
---
description: |
Pick an out-of-sync Python library from the todo list and upgrade it
by running `scripts/update_lib quick`, then open a pull request.
on:
workflow_dispatch:
inputs:
name:
description: "Module name to upgrade (leave empty to auto-pick)"
required: false
type: string
timeout-minutes: 45
permissions:
contents: read
issues: read
pull-requests: read
network:
allowed:
- defaults
- rust
- python
engine: copilot
runtimes:
python:
version: "3.14"
tools:
bash:
- ":*"
edit:
github:
toolsets: [repos, issues, pull_requests]
read-only: true
safe-outputs:
create-pull-request:
title-prefix: "Update "
labels: [pylib-sync]
draft: false
expires: 30
cache:
key: cpython-lib-${{ env.PYTHON_VERSION }}
path: cpython
restore-keys:
- cpython-lib-
env:
PYTHON_VERSION: "v3.14.4"
ISSUE_ID: "6839"
---
# Upgrade Python Library
You are an automated maintenance agent for RustPython, a Python 3 interpreter written in Rust. Your task is to upgrade one out-of-sync Python standard library module from CPython.
## Step 1: Set up the environment
The CPython source may already be cached. Check if the `cpython` directory exists and has the correct version:
```bash
if [ -d "cpython/Lib" ]; then
echo "CPython cache hit, skipping clone"
else
git clone --depth 1 --branch "$PYTHON_VERSION" https://github.com/python/cpython.git cpython
fi
```
## Step 2: Determine module name
Run this script to determine the module name:
```bash
MODULE_NAME="${{ github.event.inputs.name }}"
if [ -z "$MODULE_NAME" ]; then
echo "No module specified, running todo to find one..."
python3 scripts/update_lib todo
echo "Pick one module from the list above that is marked [ ], has no unmet deps, and has a small Δ number."
echo "Do NOT pick: opcode, datetime, random, hashlib, tokenize, pdb, _pyrepl, concurrent, asyncio, multiprocessing, ctypes, idlelib, tkinter, shutil, tarfile, email, unittest"
else
echo "Module specified by user: $MODULE_NAME"
fi
```
If the script printed "Module specified by user: ...", use that exact name. If it printed the todo list, pick one suitable module from it.
## Step 3: Run the upgrade
Run the quick upgrade command. This will copy the library from CPython, migrate test files preserving RustPython markers, auto-mark test failures, and create a git commit:
```bash
python3 scripts/update_lib quick <module_name>
```
This takes a while because it builds RustPython (`cargo build --release`) and runs tests to determine which ones pass or fail.
If the command fails, report the error and stop. Do not try to fix Rust code or modify test files manually.
## Step 4: Verify the result
After the script succeeds, check what changed:
```bash
git log -1 --stat
git diff HEAD~1 --stat
```
Make sure the commit was created with the correct message format: `Update <name> from <version>`.
## Step 5: Create the pull request
Create a pull request. Reference issue #${{ env.ISSUE_ID }} in the body but do **NOT** use keywords that auto-close issues (Fix, Close, Resolve).
Use this format for the PR body:
```
## Summary
Upgrade `<module_name>` from CPython $PYTHON_VERSION.
Part of #$ISSUE_ID
## Changes
- Updated `Lib/<module_name>` from CPython
- Migrated test files preserving RustPython markers
- Auto-marked test failures with `@expectedFailure`
```

14
.github/zizmor.yml vendored Normal file
View File

@@ -0,0 +1,14 @@
rules:
unpinned-uses:
config:
policies:
# dtolnay/rust-toolchain is a trusted action that uses lightweight branch
# refs (@stable, @nightly, etc.) by design. Pinning to a hash would break
# the intended usage pattern.
# We can remove this once https://github.com/dtolnay/rust-toolchain/issues/180 is resolved
dtolnay/rust-toolchain: any
# dtolnay/rust-toolchain handles component installation, target addition, and
# override configuration beyond what a bare `rustup` invocation provides.
# See: https://github.com/zizmorcore/zizmor/issues/1817
superfluous-actions:
disable: true

13
.gitignore vendored
View File

@@ -2,13 +2,14 @@
/*/target
**/*.rs.bk
**/*.bytecode
__pycache__
__pycache__/
**/*.pytest_cache
.*sw*
.repl_history.txt
.vscode
.vscode/
wasm-pack.log
.idea/
.envrc
flame-graph.html
flame.txt
@@ -19,3 +20,11 @@ flamescope.json
extra_tests/snippets/resources
extra_tests/not_impl.py
Lib/_sysconfig_vars*.json
Lib/site-packages/*
!Lib/site-packages/README.txt
Lib/test/data/*
!Lib/test/data/README
cpython/
.claude/scheduled_tasks.lock

84
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,84 @@
# NOTE: Reason for not using `prek.toml` is dependabot supports `pre-commit` as an ecosystem
# See: https://github.blog/changelog/2026-03-10-dependabot-now-supports-pre-commit-hooks/
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-merge-conflict
priority: 0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.12
hooks:
- id: ruff-format
priority: 0
- id: ruff-check
args: [--select, I, --fix, --exit-non-zero-on-fix]
types_or: [python]
require_serial: true
priority: 1
- repo: local
hooks:
- id: redundant-test-patches
name: check redundant test patches
entry: scripts/check_redundant_patches.py
files: '^Lib/test/.*\.py$'
language: script
types: [python]
priority: 0
- repo: local
hooks:
- id: rustfmt
name: rustfmt
entry: rustfmt
language: system
types: [rust]
priority: 0
- id: generate-rs-opcode-metadata
name: generate rust opcode metadata
entry: python tools/opcode_metadata/generate_rs_opcode_metadata.py
files: '^(crates/compiler-core/src/bytecode/instruction\.rs|tools/opcode_metadata/*)$'
pass_filenames: false
language: system
require_serial: true
priority: 1 # so rustfmt runs first
stages:
- manual
- id: generate-py-opcode-metadata
name: generate python opcode metadata
entry: python tools/opcode_metadata/generate_py_opcode_metadata.py
files: '^(crates/compiler-core/src/bytecode/instruction\.rs|tools/opcode_metadata/*)$'
pass_filenames: false
language: system
require_serial: true
priority: 1 # so rustfmt runs first
stages:
- manual
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v10.0.0
hooks:
- id: cspell
types: [rust]
additional_dependencies:
- '@cspell/dict-en_us'
- '@cspell/dict-cpp'
- '@cspell/dict-python'
- '@cspell/dict-rust'
- '@cspell/dict-win32'
- '@cspell/dict-shell'
priority: 0
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.8.3
hooks:
- id: prettier
files: '^wasm/.*$'
priority: 0

1
.python-version Normal file
View File

@@ -0,0 +1 @@
3.14.5

12
.vscode/launch.json vendored
View File

@@ -16,18 +16,6 @@
},
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'rustpython' without SSL",
"preLaunchTask": "Build RustPython Debug without SSL",
"program": "target/debug/rustpython",
"args": [],
"env": {
"RUST_BACKTRACE": "1"
},
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",

16
.vscode/tasks.json vendored
View File

@@ -1,28 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build RustPython Debug without SSL",
"type": "shell",
"command": "cargo",
"args": [
"build",
],
"problemMatcher": [
"$rustc",
],
"group": {
"kind": "build",
"isDefault": true,
},
},
{
"label": "Build RustPython Debug",
"type": "shell",
"command": "cargo",
"args": [
"build",
"--features=ssl"
],
"problemMatcher": [
"$rustc",

307
AGENTS.md Normal file
View File

@@ -0,0 +1,307 @@
# GitHub Copilot Instructions for RustPython
This document provides guidelines for working with GitHub Copilot when contributing to the RustPython project.
## Project Overview
RustPython is a Python 3 interpreter written in Rust, implementing Python 3.14.0+ compatibility. The project aims to provide:
- A complete Python-3 environment entirely in Rust (not CPython bindings)
- A clean implementation without compatibility hacks
- Cross-platform support, including WebAssembly compilation
- The ability to embed Python scripting in Rust applications
## Repository Structure
- `src/` - Top-level code for the RustPython binary
- `vm/` - The Python virtual machine implementation
- `builtins/` - Python built-in types and functions
- `stdlib/` - Essential standard library modules implemented in Rust, required to run the Python core
- `compiler/` - Python compiler components
- `parser/` - Parser for converting Python source to AST
- `core/` - Bytecode representation in Rust structures
- `codegen/` - AST to bytecode compiler
- `Lib/` - CPython's standard library in Python (copied from CPython). **IMPORTANT**: Do not edit this directory directly; The only allowed operation is copying files from CPython.
- `derive/` - Rust macros for RustPython
- `common/` - Common utilities
- `extra_tests/` - Integration tests and snippets
- `stdlib/` - Non-essential Python standard library modules implemented in Rust (useful but not required for core functionality)
- `wasm/` - WebAssembly support
- `jit/` - Experimental JIT compiler implementation
- `pylib/` - Python standard library packaging (do not modify this directory directly - its contents are generated automatically)
## AI Agent Rules
**CRITICAL: Git Operations**
- NEVER create pull requests directly without explicit user permission
- NEVER push commits to remote without explicit user permission
- Always ask the user before performing any git operations that affect the remote repository
- Commits can be created locally when requested, but pushing and PR creation require explicit approval
**CRITICAL: Pre-commit Checks**
- Before creating ANY commit, you MUST run `prek run --all-files` (or `pre-commit run --all-files`) AND the full test suite. Both must pass — do not commit if either fails.
- Test commands are documented in the [Testing](#testing) section below. At minimum run `cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher`; if the change touches `extra_tests/snippets/` run `pytest -v` there too, and if it touches `Lib/` or interpreter behavior, run the relevant `cargo run --release -- -m test <module>` modules.
- If a hook auto-fixes files (e.g. `ruff-format`, `rustfmt`), re-stage the fixes, re-run `prek` until it reports a clean pass, then re-run the tests, then commit.
- NEVER bypass these checks with `--no-verify`, `--no-gpg-sign`, or by skipping tests "because the change is small". If a hook or test fails, fix the underlying issue and create a new commit — do not amend or force the failing commit through.
## Important Development Notes
### Running Python Code
When testing Python code, always use RustPython instead of the standard `python` command:
```bash
# Use this instead of python script.py
cargo run -- script.py
# For interactive REPL
cargo run
# With specific features
cargo run --features jit
# Release mode (recommended for better performance)
cargo run --release -- script.py
```
### Comparing with CPython
When you need to compare behavior with CPython or run test suites:
```bash
# Use python command to explicitly run CPython
python my_test_script.py
# Run RustPython
cargo run -- my_test_script.py
```
### Working with the Lib Directory
The `Lib/` directory contains Python standard library files copied from the CPython repository. Important notes:
- These files should be edited very conservatively
- Modifications should be minimal and only to work around RustPython limitations
- Tests in `Lib/test` often use one of the following markers:
- Add a `# TODO: RUSTPYTHON` comment when modifications are made
- `unittest.skip("TODO: RustPython <reason>")`
- `unittest.expectedFailure` with `# TODO: RUSTPYTHON <reason>` comment
#### Choosing the right marker
When marking a test that fails on RustPython, prefer one of the following forms:
```python
@unittest.expectedFailure # TODO: RUSTPYTHON; <reason>
# or
@unittest.expectedFailureIf(<condition>, "TODO: RUSTPYTHON; <reason>")
```
If the test would crash the interpreter (segfault, Rust panic, abort, infinite loop), use `skip` instead so the rest of the suite can still run:
```python
@unittest.skip("TODO: RUSTPYTHON; <reason>")
# or
@unittest.skipIf(<condition>, "TODO: RUSTPYTHON; <reason>")
```
**When to use which:**
- **Prefer `expectedFailure` / `expectedFailureIf`** by default. The test body still runs, so if RustPython is later fixed, the unexpected pass surfaces immediately and the decorator can be removed. Use the conditional `*If` form when the failure is environment-specific (e.g., a platform or build flag).
- **Use `skip` / `skipIf` only when running the test would take down the test process** — segfaults, Rust panics, aborts, or hangs that block subsequent tests. Skipping keeps the suite usable; `expectedFailure` cannot help here, because the test body still executes.
To find WIP entries that are partly modified and may need follow-up:
```bash
grep -d recurse 'TODO: RUSTPYTHON' Lib/test/
```
### Clean Build
When you modify bytecode instructions, a full clean is required:
```bash
rm -r target/debug/build/rustpython-* && find . | grep -E "\.pyc$" | xargs rm -r
```
### Testing
```bash
# Run Rust unit tests
cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher
# Run Python snippets tests (debug mode recommended for faster compilation)
cargo run -- extra_tests/snippets/builtin_bytes.py
# Run all Python snippets tests with pytest
cd extra_tests
pytest -v
# Run the Python test module (release mode recommended for better performance)
cargo run --release -- -m test ${TEST_MODULE}
cargo run --release -- -m test test_unicode # to test test_unicode.py
# Run the Python test module with specific function
cargo run --release -- -m test test_unicode -k test_unicode_escape
```
**Note**: For `extra_tests/snippets` tests, use debug mode (`cargo run`) as compilation is faster. For `unittest` (`-m test`), use release mode (`cargo run --release`) for better runtime performance.
### Determining What to Implement
Run `./scripts/whats_left.py` to get a list of unimplemented methods, which is helpful when looking for contribution opportunities.
## Coding Guidelines
### Rust Code
- Follow the default rustfmt code style (`cargo fmt` to format)
- **IMPORTANT**: Always run clippy to lint code (`cargo clippy`) before completing tasks. Fix any warnings or lints that are introduced by your changes
- Follow Rust best practices for error handling and memory management
- Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust
#### Comments
- Do not delete or rewrite existing comments unless they are factually wrong or directly contradict the new code.
- Do not add decorative section separators (e.g. `// -----------`, `// ===`, `/* *** */`). Use `///` doc-comments or short `//` comments only when they add value.
- Do not put `///` doc comments on items annotated with `#[pyattr]`, `#[pyclass]`, or `#[pyfunction]`. The derive macros pull authoritative docstrings from CPython via the `rustpython-doc` crate; a Rust doc comment overrides that source, and on `#[pyattr]` it is silently dropped.
#### Avoid Duplicate Code in Branches
When branches differ only in a value but share common logic, extract the differing value first, then call the common logic once.
**Bad:**
```rust
let result = if condition {
let msg = format!("message A: {x}");
some_function(msg, shared_arg)
} else {
let msg = format!("message B");
some_function(msg, shared_arg)
};
```
**Good:**
```rust
let msg = if condition {
format!("message A: {x}")
} else {
format!("message B")
};
let result = some_function(msg, shared_arg);
```
### Python Code
- **IMPORTANT**: In most cases, Python code should not be edited. Bug fixes should be made through Rust code modifications only
- Follow PEP 8 style for custom Python code
- Use ruff for linting Python code
- Minimize modifications to CPython standard library files
## Integration Between Rust and Python
The project provides several mechanisms for integration:
- `pymodule` macro for creating Python modules in Rust
- `pyclass` macro for implementing Python classes in Rust
- `pyfunction` macro for exposing Rust functions to Python
- `PyObjectRef` and other types for working with Python objects in Rust
## Common Patterns
### Implementing a Python Module in Rust
```rust
#[pymodule]
mod mymodule {
use rustpython_vm::prelude::*;
#[pyfunction]
fn my_function(value: i32) -> i32 {
value * 2
}
#[pyattr]
#[pyclass(name = "MyClass")]
#[derive(Debug, PyPayload)]
struct MyClass {
value: usize,
}
#[pyclass]
impl MyClass {
#[pymethod]
fn get_value(&self) -> usize {
self.value
}
}
}
```
### Adding a Python Module to the Interpreter
```rust
vm.add_native_module(
"my_module_name".to_owned(),
Box::new(my_module::make_module),
);
```
## Building for Different Targets
### WebAssembly
```bash
# Build for WASM
cargo build --target wasm32-wasip1 --no-default-features --features freeze-stdlib,stdlib --release
```
### JIT Support
```bash
# Enable JIT support
cargo run --features jit
```
### Linux Build and Debug on macOS
See the "Testing on Linux from macOS" section in [DEVELOPMENT.md](DEVELOPMENT.md#testing-on-linux-from-macos).
### Building venvlauncher (Windows)
See DEVELOPMENT.md "CPython Version Upgrade Checklist" section.
**IMPORTANT**: All 4 venvlauncher binaries use the same source code. Do NOT add multiple `[[bin]]` entries to Cargo.toml. Build once and copy with different names.
## Test Code Modification Rules
**CRITICAL: Test code modification restrictions**
- NEVER comment out or delete any test code lines except for removing `@unittest.expectedFailure` decorators and upper TODO comments
- NEVER modify test assertions, test logic, or test data
- When a test cannot pass due to missing language features, keep it as expectedFailure and document the reason
- The only acceptable modifications to test files are:
1. Removing `@unittest.expectedFailure` decorators and the upper TODO comments when tests actually pass
2. Adding `@unittest.expectedFailure` decorators when tests cannot be fixed
**Examples of FORBIDDEN modifications:**
- Commenting out test lines
- Changing test assertions
- Modifying test data or expected results
- Removing test logic
**Correct approach when tests fail due to unsupported syntax:**
- Keep the test as `@unittest.expectedFailure`
- Document that it requires PEP 695 support
- Focus on tests that can be fixed through Rust code changes only
## CI Workflows
If you modify any file under `.github/workflows/`, the change must pass a [zizmor](https://docs.zizmor.sh/) scan in CI.
## Documentation
- Check the [architecture document](/architecture/architecture.md) for a high-level overview
- Read the [development guide](/DEVELOPMENT.md) for detailed setup instructions
- Generate documentation with `cargo doc --no-deps --all`
- Online documentation is available at [docs.rs/rustpython](https://docs.rs/rustpython/)
- [How to update test files](https://github.com/RustPython/RustPython/wiki/How-to-update-test-files#checkout-cpython-source-code-initial-setup) — guide for syncing test cases from upstream CPython into the `Lib/` directory

4766
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,117 +1,56 @@
[package]
name = "rustpython"
version = "0.3.1"
authors = ["RustPython Team"]
edition = "2021"
rust-version = "1.67.1"
description = "A python interpreter written in rust."
repository = "https://github.com/RustPython/RustPython"
license = "MIT"
include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
[workspace]
resolver = "2"
members = [
"compiler", "compiler/core", "compiler/codegen",
".", "common", "derive", "jit", "vm", "vm/sre_engine", "pylib", "stdlib", "wasm/lib", "derive-impl",
]
[workspace.dependencies]
rustpython-compiler-core = { path = "compiler/core", version = "0.3.1" }
rustpython-compiler = { path = "compiler", version = "0.3.1" }
rustpython-codegen = { path = "compiler/codegen", version = "0.3.1" }
rustpython-common = { path = "common", version = "0.3.1" }
rustpython-derive = { path = "derive", version = "0.3.1" }
rustpython-derive-impl = { path = "derive-impl", version = "0.3.1" }
rustpython-jit = { path = "jit", version = "0.3.1" }
rustpython-vm = { path = "vm", default-features = false, version = "0.3.1" }
rustpython-pylib = { path = "pylib", version = "0.3.1" }
rustpython-stdlib = { path = "stdlib", default-features = false, version = "0.3.1" }
rustpython-sre_engine = { path = "vm/sre_engine", version = "0.3.1" }
rustpython-doc = { git = "https://github.com/RustPython/__doc__", tag = "0.3.0", version = "0.3.0" }
rustpython-literal = { git = "https://github.com/RustPython/Parser.git", version = "0.3.1", rev = "a95045bc627b2fbf84caf4f010e521846be7b37f" }
rustpython-parser-core = { git = "https://github.com/RustPython/Parser.git", version = "0.3.1", rev = "a95045bc627b2fbf84caf4f010e521846be7b37f" }
rustpython-parser = { git = "https://github.com/RustPython/Parser.git", version = "0.3.1", rev = "a95045bc627b2fbf84caf4f010e521846be7b37f" }
rustpython-ast = { git = "https://github.com/RustPython/Parser.git", version = "0.3.1", rev = "a95045bc627b2fbf84caf4f010e521846be7b37f" }
rustpython-format = { git = "https://github.com/RustPython/Parser.git", version = "0.3.1", rev = "a95045bc627b2fbf84caf4f010e521846be7b37f" }
# rustpython-literal = { path = "../RustPython-parser/literal" }
# rustpython-parser-core = { path = "../RustPython-parser/core" }
# rustpython-parser = { path = "../RustPython-parser/parser" }
# rustpython-ast = { path = "../RustPython-parser/ast" }
# rustpython-format = { path = "../RustPython-parser/format" }
ahash = "0.8.11"
ascii = "1.0"
atty = "0.2.14"
bitflags = "2.4.1"
bstr = "0.2.17"
cfg-if = "1.0"
chrono = "0.4.37"
crossbeam-utils = "0.8.19"
flame = "0.2.2"
glob = "0.3"
hex = "0.4.3"
indexmap = { version = "2.2.6", features = ["std"] }
insta = "1.38.0"
itertools = "0.11.0"
is-macro = "0.3.0"
libc = "0.2.153"
log = "0.4.16"
nix = { version = "0.27", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
malachite-bigint = "0.2.0"
malachite-q = "0.4.4"
malachite-base = "0.4.4"
memchr = "2.7.2"
num-complex = "0.4.0"
num-integer = "0.1.44"
num-traits = "0.2"
num_enum = "0.7"
once_cell = "1.19.0"
parking_lot = "0.12.1"
paste = "1.0.7"
rand = "0.8.5"
rustyline = "14.0.0"
serde = { version = "1.0.133", default-features = false }
schannel = "0.1.22"
static_assertions = "1.1"
syn = "1.0.109"
thiserror = "1.0"
thread_local = "1.1.4"
unicode_names2 = "1.1.0"
widestring = "1.1.0"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true
[features]
default = ["threading", "stdlib", "zlib", "importlib"]
capi = ["dep:rustpython-capi", "threading"]
default = ["threading", "stdlib", "stdio", "importlib", "ssl-rustls-aws-lc", "host_env"]
host_env = ["rustpython-vm/host_env", "rustpython-stdlib?/host_env"]
importlib = ["rustpython-vm/importlib"]
encodings = ["rustpython-vm/encodings"]
stdio = ["rustpython-vm/stdio"]
stdlib = ["rustpython-stdlib", "rustpython-pylib", "encodings"]
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
freeze-stdlib = ["rustpython-vm/freeze-stdlib", "rustpython-pylib?/freeze-stdlib"]
flame-it = ["rustpython-vm/flame-it", "rustpython-stdlib/flame-it", "flame", "flamescope"]
freeze-stdlib = ["stdlib", "rustpython-vm/freeze-stdlib", "rustpython-pylib?/freeze-stdlib"]
jit = ["rustpython-vm/jit"]
threading = ["rustpython-vm/threading", "rustpython-stdlib/threading"]
zlib = ["stdlib", "rustpython-stdlib/zlib"]
bz2 = ["stdlib", "rustpython-stdlib/bz2"]
ssl = ["rustpython-stdlib/ssl"]
ssl-vendor = ["rustpython-stdlib/ssl-vendor"]
sqlite = ["rustpython-stdlib/sqlite"]
ssl = ["host_env"]
ssl-rustls = ["ssl", "rustpython-stdlib/ssl-rustls"]
ssl-rustls-aws-lc = ["ssl-rustls", "dep:rustls", "rustls/aws_lc_rs"]
ssl-rustls-aws-lc-fips = ["ssl-rustls-aws-lc", "rustls/fips"]
ssl-openssl = ["ssl", "rustpython-stdlib/ssl-openssl"]
ssl-vendor = ["ssl-openssl", "rustpython-stdlib/ssl-vendor"]
tkinter = ["rustpython-stdlib/tkinter"]
[build-dependencies]
winresource = "0.1"
[dependencies]
rustpython-capi = { workspace = true, optional = true }
rustpython-compiler = { workspace = true }
rustpython-pylib = { workspace = true, optional = true }
rustpython-stdlib = { workspace = true, optional = true }
rustpython-vm = { workspace = true, features = ["compiler"] }
rustpython-parser = { workspace = true }
rustpython-stdlib = { workspace = true, optional = true, features = ["compiler"] }
rustpython-vm = { workspace = true, features = ["compiler", "gc"] }
atty = { workspace = true }
cfg-if = { workspace = true }
log = { workspace = true }
flame = { workspace = true, optional = true }
clap = "2.34"
dirs = { package = "dirs-next", version = "2.0.0" }
env_logger = { version = "0.9.0", default-features = false, features = ["atty", "termcolor"] }
lexopt = "0.3"
dirs = "6"
env_logger = "0.11"
flamescope = { version = "0.1.2", optional = true }
rustls = { workspace = true, optional = true }
rustls-graviola = { workspace = true, optional = true }
[target.'cfg(windows)'.dependencies]
libc = { workspace = true }
@@ -119,8 +58,10 @@ libc = { workspace = true }
rustyline = { workspace = true }
[dev-dependencies]
criterion = { version = "0.3.5", features = ["html_reports"] }
pyo3 = { version = "0.20.2", features = ["auto-initialize"] }
criterion = { workspace = true }
pyo3 = { workspace = true, features = ["auto-initialize"] }
rustpython-stdlib = { workspace = true }
ruff_python_parser = { workspace = true }
[[bench]]
name = "execution"
@@ -134,6 +75,17 @@ harness = false
name = "rustpython"
path = "src/main.rs"
[[example]]
name = "custom_tls_providers"
path = "examples/custom_tls_providers.rs"
required-features = [
"rustls-graviola",
"rustls/ring",
"rustpython-pylib/freeze-stdlib",
"rustpython-stdlib/ssl-rustls",
"rustpython-vm/freeze-stdlib",
]
[profile.dev.package."*"]
opt-level = 3
@@ -142,6 +94,21 @@ opt-level = 3
# https://github.com/rust-lang/rust/issues/92869
# lto = "thin"
# Some crates don't change as much but benefit more from
# more expensive optimization passes, so we selectively
# decrease codegen-units in some cases.
[profile.release.package.rustpython-doc]
codegen-units = 1
[profile.release.package.rustpython-literal]
codegen-units = 1
[profile.release.package.rustpython-common]
codegen-units = 1
[profile.release.package.rustpython-wtf8]
codegen-units = 1
[profile.bench]
lto = "thin"
codegen-units = 1
@@ -151,15 +118,274 @@ opt-level = 3
lto = "thin"
[patch.crates-io]
parking_lot_core = { git = "https://github.com/youknowone/parking_lot", branch = "rustpython" }
# REDOX START, Uncomment when you want to compile/check with redoxer
# REDOX END
# Used only on Windows to build the vcpkg dependencies
[package.metadata.vcpkg]
git = "https://github.com/microsoft/vcpkg"
# The revision of the vcpkg repository to use
# https://github.com/microsoft/vcpkg/tags
rev = "2024.02.14"
[package.metadata.packager]
product-name = "RustPython"
identifier = "com.rustpython.rustpython"
description = "An open source Python 3 interpreter written in Rust"
homepage = "https://rustpython.github.io/"
license_file = "LICENSE"
authors = ["RustPython Team"]
publisher = "RustPython Team"
resources = ["LICENSE", "README.md", "Lib"]
icons = ["32x32.png"]
[package.metadata.vcpkg.target]
x86_64-pc-windows-msvc = { triplet = "x64-windows-static-md", dev-dependencies = ["openssl" ] }
[package.metadata.packager.nsis]
installer_mode = "both"
template = "installer-config/installer.nsi"
[package.metadata.packager.wix]
template = "installer-config/installer.wxs"
[workspace]
resolver = "2"
members = [
".",
"crates/*",
]
exclude = ["pymath"]
[workspace.package]
version = "0.5.0"
authors = ["RustPython Team"]
edition = "2024"
rust-version = "1.95.0"
repository = "https://github.com/RustPython/RustPython"
license = "MIT"
[workspace.dependencies]
rustpython-capi = { path = "crates/capi", version = "0.5.0" }
rustpython-compiler-core = { path = "crates/compiler-core", version = "0.5.0" }
rustpython-compiler = { path = "crates/compiler", version = "0.5.0" }
rustpython-codegen = { path = "crates/codegen", version = "0.5.0" }
rustpython-common = { path = "crates/common", version = "0.5.0" }
rustpython-host_env = { path = "crates/host_env", version = "0.5.0" }
rustpython-derive = { path = "crates/derive", version = "0.5.0" }
rustpython-derive-impl = { path = "crates/derive-impl", version = "0.5.0" }
rustpython-jit = { path = "crates/jit", version = "0.5.0" }
rustpython-literal = { path = "crates/literal", version = "0.5.0" }
rustpython-vm = { path = "crates/vm", default-features = false, version = "0.5.0" }
rustpython-pylib = { path = "crates/pylib", version = "0.5.0" }
rustpython-stdlib = { path = "crates/stdlib", default-features = false, version = "0.5.0" }
rustpython-sre_engine = { path = "crates/sre_engine", version = "0.5.0" }
rustpython-wtf8 = { path = "crates/wtf8", version = "0.5.0" }
rustpython-doc = { path = "crates/doc", version = "0.5.0" }
# Use RustPython-packaged Ruff crates from the published fork while keeping
# existing crate names in the codebase.
ruff_python_parser = { package = "rustpython-ruff_python_parser", version = "0.15.8" }
ruff_python_ast = { package = "rustpython-ruff_python_ast", version = "0.15.8" }
ruff_text_size = { package = "rustpython-ruff_text_size", version = "0.15.8" }
ruff_source_file = { package = "rustpython-ruff_source_file", version = "0.15.8" }
# To update ruff crates, comment out the above lines and uncomment the following lines to pull directly from the Ruff repository at the specified commit hash.
# Ruff tag 0.15.8 is based on commit c2a8815842f9dc5d24ec19385eae0f1a7188b0d9
# at the time of this capture. We use the commit hash to ensure reproducible builds.
# ruff_python_parser = { git = "https://github.com/astral-sh/ruff.git", rev = "c2a8815842f9dc5d24ec19385eae0f1a7188b0d9" }
# ruff_python_ast = { git = "https://github.com/astral-sh/ruff.git", rev = "c2a8815842f9dc5d24ec19385eae0f1a7188b0d9" }
# ruff_text_size = { git = "https://github.com/astral-sh/ruff.git", rev = "c2a8815842f9dc5d24ec19385eae0f1a7188b0d9" }
# ruff_source_file = { git = "https://github.com/astral-sh/ruff.git", rev = "c2a8815842f9dc5d24ec19385eae0f1a7188b0d9" }
der = { version = "0.8", features = ["alloc", "oid", "pem", "zeroize"] }
phf = { version = "0.13.1", default-features = false, features = ["macros"]}
adler32 = "1.2.0"
approx = "0.5.1"
ascii = "1.1"
base64 = "0.22"
blake2 = "0.10.4"
bitflags = "2.11.0"
bitflagset = "0.0.3"
bstr = "1"
bzip2 = "0.6"
chrono = { version = "0.4.44", default-features = false, features = ["clock", "std"] }
console_error_panic_hook = "0.1"
constant_time_eq = "0.4"
cranelift = "0.131.2"
cranelift-jit = "0.131.2"
cranelift-module = "0.131.0"
crc32fast = "1.3.2"
criterion = { version = "0.8", features = ["html_reports"] }
crossbeam-utils = "0.8.21"
csv-core = "0.1.11"
digest = "0.10.7"
dns-lookup = "3.0"
dyn-clone = "1.0.10"
exitcode = "1.1.2"
flame = "0.2.2"
flamer = "0.5"
flate2 = { version = "1.1.9", default-features = false }
# Bump only when the openssl crate bumps it
foreign-types-shared = "0.1"
gethostname = "1.0.2"
getrandom = { version = "0.4", features = ["std"] }
glob = "0.3"
half = "2"
hex = "0.4.3"
hexf-parse = "0.2.1"
hmac = "0.12"
indexmap = { version = "2.14.0", features = ["std"] }
insta = "1.47"
itertools = "0.14.0"
is-macro = "0.3.7"
js-sys = "0.3"
junction = "1.4.2"
lexical-parse-float = "1.0.6"
libc = "0.2.186"
libffi = "5"
libloading = "0.9"
liblzma = "0.4"
liblzma-sys = "0.4"
libsqlite3-sys = "0.37"
libz-rs-sys = "0.6"
lock_api = "0.4"
log = "0.4.29"
lz4_flex = "0.13"
nix = { version = "0.31", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
mac_address = "1.1.3"
malachite-bigint = "0.9.1"
malachite-q = "0.9.1"
malachite-base = "0.9.1"
md-5 = "0.10.1"
memchr = "2.8.0"
memmap2 = "0.9.10"
mt19937 = "<=3.3" # upgrade it once rand is upgraded
num-complex = "0.4.6"
num-integer = "0.1.46"
num-traits = "0.2"
num_cpus = "1.17.0"
num_enum = { version = "0.7", default-features = false }
oid-registry = "0.8"
openssl = "0.10.80"
openssl-sys = "0.9.110"
openssl-probe = "0.2.1"
optional = "0.5"
parking_lot = "0.12.3"
paste = "1.0.15"
pbkdf2 = "0.12"
pem-rfc7468 = "1.0"
pkcs8 = "0.11"
proc-macro2 = "1.0.105"
psm = "0.1"
pymath = { version = "0.2.0", features = ["mul_add", "malachite-bigint", "complex"] }
pyo3 = "0.28"
quote = "1.0.45"
radium = "1.1.1"
rand = "0.10"
rand_core = { version = "0.9", features = ["os_rng"] }
rapidhash = "4.4.1"
result-like = "0.5.0"
rustix = { version = "1.1", features = ["event", "param", "system"] }
rustls = { version = "0.23.39", default-features = false }
rustls-graviola = "0.3"
rustls-native-certs = "0.8"
rustls-pemfile = "2.2"
rustls-platform-verifier = "0.7"
rustyline = "18"
serde = { package = "serde_core", version = "1.0.225", default-features = false, features = ["alloc"] }
schannel = "0.1.29"
scopeguard = "1"
serde-wasm-bindgen = "0.6.5"
sha-1 = "0.10.0"
sha2 = "0.10.2"
sha3 = "0.10.1"
siphasher = "1"
socket2 = "0.6.3"
static_assertions = "1.1"
strum = "0.28"
strum_macros = "0.28"
syn = "2"
syn-ext = "0.5.0"
system-configuration = "0.7.0"
tcl-sys = { git = "https://github.com/arihant2math/tkinter.git", tag = "v0.2.0" }
textwrap = { version = "0.16.2", default-features = false }
termios = "0.3.3"
thiserror = "2.0"
timsort = "0.1.2"
tk-sys = { git = "https://github.com/arihant2math/tkinter.git", tag = "v0.2.0" }
icu_casemap = "2"
icu_locale = "2"
icu_properties = "2"
icu_normalizer = "2"
uuid = "1.23.1"
ucd = "0.1.1"
unic-ucd-age = "0.9.0"
unicode_names2 = "2.0.0"
widestring = "1.2.0"
windows-sys = "0.61.2"
wasm-bindgen = "0.2.106"
wasm-bindgen-futures = "0.4"
web-sys = "0.3"
webpki-roots = "1.0"
which = "8"
x509-cert = "0.2.5"
x509-parser = "0.18"
xml = "1.2"
writeable = "0.6"
# Lints
[workspace.lints.rust]
unsafe_code = "allow"
unsafe_op_in_unsafe_fn = "deny"
elided_lifetimes_in_paths = "warn"
unreachable_pub = "warn"
[workspace.lints.clippy]
correctness = { level = "warn", priority = -2 }
suspicious = { level = "warn", priority = -2 }
perf = { level = "warn", priority = -2 }
style = { level = "warn", priority = -2 }
complexity = { level = "warn", priority = -2 }
# pedantic = { level = "warn", priority = -2 } # TODO: Enable this
missing_errors_doc = "allow" # Too many errors. No auto-fix available
missing_panics_doc = "allow" # Too many errors. No auto-fix available
match_same_arms = "allow" # Not always more readable
if_not_else = "allow" # Not always more readable
single_match_else = "allow"
similar_names = "allow"
# restriction lints
alloc_instead_of_core = "warn"
cfg_not_test = "warn"
redundant_test_prefix = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
tests_outside_test_module = "warn"
# nursery lints to enforce gradually
debug_assert_with_mut_call = "warn"
derive_partial_eq_without_eq = "warn"
imprecise_flops = "warn"
or_fun_call = "warn"
redundant_clone = "warn"
search_is_some = "warn"
single_option_map = "warn"
trait_duplication_in_bounds = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
use_self = "warn"
useless_let_if_seq = "warn"
# pedantic lints to enforce gradually
cloned_instead_of_copied = "warn"
collapsible_else_if = "warn"
comparison_chain = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
format_collect = "warn"
from_iter_instead_of_collect = "warn"
inconsistent_struct_constructor = "warn"
inefficient_to_string = "warn"
manual_is_variant_and = "warn"
map_unwrap_or = "warn"
must_use_candidate = "warn"
redundant_else = "warn"
uninlined_format_args = "warn"
unnecessary_wraps = "warn"
unnested_or_patterns = "warn"

View File

@@ -19,13 +19,13 @@ The contents of the Development Guide include:
RustPython requires the following:
- Rust latest stable version (e.g 1.69.0 as of Apr 20 2023)
- Rust latest stable version (e.g 1.92.0 as of Jan 7 2026)
- To check Rust version: `rustc --version`
- If you have `rustup` on your system, enter to update to the latest
stable version: `rustup update stable`
- If you do not have Rust installed, use [rustup](https://rustup.rs/) to
do so.
- CPython version 3.12 or higher
- CPython version 3.14 or higher
- CPython can be installed by your operating system's package manager,
from the [Python website](https://www.python.org/downloads/), or
using a third-party distribution, such as
@@ -65,7 +65,7 @@ $ pytest -v
Rust unit tests can be run with `cargo`:
```shell
$ cargo test --workspace --exclude rustpython_wasm
$ cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher
```
Python unit tests can be run by compiling RustPython and running the test module:
@@ -95,6 +95,41 @@ To run only `test_cmath` (located at `Lib/test/test_cmath`) verbosely:
$ cargo run --release -- -m test test_cmath -v
```
### Testing on Linux from macOS
You can test RustPython on Linux from macOS using Apple's `container` CLI.
**Setup (one-time):**
```shell
# Install container CLI
$ brew install container
# Disable Rosetta requirement for arm64-only builds
$ defaults write com.apple.container.defaults build.rosetta -bool false
# Build the development image
$ container build --arch arm64 -t rustpython-dev -f .devcontainer/Dockerfile .
```
**Running tests:**
```shell
# Start a persistent container in background (8GB memory, 4 CPUs for compilation)
$ container run -d --name rustpython-test -m 8G -c 4 \
--mount type=bind,source=$(pwd),target=/workspace \
-w /workspace rustpython-dev sleep infinity
# Run tests inside the container
$ container exec rustpython-test sh -c "cargo run --release -- -m test test_ensurepip"
# Run any command
$ container exec rustpython-test sh -c "cargo test --workspace"
# Stop and remove the container when done
$ container rm -f rustpython-test
```
## Profiling
To profile RustPython, build it in `release` mode with the `flame-it` feature.
@@ -118,19 +153,19 @@ exists a raw html viewer which is currently broken, and we welcome a PR to fix i
Understanding a new codebase takes time. Here's a brief view of the
repository's structure:
- `compiler/src`: python compilation to bytecode
- `core/src`: python bytecode representation in rust structures
- `parser/src`: python lexing, parsing and ast
- `derive/src`: Rust language extensions and macros specific to rustpython
- `crates/compiler/src`: python compilation to bytecode
- `crates/compiler-core/src`: python bytecode representation in rust structures
- `crates/derive/src` and `crates/derive-impl/src`: Rust language extensions and macros specific to rustpython
- `Lib`: Carefully selected / copied files from CPython sourcecode. This is
the python side of the standard library.
- `test`: CPython test suite
- `vm/src`: python virtual machine
- `crates/vm/src`: python virtual machine
- `builtins`: Builtin functions and types
- `stdlib`: Standard library parts implemented in rust.
- `src`: using the other subcrates to bring rustpython to life.
- `wasm`: Binary crate and resources for WebAssembly build
- `extra_tests`: extra integration test snippets as a supplement to `Lib/test`
- `crates/wasm`: Binary crate and resources for WebAssembly build
- `extra_tests`: extra integration test snippets as a supplement to `Lib/test`.
Add new RustPython-only regression tests here; do not place new tests under `Lib/test`.
## Understanding Internals
@@ -140,9 +175,9 @@ implementation is found in the `src` directory (specifically, `src/lib.rs`).
The top-level `rustpython` binary depends on several lower-level crates including:
- `rustpython-parser` (implementation in `compiler/parser/src`)
- `rustpython-compiler` (implementation in `compiler/src`)
- `rustpython-vm` (implementation in `vm/src`)
- `ruff_python_parser` and `ruff_python_ast` (external dependencies from the Ruff project)
- `rustpython-compiler` (implementation in `crates/compiler/src`)
- `rustpython-vm` (implementation in `crates/vm/src`)
Together, these crates provide the functions of a programming language and
enable a line of code to go through a series of steps:
@@ -153,31 +188,26 @@ enable a line of code to go through a series of steps:
- compile the AST into bytecode
- execute the bytecode in the virtual machine (VM).
### rustpython-parser
### Parser and AST
This crate contains the lexer and parser to convert a line of code to
an Abstract Syntax Tree (AST):
RustPython uses the Ruff project's parser and AST implementation:
- Lexer: `compiler/parser/src/lexer.rs` converts Python source code into tokens
- Parser: `compiler/parser/src/parser.rs` takes the tokens generated by the lexer and parses
the tokens into an AST (Abstract Syntax Tree) where the nodes of the syntax
tree are Rust structs and enums.
- The Parser relies on `LALRPOP`, a Rust parser generator framework. The
LALRPOP definition of Python's grammar is in `compiler/parser/src/python.lalrpop`.
- More information on parsers and a tutorial can be found in the
[LALRPOP book](https://lalrpop.github.io/lalrpop/).
- AST: `compiler/ast/` implements in Rust the Python types and expressions
represented by the AST nodes.
- Parser: `ruff_python_parser` is used to convert Python source code into tokens
and parse them into an Abstract Syntax Tree (AST)
- AST: `ruff_python_ast` provides the Rust types and expressions represented by
the AST nodes
- These are external dependencies maintained by the Ruff project
- For more information, visit the [Ruff GitHub repository](https://github.com/astral-sh/ruff)
### rustpython-compiler
The `rustpython-compiler` crate's purpose is to transform the AST (Abstract Syntax
Tree) to bytecode. The implementation of the compiler is found in the
`compiler/src` directory. The compiler implements Python's symbol table,
`crates/compiler/src` directory. The compiler implements Python's symbol table,
ast->bytecode compiler, and bytecode optimizer in Rust.
Implementation of bytecode structure in Rust is found in the `compiler/core/src`
directory. `compiler/core/src/bytecode.rs` contains the representation of
Implementation of bytecode structure in Rust is found in the `crates/compiler-core/src`
directory. `crates/compiler-core/src/bytecode.rs` contains the representation of
instructions and operations in Rust. Further information about Python's
bytecode instructions can be found in the
[Python documentation](https://docs.python.org/3/library/dis.html#bytecodes).
@@ -185,14 +215,14 @@ bytecode instructions can be found in the
### rustpython-vm
The `rustpython-vm` crate has the important job of running the virtual machine that
executes Python's instructions. The `vm/src` directory contains code to
executes Python's instructions. The `crates/vm/src` directory contains code to
implement the read and evaluation loop that fetches and dispatches
instructions. This directory also contains the implementation of the
Python Standard Library modules in Rust (`vm/src/stdlib`). In Python
everything can be represented as an object. The `vm/src/builtins` directory holds
Python Standard Library modules in Rust (`crates/vm/src/stdlib`). In Python
everything can be represented as an object. The `crates/vm/src/builtins` directory holds
the Rust code used to represent different Python objects and their methods. The
core implementation of what a Python object is can be found in
`vm/src/object/core.rs`.
`crates/vm/src/object/core.rs`.
### Code generation

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2020 RustPython Team
Copyright (c) 2026 RustPython Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

6
Lib/__future__.py vendored
View File

@@ -33,7 +33,7 @@ in releases at or after that, modules no longer need
to use the feature in question, but may continue to use such imports.
MandatoryRelease may also be None, meaning that a planned feature got
dropped.
dropped or that the release version is undetermined.
Instances of class _Feature have two corresponding methods,
.getOptionalRelease() and .getMandatoryRelease().
@@ -96,7 +96,7 @@ class _Feature:
"""Return release in which this feature will become mandatory.
This is a 5-tuple, of the same form as sys.version_info, or, if
the feature was dropped, is None.
the feature was dropped, or the release date is undetermined, is None.
"""
return self.mandatory
@@ -143,5 +143,5 @@ generator_stop = _Feature((3, 5, 0, "beta", 1),
CO_FUTURE_GENERATOR_STOP)
annotations = _Feature((3, 7, 0, "beta", 1),
(3, 11, 0, "alpha", 0),
None,
CO_FUTURE_ANNOTATIONS)

108
Lib/_aix_support.py vendored Normal file
View File

@@ -0,0 +1,108 @@
"""Shared AIX support functions."""
import sys
import sysconfig
# Taken from _osx_support _read_output function
def _read_cmd_output(commandstring, capture_stderr=False):
"""Output from successful command execution or None"""
# Similar to os.popen(commandstring, "r").read(),
# but without actually using os.popen because that
# function is not usable during python bootstrap.
import os
import contextlib
fp = open("/tmp/_aix_support.%s"%(
os.getpid(),), "w+b")
with contextlib.closing(fp) as fp:
if capture_stderr:
cmd = "%s >'%s' 2>&1" % (commandstring, fp.name)
else:
cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
return fp.read() if not os.system(cmd) else None
def _aix_tag(vrtl, bd):
# type: (List[int], int) -> str
# Infer the ABI bitwidth from maxsize (assuming 64 bit as the default)
_sz = 32 if sys.maxsize == (2**31-1) else 64
_bd = bd if bd != 0 else 9988
# vrtl[version, release, technology_level]
return "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(vrtl[0], vrtl[1], vrtl[2], _bd, _sz)
# extract version, release and technology level from a VRMF string
def _aix_vrtl(vrmf):
# type: (str) -> List[int]
v, r, tl = vrmf.split(".")[:3]
return [int(v[-1]), int(r), int(tl)]
def _aix_bos_rte():
# type: () -> Tuple[str, int]
"""
Return a Tuple[str, int] e.g., ['7.1.4.34', 1806]
The fileset bos.rte represents the current AIX run-time level. It's VRMF and
builddate reflect the current ABI levels of the runtime environment.
If no builddate is found give a value that will satisfy pep425 related queries
"""
# All AIX systems to have lslpp installed in this location
# subprocess may not be available during python bootstrap
try:
import subprocess
out = subprocess.check_output(["/usr/bin/lslpp", "-Lqc", "bos.rte"])
except ImportError:
out = _read_cmd_output("/usr/bin/lslpp -Lqc bos.rte")
out = out.decode("utf-8")
out = out.strip().split(":") # type: ignore
_bd = int(out[-1]) if out[-1] != '' else 9988
return (str(out[2]), _bd)
def aix_platform():
# type: () -> str
"""
AIX filesets are identified by four decimal values: V.R.M.F.
V (version) and R (release) can be retrieved using ``uname``
Since 2007, starting with AIX 5.3 TL7, the M value has been
included with the fileset bos.rte and represents the Technology
Level (TL) of AIX. The F (Fix) value also increases, but is not
relevant for comparing releases and binary compatibility.
For binary compatibility the so-called builddate is needed.
Again, the builddate of an AIX release is associated with bos.rte.
AIX ABI compatibility is described as guaranteed at: https://www.ibm.com/\
support/knowledgecenter/en/ssw_aix_72/install/binary_compatability.html
For pep425 purposes the AIX platform tag becomes:
"aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(v, r, tl, builddate, bitsize)
e.g., "aix-6107-1415-32" for AIX 6.1 TL7 bd 1415, 32-bit
and, "aix-6107-1415-64" for AIX 6.1 TL7 bd 1415, 64-bit
"""
vrmf, bd = _aix_bos_rte()
return _aix_tag(_aix_vrtl(vrmf), bd)
# extract vrtl from the BUILD_GNU_TYPE as an int
def _aix_bgt():
# type: () -> List[int]
gnu_type = sysconfig.get_config_var("BUILD_GNU_TYPE")
if not gnu_type:
raise ValueError("BUILD_GNU_TYPE is not defined")
return _aix_vrtl(vrmf=gnu_type)
def aix_buildtag():
# type: () -> str
"""
Return the platform_tag of the system Python was built on.
"""
# AIX_BUILDDATE is defined by configure with:
# lslpp -Lcq bos.rte | awk -F: '{ print $NF }'
build_date = sysconfig.get_config_var("AIX_BUILDDATE")
try:
build_date = int(build_date)
except (ValueError, TypeError):
raise ValueError(f"AIX_BUILDDATE is not defined or invalid: "
f"{build_date!r}")
return _aix_tag(_aix_bgt(), build_date)

192
Lib/_android_support.py vendored Normal file
View File

@@ -0,0 +1,192 @@
import io
import sys
from threading import RLock
from time import sleep, time
# The maximum length of a log message in bytes, including the level marker and
# tag, is defined as LOGGER_ENTRY_MAX_PAYLOAD at
# https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:system/logging/liblog/include/log/log.h;l=71.
# Messages longer than this will be truncated by logcat. This limit has already
# been reduced at least once in the history of Android (from 4076 to 4068 between
# API level 23 and 26), so leave some headroom.
MAX_BYTES_PER_WRITE = 4000
# UTF-8 uses a maximum of 4 bytes per character, so limiting text writes to this
# size ensures that we can always avoid exceeding MAX_BYTES_PER_WRITE.
# However, if the actual number of bytes per character is smaller than that,
# then we may still join multiple consecutive text writes into binary
# writes containing a larger number of characters.
MAX_CHARS_PER_WRITE = MAX_BYTES_PER_WRITE // 4
# When embedded in an app on current versions of Android, there's no easy way to
# monitor the C-level stdout and stderr. The testbed comes with a .c file to
# redirect them to the system log using a pipe, but that wouldn't be convenient
# or appropriate for all apps. So we redirect at the Python level instead.
def init_streams(android_log_write, stdout_prio, stderr_prio):
if sys.executable:
return # Not embedded in an app.
global logcat
logcat = Logcat(android_log_write)
sys.stdout = TextLogStream(stdout_prio, "python.stdout", sys.stdout)
sys.stderr = TextLogStream(stderr_prio, "python.stderr", sys.stderr)
class TextLogStream(io.TextIOWrapper):
def __init__(self, prio, tag, original=None, **kwargs):
# Respect the -u option.
if original:
kwargs.setdefault("write_through", original.write_through)
fileno = original.fileno()
else:
fileno = None
# The default is surrogateescape for stdout and backslashreplace for
# stderr, but in the context of an Android log, readability is more
# important than reversibility.
kwargs.setdefault("encoding", "UTF-8")
kwargs.setdefault("errors", "backslashreplace")
super().__init__(BinaryLogStream(prio, tag, fileno), **kwargs)
self._lock = RLock()
self._pending_bytes = []
self._pending_bytes_count = 0
def __repr__(self):
return f"<TextLogStream {self.buffer.tag!r}>"
def write(self, s):
if not isinstance(s, str):
raise TypeError(
f"write() argument must be str, not {type(s).__name__}")
# In case `s` is a str subclass that writes itself to stdout or stderr
# when we call its methods, convert it to an actual str.
s = str.__str__(s)
# We want to emit one log message per line wherever possible, so split
# the string into lines first. Note that "".splitlines() == [], so
# nothing will be logged for an empty string.
with self._lock:
for line in s.splitlines(keepends=True):
while line:
chunk = line[:MAX_CHARS_PER_WRITE]
line = line[MAX_CHARS_PER_WRITE:]
self._write_chunk(chunk)
return len(s)
# The size and behavior of TextIOWrapper's buffer is not part of its public
# API, so we handle buffering ourselves to avoid truncation.
def _write_chunk(self, s):
b = s.encode(self.encoding, self.errors)
if self._pending_bytes_count + len(b) > MAX_BYTES_PER_WRITE:
self.flush()
self._pending_bytes.append(b)
self._pending_bytes_count += len(b)
if (
self.write_through
or b.endswith(b"\n")
or self._pending_bytes_count > MAX_BYTES_PER_WRITE
):
self.flush()
def flush(self):
with self._lock:
self.buffer.write(b"".join(self._pending_bytes))
self._pending_bytes.clear()
self._pending_bytes_count = 0
# Since this is a line-based logging system, line buffering cannot be turned
# off, i.e. a newline always causes a flush.
@property
def line_buffering(self):
return True
class BinaryLogStream(io.RawIOBase):
def __init__(self, prio, tag, fileno=None):
self.prio = prio
self.tag = tag
self._fileno = fileno
def __repr__(self):
return f"<BinaryLogStream {self.tag!r}>"
def writable(self):
return True
def write(self, b):
if type(b) is not bytes:
try:
b = bytes(memoryview(b))
except TypeError:
raise TypeError(
f"write() argument must be bytes-like, not {type(b).__name__}"
) from None
# Writing an empty string to the stream should have no effect.
if b:
logcat.write(self.prio, self.tag, b)
return len(b)
# This is needed by the test suite --timeout option, which uses faulthandler.
def fileno(self):
if self._fileno is None:
raise io.UnsupportedOperation("fileno")
return self._fileno
# When a large volume of data is written to logcat at once, e.g. when a test
# module fails in --verbose3 mode, there's a risk of overflowing logcat's own
# buffer and losing messages. We avoid this by imposing a rate limit using the
# token bucket algorithm, based on a conservative estimate of how fast `adb
# logcat` can consume data.
MAX_BYTES_PER_SECOND = 1024 * 1024
# The logcat buffer size of a device can be determined by running `logcat -g`.
# We set the token bucket size to half of the buffer size of our current minimum
# API level, because other things on the system will be producing messages as
# well.
BUCKET_SIZE = 128 * 1024
# https://cs.android.com/android/platform/superproject/+/android-14.0.0_r1:system/logging/liblog/include/log/log_read.h;l=39
PER_MESSAGE_OVERHEAD = 28
class Logcat:
def __init__(self, android_log_write):
self.android_log_write = android_log_write
self._lock = RLock()
self._bucket_level = 0
self._prev_write_time = time()
def write(self, prio, tag, message):
# Encode null bytes using "modified UTF-8" to avoid them truncating the
# message.
message = message.replace(b"\x00", b"\xc0\x80")
# On API level 30 and higher, Logcat will strip any number of leading
# newlines. This is visible in all `logcat` modes, even --binary. Work
# around this by adding a leading space, which shouldn't make any
# difference to the log's usability.
if message.startswith(b"\n"):
message = b" " + message
with self._lock:
now = time()
self._bucket_level += (
(now - self._prev_write_time) * MAX_BYTES_PER_SECOND)
# If the bucket level is still below zero, the clock must have gone
# backwards, so reset it to zero and continue.
self._bucket_level = max(0, min(self._bucket_level, BUCKET_SIZE))
self._prev_write_time = now
self._bucket_level -= PER_MESSAGE_OVERHEAD + len(tag) + len(message)
if self._bucket_level < 0:
sleep(-self._bucket_level / MAX_BYTES_PER_SECOND)
self.android_log_write(prio, tag, message)

66
Lib/_apple_support.py vendored Normal file
View File

@@ -0,0 +1,66 @@
import io
import sys
def init_streams(log_write, stdout_level, stderr_level):
# Redirect stdout and stderr to the Apple system log. This method is
# invoked by init_apple_streams() (initconfig.c) if config->use_system_logger
# is enabled.
sys.stdout = SystemLog(log_write, stdout_level, errors=sys.stderr.errors)
sys.stderr = SystemLog(log_write, stderr_level, errors=sys.stderr.errors)
class SystemLog(io.TextIOWrapper):
def __init__(self, log_write, level, **kwargs):
kwargs.setdefault("encoding", "UTF-8")
kwargs.setdefault("line_buffering", True)
super().__init__(LogStream(log_write, level), **kwargs)
def __repr__(self):
return f"<SystemLog (level {self.buffer.level})>"
def write(self, s):
if not isinstance(s, str):
raise TypeError(
f"write() argument must be str, not {type(s).__name__}")
# In case `s` is a str subclass that writes itself to stdout or stderr
# when we call its methods, convert it to an actual str.
s = str.__str__(s)
# We want to emit one log message per line, so split
# the string before sending it to the superclass.
for line in s.splitlines(keepends=True):
super().write(line)
return len(s)
class LogStream(io.RawIOBase):
def __init__(self, log_write, level):
self.log_write = log_write
self.level = level
def __repr__(self):
return f"<LogStream (level {self.level!r})>"
def writable(self):
return True
def write(self, b):
if type(b) is not bytes:
try:
b = bytes(memoryview(b))
except TypeError:
raise TypeError(
f"write() argument must be bytes-like, not {type(b).__name__}"
) from None
# Writing an empty string to the stream should have no effect.
if b:
# Encode null bytes using "modified UTF-8" to avoid truncating the
# message. This should not affect the return value, as the caller
# may be expecting it to match the length of the input.
self.log_write(self.level, b.replace(b"\x00", b"\xc0\x80"))
return len(b)

1161
Lib/_ast_unparse.py vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -85,6 +85,10 @@ dict_values = type({}.values())
dict_items = type({}.items())
## misc ##
mappingproxy = type(type.__dict__)
def _get_framelocalsproxy():
return type(sys._getframe().f_locals)
framelocalsproxy = _get_framelocalsproxy()
del _get_framelocalsproxy
generator = type((lambda: (yield))())
## coroutine ##
async def _coro(): pass
@@ -481,9 +485,10 @@ class _CallableGenericAlias(GenericAlias):
def __repr__(self):
if len(self.__args__) == 2 and _is_param_expr(self.__args__[0]):
return super().__repr__()
from annotationlib import type_repr
return (f'collections.abc.Callable'
f'[[{", ".join([_type_repr(a) for a in self.__args__[:-1]])}], '
f'{_type_repr(self.__args__[-1])}]')
f'[[{", ".join([type_repr(a) for a in self.__args__[:-1]])}], '
f'{type_repr(self.__args__[-1])}]')
def __reduce__(self):
args = self.__args__
@@ -520,23 +525,6 @@ def _is_param_expr(obj):
names = ('ParamSpec', '_ConcatenateGenericAlias')
return obj.__module__ == 'typing' and any(obj.__name__ == name for name in names)
def _type_repr(obj):
"""Return the repr() of an object, special-casing types (internal helper).
Copied from :mod:`typing` since collections.abc
shouldn't depend on that module.
(Keep this roughly in sync with the typing version.)
"""
if isinstance(obj, type):
if obj.__module__ == 'builtins':
return obj.__qualname__
return f'{obj.__module__}.{obj.__qualname__}'
if obj is Ellipsis:
return '...'
if isinstance(obj, FunctionType):
return obj.__name__
return repr(obj)
class Callable(metaclass=ABCMeta):
@@ -836,6 +824,7 @@ class Mapping(Collection):
__reversed__ = None
Mapping.register(mappingproxy)
Mapping.register(framelocalsproxy)
class MappingView(Sized):
@@ -973,7 +962,7 @@ class MutableMapping(Mapping):
def update(self, other=(), /, **kwds):
''' D.update([E, ]**F) -> None. Update D from mapping/iterable E and F.
If E present and has a .keys() method, does: for k in E: D[k] = E[k]
If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k]
If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v
In either case, this is followed by: for k, v in F.items(): D[k] = v
'''
@@ -1068,6 +1057,7 @@ class Sequence(Reversible, Collection):
Sequence.register(tuple)
Sequence.register(str)
Sequence.register(bytes)
Sequence.register(range)
Sequence.register(memoryview)
@@ -1078,7 +1068,7 @@ class _DeprecateByteStringMeta(ABCMeta):
warnings._deprecated(
"collections.abc.ByteString",
remove=(3, 14),
remove=(3, 17),
)
return super().__new__(cls, name, bases, namespace, **kwargs)
@@ -1087,14 +1077,18 @@ class _DeprecateByteStringMeta(ABCMeta):
warnings._deprecated(
"collections.abc.ByteString",
remove=(3, 14),
remove=(3, 17),
)
return super().__instancecheck__(instance)
class ByteString(Sequence, metaclass=_DeprecateByteStringMeta):
"""This unifies bytes and bytearray.
"""Deprecated ABC serving as a common supertype of ``bytes`` and ``bytearray``.
XXX Should add all their methods.
This ABC is scheduled for removal in Python 3.17.
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
implements the buffer protocol at runtime. For use in type annotations,
either use ``Buffer`` or a union that explicitly specifies the types your
code supports (e.g., ``bytes | bytearray | memoryview``).
"""
__slots__ = ()
@@ -1170,4 +1164,4 @@ class MutableSequence(Sequence):
MutableSequence.register(list)
MutableSequence.register(bytearray) # Multiply inheriting, see ByteString
MutableSequence.register(bytearray)

355
Lib/_colorize.py vendored Normal file
View File

@@ -0,0 +1,355 @@
import os
import sys
from collections.abc import Callable, Iterator, Mapping
from dataclasses import dataclass, field, Field
COLORIZE = True
# types
if False:
from typing import IO, Self, ClassVar
_theme: Theme
class ANSIColors:
RESET = "\x1b[0m"
BLACK = "\x1b[30m"
BLUE = "\x1b[34m"
CYAN = "\x1b[36m"
GREEN = "\x1b[32m"
GREY = "\x1b[90m"
MAGENTA = "\x1b[35m"
RED = "\x1b[31m"
WHITE = "\x1b[37m" # more like LIGHT GRAY
YELLOW = "\x1b[33m"
BOLD = "\x1b[1m"
BOLD_BLACK = "\x1b[1;30m" # DARK GRAY
BOLD_BLUE = "\x1b[1;34m"
BOLD_CYAN = "\x1b[1;36m"
BOLD_GREEN = "\x1b[1;32m"
BOLD_MAGENTA = "\x1b[1;35m"
BOLD_RED = "\x1b[1;31m"
BOLD_WHITE = "\x1b[1;37m" # actual WHITE
BOLD_YELLOW = "\x1b[1;33m"
# intense = like bold but without being bold
INTENSE_BLACK = "\x1b[90m"
INTENSE_BLUE = "\x1b[94m"
INTENSE_CYAN = "\x1b[96m"
INTENSE_GREEN = "\x1b[92m"
INTENSE_MAGENTA = "\x1b[95m"
INTENSE_RED = "\x1b[91m"
INTENSE_WHITE = "\x1b[97m"
INTENSE_YELLOW = "\x1b[93m"
BACKGROUND_BLACK = "\x1b[40m"
BACKGROUND_BLUE = "\x1b[44m"
BACKGROUND_CYAN = "\x1b[46m"
BACKGROUND_GREEN = "\x1b[42m"
BACKGROUND_MAGENTA = "\x1b[45m"
BACKGROUND_RED = "\x1b[41m"
BACKGROUND_WHITE = "\x1b[47m"
BACKGROUND_YELLOW = "\x1b[43m"
INTENSE_BACKGROUND_BLACK = "\x1b[100m"
INTENSE_BACKGROUND_BLUE = "\x1b[104m"
INTENSE_BACKGROUND_CYAN = "\x1b[106m"
INTENSE_BACKGROUND_GREEN = "\x1b[102m"
INTENSE_BACKGROUND_MAGENTA = "\x1b[105m"
INTENSE_BACKGROUND_RED = "\x1b[101m"
INTENSE_BACKGROUND_WHITE = "\x1b[107m"
INTENSE_BACKGROUND_YELLOW = "\x1b[103m"
ColorCodes = set()
NoColors = ANSIColors()
for attr, code in ANSIColors.__dict__.items():
if not attr.startswith("__"):
ColorCodes.add(code)
setattr(NoColors, attr, "")
#
# Experimental theming support (see gh-133346)
#
# - Create a theme by copying an existing `Theme` with one or more sections
# replaced, using `default_theme.copy_with()`;
# - create a theme section by copying an existing `ThemeSection` with one or
# more colors replaced, using for example `default_theme.syntax.copy_with()`;
# - create a theme from scratch by instantiating a `Theme` data class with
# the required sections (which are also dataclass instances).
#
# Then call `_colorize.set_theme(your_theme)` to set it.
#
# Put your theme configuration in $PYTHONSTARTUP for the interactive shell,
# or sitecustomize.py in your virtual environment or Python installation for
# other uses. Your applications can call `_colorize.set_theme()` too.
#
# Note that thanks to the dataclasses providing default values for all fields,
# creating a new theme or theme section from scratch is possible without
# specifying all keys.
#
# For example, here's a theme that makes punctuation and operators less prominent:
#
# try:
# from _colorize import set_theme, default_theme, Syntax, ANSIColors
# except ImportError:
# pass
# else:
# theme_with_dim_operators = default_theme.copy_with(
# syntax=Syntax(op=ANSIColors.INTENSE_BLACK),
# )
# set_theme(theme_with_dim_operators)
# del set_theme, default_theme, Syntax, ANSIColors, theme_with_dim_operators
#
# Guarding the import ensures that your .pythonstartup file will still work in
# Python 3.13 and older. Deleting the variables ensures they don't remain in your
# interactive shell's global scope.
class ThemeSection(Mapping[str, str]):
"""A mixin/base class for theme sections.
It enables dictionary access to a section, as well as implements convenience
methods.
"""
# The two types below are just that: types to inform the type checker that the
# mixin will work in context of those fields existing
__dataclass_fields__: ClassVar[dict[str, Field[str]]]
_name_to_value: Callable[[str], str]
def __post_init__(self) -> None:
name_to_value = {}
for color_name in self.__dataclass_fields__:
name_to_value[color_name] = getattr(self, color_name)
super().__setattr__('_name_to_value', name_to_value.__getitem__)
def copy_with(self, **kwargs: str) -> Self:
color_state: dict[str, str] = {}
for color_name in self.__dataclass_fields__:
color_state[color_name] = getattr(self, color_name)
color_state.update(kwargs)
return type(self)(**color_state)
@classmethod
def no_colors(cls) -> Self:
color_state: dict[str, str] = {}
for color_name in cls.__dataclass_fields__:
color_state[color_name] = ""
return cls(**color_state)
def __getitem__(self, key: str) -> str:
return self._name_to_value(key)
def __len__(self) -> int:
return len(self.__dataclass_fields__)
def __iter__(self) -> Iterator[str]:
return iter(self.__dataclass_fields__)
@dataclass(frozen=True, kw_only=True)
class Argparse(ThemeSection):
usage: str = ANSIColors.BOLD_BLUE
prog: str = ANSIColors.BOLD_MAGENTA
prog_extra: str = ANSIColors.MAGENTA
heading: str = ANSIColors.BOLD_BLUE
summary_long_option: str = ANSIColors.CYAN
summary_short_option: str = ANSIColors.GREEN
summary_label: str = ANSIColors.YELLOW
summary_action: str = ANSIColors.GREEN
long_option: str = ANSIColors.BOLD_CYAN
short_option: str = ANSIColors.BOLD_GREEN
label: str = ANSIColors.BOLD_YELLOW
action: str = ANSIColors.BOLD_GREEN
reset: str = ANSIColors.RESET
@dataclass(frozen=True)
class Syntax(ThemeSection):
prompt: str = ANSIColors.BOLD_MAGENTA
keyword: str = ANSIColors.BOLD_BLUE
keyword_constant: str = ANSIColors.BOLD_BLUE
builtin: str = ANSIColors.CYAN
comment: str = ANSIColors.RED
string: str = ANSIColors.GREEN
number: str = ANSIColors.YELLOW
op: str = ANSIColors.RESET
definition: str = ANSIColors.BOLD
soft_keyword: str = ANSIColors.BOLD_BLUE
reset: str = ANSIColors.RESET
@dataclass(frozen=True)
class Traceback(ThemeSection):
type: str = ANSIColors.BOLD_MAGENTA
message: str = ANSIColors.MAGENTA
filename: str = ANSIColors.MAGENTA
line_no: str = ANSIColors.MAGENTA
frame: str = ANSIColors.MAGENTA
error_highlight: str = ANSIColors.BOLD_RED
error_range: str = ANSIColors.RED
reset: str = ANSIColors.RESET
@dataclass(frozen=True)
class Unittest(ThemeSection):
passed: str = ANSIColors.GREEN
warn: str = ANSIColors.YELLOW
fail: str = ANSIColors.RED
fail_info: str = ANSIColors.BOLD_RED
reset: str = ANSIColors.RESET
@dataclass(frozen=True)
class Theme:
"""A suite of themes for all sections of Python.
When adding a new one, remember to also modify `copy_with` and `no_colors`
below.
"""
argparse: Argparse = field(default_factory=Argparse)
syntax: Syntax = field(default_factory=Syntax)
traceback: Traceback = field(default_factory=Traceback)
unittest: Unittest = field(default_factory=Unittest)
def copy_with(
self,
*,
argparse: Argparse | None = None,
syntax: Syntax | None = None,
traceback: Traceback | None = None,
unittest: Unittest | None = None,
) -> Self:
"""Return a new Theme based on this instance with some sections replaced.
Themes are immutable to protect against accidental modifications that
could lead to invalid terminal states.
"""
return type(self)(
argparse=argparse or self.argparse,
syntax=syntax or self.syntax,
traceback=traceback or self.traceback,
unittest=unittest or self.unittest,
)
@classmethod
def no_colors(cls) -> Self:
"""Return a new Theme where colors in all sections are empty strings.
This allows writing user code as if colors are always used. The color
fields will be ANSI color code strings when colorization is desired
and possible, and empty strings otherwise.
"""
return cls(
argparse=Argparse.no_colors(),
syntax=Syntax.no_colors(),
traceback=Traceback.no_colors(),
unittest=Unittest.no_colors(),
)
def get_colors(
colorize: bool = False, *, file: IO[str] | IO[bytes] | None = None
) -> ANSIColors:
if colorize or can_colorize(file=file):
return ANSIColors()
else:
return NoColors
def decolor(text: str) -> str:
"""Remove ANSI color codes from a string."""
for code in ColorCodes:
text = text.replace(code, "")
return text
def can_colorize(*, file: IO[str] | IO[bytes] | None = None) -> bool:
def _safe_getenv(k: str, fallback: str | None = None) -> str | None:
"""Exception-safe environment retrieval. See gh-128636."""
try:
return os.environ.get(k, fallback)
except Exception:
return fallback
if file is None:
file = sys.stdout
if not sys.flags.ignore_environment:
if _safe_getenv("PYTHON_COLORS") == "0":
return False
if _safe_getenv("PYTHON_COLORS") == "1":
return True
if _safe_getenv("NO_COLOR"):
return False
if not COLORIZE:
return False
if _safe_getenv("FORCE_COLOR"):
return True
if _safe_getenv("TERM") == "dumb":
return False
if not hasattr(file, "fileno"):
return False
if sys.platform == "win32":
try:
import nt
if not nt._supports_virtual_terminal():
return False
except (ImportError, AttributeError):
return False
try:
return os.isatty(file.fileno())
except OSError:
return hasattr(file, "isatty") and file.isatty()
default_theme = Theme()
theme_no_color = default_theme.no_colors()
def get_theme(
*,
tty_file: IO[str] | IO[bytes] | None = None,
force_color: bool = False,
force_no_color: bool = False,
) -> Theme:
"""Returns the currently set theme, potentially in a zero-color variant.
In cases where colorizing is not possible (see `can_colorize`), the returned
theme contains all empty strings in all color definitions.
See `Theme.no_colors()` for more information.
It is recommended not to cache the result of this function for extended
periods of time because the user might influence theme selection by
the interactive shell, a debugger, or application-specific code. The
environment (including environment variable state and console configuration
on Windows) can also change in the course of the application life cycle.
"""
if force_color or (not force_no_color and
can_colorize(file=tty_file)):
return _theme
return theme_no_color
def set_theme(t: Theme) -> None:
global _theme
if not isinstance(t, Theme):
raise ValueError(f"Expected Theme object, found {t}")
_theme = t
set_theme(default_theme)

View File

@@ -22,7 +22,6 @@ IMPORT_MAPPING = {
'tkMessageBox': 'tkinter.messagebox',
'ScrolledText': 'tkinter.scrolledtext',
'Tkconstants': 'tkinter.constants',
'Tix': 'tkinter.tix',
'ttk': 'tkinter.ttk',
'Tkinter': 'tkinter',
'markupbase': '_markupbase',
@@ -257,3 +256,4 @@ PYTHON3_IMPORTERROR_EXCEPTIONS = (
for excname in PYTHON3_IMPORTERROR_EXCEPTIONS:
REVERSE_NAME_MAPPING[('builtins', excname)] = ('exceptions', 'ImportError')
del excname

22
Lib/_dummy_os.py vendored
View File

@@ -5,22 +5,30 @@ A shim of the os module containing only simple path-related utilities
try:
from os import *
except ImportError:
import abc
import abc, sys
def __getattr__(name):
raise OSError("no os specific module found")
if name in {"_path_normpath", "__path__"}:
raise AttributeError(name)
if name.isupper():
return 0
def dummy(*args, **kwargs):
import io
return io.UnsupportedOperation(f"{name}: no os specific module found")
dummy.__name__ = f"dummy_{name}"
return dummy
def _shim():
import _dummy_os, sys
sys.modules['os'] = _dummy_os
sys.modules['os.path'] = _dummy_os.path
sys.modules['os'] = sys.modules['posix'] = sys.modules[__name__]
import posixpath as path
import sys
sys.modules['os.path'] = path
del sys
sep = path.sep
supports_dir_fd = set()
supports_effective_ids = set()
supports_fd = set()
supports_follow_symlinks = set()
def fspath(path):

149
Lib/_dummy_thread.py vendored
View File

@@ -11,15 +11,35 @@ Suggested usage is::
import _dummy_thread as _thread
"""
# Exports only things specified by thread documentation;
# skipping obsolete synonyms allocate(), start_new(), exit_thread().
__all__ = ['error', 'start_new_thread', 'exit', 'get_ident', 'allocate_lock',
'interrupt_main', 'LockType', 'RLock',
'_count']
__all__ = [
"error",
"start_new_thread",
"exit",
"get_ident",
"allocate_lock",
"interrupt_main",
"LockType",
"RLock",
"_count",
"start_joinable_thread",
"daemon_threads_allowed",
"_shutdown",
"_make_thread_handle",
"_ThreadHandle",
"_get_main_thread_ident",
"_is_main_interpreter",
"_local",
]
# A dummy value
TIMEOUT_MAX = 2**31
# Main thread ident for dummy implementation
_MAIN_THREAD_IDENT = -1
# NOTE: this module can be imported early in the extension building process,
# and so top level imports of other modules should be avoided. Instead, all
# imports are done when needed on a function-by-function basis. Since threads
@@ -27,6 +47,7 @@ TIMEOUT_MAX = 2**31
error = RuntimeError
def start_new_thread(function, args, kwargs={}):
"""Dummy implementation of _thread.start_new_thread().
@@ -52,6 +73,7 @@ def start_new_thread(function, args, kwargs={}):
pass
except:
import traceback
traceback.print_exc()
_main = True
global _interrupt
@@ -59,10 +81,58 @@ def start_new_thread(function, args, kwargs={}):
_interrupt = False
raise KeyboardInterrupt
def start_joinable_thread(function, handle=None, daemon=True):
"""Dummy implementation of _thread.start_joinable_thread().
In dummy thread, we just run the function synchronously.
"""
if handle is None:
handle = _ThreadHandle()
try:
function()
except SystemExit:
pass
except:
import traceback
traceback.print_exc()
handle._set_done()
return handle
def daemon_threads_allowed():
"""Dummy implementation of _thread.daemon_threads_allowed()."""
return True
def _shutdown():
"""Dummy implementation of _thread._shutdown()."""
pass
def _make_thread_handle(ident):
"""Dummy implementation of _thread._make_thread_handle()."""
handle = _ThreadHandle()
handle._ident = ident
return handle
def _get_main_thread_ident():
"""Dummy implementation of _thread._get_main_thread_ident()."""
return _MAIN_THREAD_IDENT
def _is_main_interpreter():
"""Dummy implementation of _thread._is_main_interpreter()."""
return True
def exit():
"""Dummy implementation of _thread.exit()."""
raise SystemExit
def get_ident():
"""Dummy implementation of _thread.get_ident().
@@ -70,26 +140,31 @@ def get_ident():
available, it is safe to assume that the current process is the
only thread. Thus a constant can be safely returned.
"""
return -1
return _MAIN_THREAD_IDENT
def allocate_lock():
"""Dummy implementation of _thread.allocate_lock()."""
return LockType()
def stack_size(size=None):
"""Dummy implementation of _thread.stack_size()."""
if size is not None:
raise error("setting thread stack size not supported")
return 0
def _set_sentinel():
"""Dummy implementation of _thread._set_sentinel()."""
return LockType()
def _count():
"""Dummy implementation of _thread._count()."""
return 0
class LockType(object):
"""Class implementing dummy implementation of _thread.LockType.
@@ -125,6 +200,7 @@ class LockType(object):
else:
if timeout > 0:
import time
time.sleep(timeout)
return False
@@ -153,14 +229,41 @@ class LockType(object):
"locked" if self.locked_status else "unlocked",
self.__class__.__module__,
self.__class__.__qualname__,
hex(id(self))
hex(id(self)),
)
class _ThreadHandle:
"""Dummy implementation of _thread._ThreadHandle."""
def __init__(self):
self._ident = _MAIN_THREAD_IDENT
self._done = False
@property
def ident(self):
return self._ident
def _set_done(self):
self._done = True
def is_done(self):
return self._done
def join(self, timeout=None):
# In dummy thread, thread is always done
return
def __repr__(self):
return f"<_ThreadHandle ident={self._ident}>"
# Used to signal that interrupt_main was called in a "thread"
_interrupt = False
# True when not executing in a "thread"
_main = True
def interrupt_main():
"""Set _interrupt flag to True to have start_new_thread raise
KeyboardInterrupt upon exiting."""
@@ -170,6 +273,7 @@ def interrupt_main():
global _interrupt
_interrupt = True
class RLock:
def __init__(self):
self.locked_count = 0
@@ -190,7 +294,7 @@ class RLock:
return True
def locked(self):
return self.locked_status != 0
return self.locked_count != 0
def __repr__(self):
return "<%s %s.%s object owner=%s count=%s at %s>" % (
@@ -199,5 +303,36 @@ class RLock:
self.__class__.__qualname__,
get_ident() if self.locked_count else 0,
self.locked_count,
hex(id(self))
hex(id(self)),
)
class _local:
"""Dummy implementation of _thread._local (thread-local storage)."""
def __init__(self):
object.__setattr__(self, "_local__impl", {})
def __getattribute__(self, name):
if name.startswith("_local__"):
return object.__getattribute__(self, name)
impl = object.__getattribute__(self, "_local__impl")
try:
return impl[name]
except KeyError:
raise AttributeError(name)
def __setattr__(self, name, value):
if name.startswith("_local__"):
return object.__setattr__(self, name, value)
impl = object.__getattribute__(self, "_local__impl")
impl[name] = value
def __delattr__(self, name):
if name.startswith("_local__"):
return object.__delattr__(self, name)
impl = object.__getattribute__(self, "_local__impl")
try:
del impl[name]
except KeyError:
raise AttributeError(name)

71
Lib/_ios_support.py vendored Normal file
View File

@@ -0,0 +1,71 @@
import sys
try:
from ctypes import cdll, c_void_p, c_char_p, util
except ImportError:
# ctypes is an optional module. If it's not present, we're limited in what
# we can tell about the system, but we don't want to prevent the module
# from working.
print("ctypes isn't available; iOS system calls will not be available", file=sys.stderr)
objc = None
else:
# ctypes is available. Load the ObjC library, and wrap the objc_getClass,
# sel_registerName methods
lib = util.find_library("objc")
if lib is None:
# Failed to load the objc library
raise ImportError("ObjC runtime library couldn't be loaded")
objc = cdll.LoadLibrary(lib)
objc.objc_getClass.restype = c_void_p
objc.objc_getClass.argtypes = [c_char_p]
objc.sel_registerName.restype = c_void_p
objc.sel_registerName.argtypes = [c_char_p]
def get_platform_ios():
# Determine if this is a simulator using the multiarch value
is_simulator = sys.implementation._multiarch.endswith("simulator")
# We can't use ctypes; abort
if not objc:
return None
# Most of the methods return ObjC objects
objc.objc_msgSend.restype = c_void_p
# All the methods used have no arguments.
objc.objc_msgSend.argtypes = [c_void_p, c_void_p]
# Equivalent of:
# device = [UIDevice currentDevice]
UIDevice = objc.objc_getClass(b"UIDevice")
SEL_currentDevice = objc.sel_registerName(b"currentDevice")
device = objc.objc_msgSend(UIDevice, SEL_currentDevice)
# Equivalent of:
# device_systemVersion = [device systemVersion]
SEL_systemVersion = objc.sel_registerName(b"systemVersion")
device_systemVersion = objc.objc_msgSend(device, SEL_systemVersion)
# Equivalent of:
# device_systemName = [device systemName]
SEL_systemName = objc.sel_registerName(b"systemName")
device_systemName = objc.objc_msgSend(device, SEL_systemName)
# Equivalent of:
# device_model = [device model]
SEL_model = objc.sel_registerName(b"model")
device_model = objc.objc_msgSend(device, SEL_model)
# UTF8String returns a const char*;
SEL_UTF8String = objc.sel_registerName(b"UTF8String")
objc.objc_msgSend.restype = c_char_p
# Equivalent of:
# system = [device_systemName UTF8String]
# release = [device_systemVersion UTF8String]
# model = [device_model UTF8String]
system = objc.objc_msgSend(device_systemName, SEL_UTF8String).decode()
release = objc.objc_msgSend(device_systemVersion, SEL_UTF8String).decode()
model = objc.objc_msgSend(device_model, SEL_UTF8String).decode()
return system, release, model, is_simulator

2
Lib/_markupbase.py vendored
View File

@@ -13,7 +13,7 @@ _commentclose = re.compile(r'--\s*>')
_markedsectionclose = re.compile(r']\s*]\s*>')
# An analysis of the MS-Word extensions is available at
# http://www.planetpublish.com/xmlarena/xap/Thursday/WordtoXML.pdf
# http://web.archive.org/web/20060321153828/http://www.planetpublish.com/xmlarena/xap/Thursday/WordtoXML.pdf
_msmarkedsectionclose = re.compile(r']\s*>')

371
Lib/_opcode_metadata.py generated vendored Normal file
View File

@@ -0,0 +1,371 @@
# This file is generated by tools/opcode_metadata/generate_py_opcode_metadata.py
# for RustPython bytecode format (CPython 3.14 compatible opcode numbers).
# Do not edit!
_specializations = {
"RESUME": [
"RESUME_CHECK",
],
"LOAD_CONST": [
"LOAD_CONST_MORTAL",
"LOAD_CONST_IMMORTAL",
],
"TO_BOOL": [
"TO_BOOL_ALWAYS_TRUE",
"TO_BOOL_BOOL",
"TO_BOOL_INT",
"TO_BOOL_LIST",
"TO_BOOL_NONE",
"TO_BOOL_STR",
],
"BINARY_OP": [
"BINARY_OP_MULTIPLY_INT",
"BINARY_OP_ADD_INT",
"BINARY_OP_SUBTRACT_INT",
"BINARY_OP_MULTIPLY_FLOAT",
"BINARY_OP_ADD_FLOAT",
"BINARY_OP_SUBTRACT_FLOAT",
"BINARY_OP_ADD_UNICODE",
"BINARY_OP_SUBSCR_LIST_INT",
"BINARY_OP_SUBSCR_LIST_SLICE",
"BINARY_OP_SUBSCR_TUPLE_INT",
"BINARY_OP_SUBSCR_STR_INT",
"BINARY_OP_SUBSCR_DICT",
"BINARY_OP_SUBSCR_GETITEM",
"BINARY_OP_EXTEND",
"BINARY_OP_INPLACE_ADD_UNICODE",
],
"STORE_SUBSCR": [
"STORE_SUBSCR_DICT",
"STORE_SUBSCR_LIST_INT",
],
"SEND": [
"SEND_GEN",
],
"UNPACK_SEQUENCE": [
"UNPACK_SEQUENCE_TWO_TUPLE",
"UNPACK_SEQUENCE_TUPLE",
"UNPACK_SEQUENCE_LIST",
],
"STORE_ATTR": [
"STORE_ATTR_INSTANCE_VALUE",
"STORE_ATTR_SLOT",
"STORE_ATTR_WITH_HINT",
],
"LOAD_GLOBAL": [
"LOAD_GLOBAL_MODULE",
"LOAD_GLOBAL_BUILTIN",
],
"LOAD_SUPER_ATTR": [
"LOAD_SUPER_ATTR_ATTR",
"LOAD_SUPER_ATTR_METHOD",
],
"LOAD_ATTR": [
"LOAD_ATTR_INSTANCE_VALUE",
"LOAD_ATTR_MODULE",
"LOAD_ATTR_WITH_HINT",
"LOAD_ATTR_SLOT",
"LOAD_ATTR_CLASS",
"LOAD_ATTR_CLASS_WITH_METACLASS_CHECK",
"LOAD_ATTR_PROPERTY",
"LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN",
"LOAD_ATTR_METHOD_WITH_VALUES",
"LOAD_ATTR_METHOD_NO_DICT",
"LOAD_ATTR_METHOD_LAZY_DICT",
"LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES",
"LOAD_ATTR_NONDESCRIPTOR_NO_DICT",
],
"COMPARE_OP": [
"COMPARE_OP_FLOAT",
"COMPARE_OP_INT",
"COMPARE_OP_STR",
],
"CONTAINS_OP": [
"CONTAINS_OP_SET",
"CONTAINS_OP_DICT",
],
"JUMP_BACKWARD": [
"JUMP_BACKWARD_NO_JIT",
"JUMP_BACKWARD_JIT",
],
"FOR_ITER": [
"FOR_ITER_LIST",
"FOR_ITER_TUPLE",
"FOR_ITER_RANGE",
"FOR_ITER_GEN",
],
"CALL": [
"CALL_BOUND_METHOD_EXACT_ARGS",
"CALL_PY_EXACT_ARGS",
"CALL_TYPE_1",
"CALL_STR_1",
"CALL_TUPLE_1",
"CALL_BUILTIN_CLASS",
"CALL_BUILTIN_O",
"CALL_BUILTIN_FAST",
"CALL_BUILTIN_FAST_WITH_KEYWORDS",
"CALL_LEN",
"CALL_ISINSTANCE",
"CALL_LIST_APPEND",
"CALL_METHOD_DESCRIPTOR_O",
"CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS",
"CALL_METHOD_DESCRIPTOR_NOARGS",
"CALL_METHOD_DESCRIPTOR_FAST",
"CALL_ALLOC_AND_ENTER_INIT",
"CALL_PY_GENERAL",
"CALL_BOUND_METHOD_GENERAL",
"CALL_NON_PY_GENERAL",
],
"CALL_KW": [
"CALL_KW_BOUND_METHOD",
"CALL_KW_PY",
"CALL_KW_NON_PY",
],
}
_specialized_opmap = {
'BINARY_OP_ADD_FLOAT': 129,
'BINARY_OP_ADD_INT': 130,
'BINARY_OP_ADD_UNICODE': 131,
'BINARY_OP_EXTEND': 132,
'BINARY_OP_INPLACE_ADD_UNICODE': 3,
'BINARY_OP_MULTIPLY_FLOAT': 133,
'BINARY_OP_MULTIPLY_INT': 134,
'BINARY_OP_SUBSCR_DICT': 135,
'BINARY_OP_SUBSCR_GETITEM': 136,
'BINARY_OP_SUBSCR_LIST_INT': 137,
'BINARY_OP_SUBSCR_LIST_SLICE': 138,
'BINARY_OP_SUBSCR_STR_INT': 139,
'BINARY_OP_SUBSCR_TUPLE_INT': 140,
'BINARY_OP_SUBTRACT_FLOAT': 141,
'BINARY_OP_SUBTRACT_INT': 142,
'CALL_ALLOC_AND_ENTER_INIT': 143,
'CALL_BOUND_METHOD_EXACT_ARGS': 144,
'CALL_BOUND_METHOD_GENERAL': 145,
'CALL_BUILTIN_CLASS': 146,
'CALL_BUILTIN_FAST': 147,
'CALL_BUILTIN_FAST_WITH_KEYWORDS': 148,
'CALL_BUILTIN_O': 149,
'CALL_ISINSTANCE': 150,
'CALL_KW_BOUND_METHOD': 151,
'CALL_KW_NON_PY': 152,
'CALL_KW_PY': 153,
'CALL_LEN': 154,
'CALL_LIST_APPEND': 155,
'CALL_METHOD_DESCRIPTOR_FAST': 156,
'CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS': 157,
'CALL_METHOD_DESCRIPTOR_NOARGS': 158,
'CALL_METHOD_DESCRIPTOR_O': 159,
'CALL_NON_PY_GENERAL': 160,
'CALL_PY_EXACT_ARGS': 161,
'CALL_PY_GENERAL': 162,
'CALL_STR_1': 163,
'CALL_TUPLE_1': 164,
'CALL_TYPE_1': 165,
'COMPARE_OP_FLOAT': 166,
'COMPARE_OP_INT': 167,
'COMPARE_OP_STR': 168,
'CONTAINS_OP_DICT': 169,
'CONTAINS_OP_SET': 170,
'FOR_ITER_GEN': 171,
'FOR_ITER_LIST': 172,
'FOR_ITER_RANGE': 173,
'FOR_ITER_TUPLE': 174,
'JUMP_BACKWARD_JIT': 175,
'JUMP_BACKWARD_NO_JIT': 176,
'LOAD_ATTR_CLASS': 177,
'LOAD_ATTR_CLASS_WITH_METACLASS_CHECK': 178,
'LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN': 179,
'LOAD_ATTR_INSTANCE_VALUE': 180,
'LOAD_ATTR_METHOD_LAZY_DICT': 181,
'LOAD_ATTR_METHOD_NO_DICT': 182,
'LOAD_ATTR_METHOD_WITH_VALUES': 183,
'LOAD_ATTR_MODULE': 184,
'LOAD_ATTR_NONDESCRIPTOR_NO_DICT': 185,
'LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES': 186,
'LOAD_ATTR_PROPERTY': 187,
'LOAD_ATTR_SLOT': 188,
'LOAD_ATTR_WITH_HINT': 189,
'LOAD_CONST_IMMORTAL': 190,
'LOAD_CONST_MORTAL': 191,
'LOAD_GLOBAL_BUILTIN': 192,
'LOAD_GLOBAL_MODULE': 193,
'LOAD_SUPER_ATTR_ATTR': 194,
'LOAD_SUPER_ATTR_METHOD': 195,
'RESUME_CHECK': 196,
'SEND_GEN': 197,
'STORE_ATTR_INSTANCE_VALUE': 198,
'STORE_ATTR_SLOT': 199,
'STORE_ATTR_WITH_HINT': 200,
'STORE_SUBSCR_DICT': 201,
'STORE_SUBSCR_LIST_INT': 202,
'TO_BOOL_ALWAYS_TRUE': 203,
'TO_BOOL_BOOL': 204,
'TO_BOOL_INT': 205,
'TO_BOOL_LIST': 206,
'TO_BOOL_NONE': 207,
'TO_BOOL_STR': 208,
'UNPACK_SEQUENCE_LIST': 209,
'UNPACK_SEQUENCE_TUPLE': 210,
'UNPACK_SEQUENCE_TWO_TUPLE': 211,
}
opmap = {
'CACHE': 0,
'RESERVED': 17,
'RESUME': 128,
'INSTRUMENTED_LINE': 254,
'ENTER_EXECUTOR': 255,
'BINARY_SLICE': 1,
'BUILD_TEMPLATE': 2,
'CALL_FUNCTION_EX': 4,
'CHECK_EG_MATCH': 5,
'CHECK_EXC_MATCH': 6,
'CLEANUP_THROW': 7,
'DELETE_SUBSCR': 8,
'END_FOR': 9,
'END_SEND': 10,
'EXIT_INIT_CHECK': 11,
'FORMAT_SIMPLE': 12,
'FORMAT_WITH_SPEC': 13,
'GET_AITER': 14,
'GET_ANEXT': 15,
'GET_ITER': 16,
'GET_LEN': 18,
'GET_YIELD_FROM_ITER': 19,
'INTERPRETER_EXIT': 20,
'LOAD_BUILD_CLASS': 21,
'LOAD_LOCALS': 22,
'MAKE_FUNCTION': 23,
'MATCH_KEYS': 24,
'MATCH_MAPPING': 25,
'MATCH_SEQUENCE': 26,
'NOP': 27,
'NOT_TAKEN': 28,
'POP_EXCEPT': 29,
'POP_ITER': 30,
'POP_TOP': 31,
'PUSH_EXC_INFO': 32,
'PUSH_NULL': 33,
'RETURN_GENERATOR': 34,
'RETURN_VALUE': 35,
'SETUP_ANNOTATIONS': 36,
'STORE_SLICE': 37,
'STORE_SUBSCR': 38,
'TO_BOOL': 39,
'UNARY_INVERT': 40,
'UNARY_NEGATIVE': 41,
'UNARY_NOT': 42,
'WITH_EXCEPT_START': 43,
'BINARY_OP': 44,
'BUILD_INTERPOLATION': 45,
'BUILD_LIST': 46,
'BUILD_MAP': 47,
'BUILD_SET': 48,
'BUILD_SLICE': 49,
'BUILD_STRING': 50,
'BUILD_TUPLE': 51,
'CALL': 52,
'CALL_INTRINSIC_1': 53,
'CALL_INTRINSIC_2': 54,
'CALL_KW': 55,
'COMPARE_OP': 56,
'CONTAINS_OP': 57,
'CONVERT_VALUE': 58,
'COPY': 59,
'COPY_FREE_VARS': 60,
'DELETE_ATTR': 61,
'DELETE_DEREF': 62,
'DELETE_FAST': 63,
'DELETE_GLOBAL': 64,
'DELETE_NAME': 65,
'DICT_MERGE': 66,
'DICT_UPDATE': 67,
'END_ASYNC_FOR': 68,
'EXTENDED_ARG': 69,
'FOR_ITER': 70,
'GET_AWAITABLE': 71,
'IMPORT_FROM': 72,
'IMPORT_NAME': 73,
'IS_OP': 74,
'JUMP_BACKWARD': 75,
'JUMP_BACKWARD_NO_INTERRUPT': 76,
'JUMP_FORWARD': 77,
'LIST_APPEND': 78,
'LIST_EXTEND': 79,
'LOAD_ATTR': 80,
'LOAD_COMMON_CONSTANT': 81,
'LOAD_CONST': 82,
'LOAD_DEREF': 83,
'LOAD_FAST': 84,
'LOAD_FAST_AND_CLEAR': 85,
'LOAD_FAST_BORROW': 86,
'LOAD_FAST_BORROW_LOAD_FAST_BORROW': 87,
'LOAD_FAST_CHECK': 88,
'LOAD_FAST_LOAD_FAST': 89,
'LOAD_FROM_DICT_OR_DEREF': 90,
'LOAD_FROM_DICT_OR_GLOBALS': 91,
'LOAD_GLOBAL': 92,
'LOAD_NAME': 93,
'LOAD_SMALL_INT': 94,
'LOAD_SPECIAL': 95,
'LOAD_SUPER_ATTR': 96,
'MAKE_CELL': 97,
'MAP_ADD': 98,
'MATCH_CLASS': 99,
'POP_JUMP_IF_FALSE': 100,
'POP_JUMP_IF_NONE': 101,
'POP_JUMP_IF_NOT_NONE': 102,
'POP_JUMP_IF_TRUE': 103,
'RAISE_VARARGS': 104,
'RERAISE': 105,
'SEND': 106,
'SET_ADD': 107,
'SET_FUNCTION_ATTRIBUTE': 108,
'SET_UPDATE': 109,
'STORE_ATTR': 110,
'STORE_DEREF': 111,
'STORE_FAST': 112,
'STORE_FAST_LOAD_FAST': 113,
'STORE_FAST_STORE_FAST': 114,
'STORE_GLOBAL': 115,
'STORE_NAME': 116,
'SWAP': 117,
'UNPACK_EX': 118,
'UNPACK_SEQUENCE': 119,
'YIELD_VALUE': 120,
'INSTRUMENTED_END_FOR': 234,
'INSTRUMENTED_POP_ITER': 235,
'INSTRUMENTED_END_SEND': 236,
'INSTRUMENTED_FOR_ITER': 237,
'INSTRUMENTED_INSTRUCTION': 238,
'INSTRUMENTED_JUMP_FORWARD': 239,
'INSTRUMENTED_NOT_TAKEN': 240,
'INSTRUMENTED_POP_JUMP_IF_TRUE': 241,
'INSTRUMENTED_POP_JUMP_IF_FALSE': 242,
'INSTRUMENTED_POP_JUMP_IF_NONE': 243,
'INSTRUMENTED_POP_JUMP_IF_NOT_NONE': 244,
'INSTRUMENTED_RESUME': 245,
'INSTRUMENTED_RETURN_VALUE': 246,
'INSTRUMENTED_YIELD_VALUE': 247,
'INSTRUMENTED_END_ASYNC_FOR': 248,
'INSTRUMENTED_LOAD_SUPER_ATTR': 249,
'INSTRUMENTED_CALL': 250,
'INSTRUMENTED_CALL_KW': 251,
'INSTRUMENTED_CALL_FUNCTION_EX': 252,
'INSTRUMENTED_JUMP_BACKWARD': 253,
'ANNOTATIONS_PLACEHOLDER': 256,
'JUMP': 257,
'JUMP_IF_FALSE': 258,
'JUMP_IF_TRUE': 259,
'JUMP_NO_INTERRUPT': 260,
'LOAD_CLOSURE': 261,
'POP_BLOCK': 262,
'SETUP_CLEANUP': 263,
'SETUP_FINALLY': 264,
'SETUP_WITH': 265,
'STORE_FAST_MAYBE_NULL': 266,
}
HAVE_ARGUMENT = 43
MIN_INSTRUMENTED_OPCODE = 234

5
Lib/_osx_support.py vendored
View File

@@ -507,6 +507,11 @@ def get_platform_osx(_config_vars, osname, release, machine):
# MACOSX_DEPLOYMENT_TARGET.
macver = _config_vars.get('MACOSX_DEPLOYMENT_TARGET', '')
if macver and '.' not in macver:
# Ensure that the version includes at least a major
# and minor version, even if MACOSX_DEPLOYMENT_TARGET
# is set to a single-label version like "14".
macver += '.0'
macrelease = _get_system_version() or macver
macver = macver or macrelease

869
Lib/_py_warnings.py vendored Normal file
View File

@@ -0,0 +1,869 @@
"""Python part of the warnings subsystem."""
import sys
import _contextvars
import _thread
__all__ = ["warn", "warn_explicit", "showwarning",
"formatwarning", "filterwarnings", "simplefilter",
"resetwarnings", "catch_warnings", "deprecated"]
# Normally '_wm' is sys.modules['warnings'] but for unit tests it can be
# a different module. User code is allowed to reassign global attributes
# of the 'warnings' module, commonly 'filters' or 'showwarning'. So we
# need to lookup these global attributes dynamically on the '_wm' object,
# rather than binding them earlier. The code in this module consistently uses
# '_wm.<something>' rather than using the globals of this module. If the
# '_warnings' C extension is in use, some globals are replaced by functions
# and variables defined in that extension.
_wm = None
def _set_module(module):
global _wm
_wm = module
# filters contains a sequence of filter 5-tuples
# The components of the 5-tuple are:
# - an action: error, ignore, always, all, default, module, or once
# - a compiled regex that must match the warning message
# - a class representing the warning category
# - a compiled regex that must match the module that is being warned
# - a line number for the line being warning, or 0 to mean any line
# If either if the compiled regexs are None, match anything.
filters = []
defaultaction = "default"
onceregistry = {}
_lock = _thread.RLock()
_filters_version = 1
# If true, catch_warnings() will use a context var to hold the modified
# filters list. Otherwise, catch_warnings() will operate on the 'filters'
# global of the warnings module.
_use_context = sys.flags.context_aware_warnings
class _Context:
def __init__(self, filters):
self._filters = filters
self.log = None # if set to a list, logging is enabled
def copy(self):
context = _Context(self._filters[:])
if self.log is not None:
context.log = self.log
return context
def _record_warning(self, msg):
self.log.append(msg)
class _GlobalContext(_Context):
def __init__(self):
self.log = None
@property
def _filters(self):
# Since there is quite a lot of code that assigns to
# warnings.filters, this needs to return the current value of
# the module global.
try:
return _wm.filters
except AttributeError:
# 'filters' global was deleted. Do we need to actually handle this case?
return []
_global_context = _GlobalContext()
_warnings_context = _contextvars.ContextVar('warnings_context')
def _get_context():
if not _use_context:
return _global_context
try:
return _wm._warnings_context.get()
except LookupError:
return _global_context
def _set_context(context):
assert _use_context
_wm._warnings_context.set(context)
def _new_context():
assert _use_context
old_context = _wm._get_context()
new_context = old_context.copy()
_wm._set_context(new_context)
return old_context, new_context
def _get_filters():
"""Return the current list of filters. This is a non-public API used by
module functions and by the unit tests."""
return _wm._get_context()._filters
def _filters_mutated_lock_held():
_wm._filters_version += 1
def showwarning(message, category, filename, lineno, file=None, line=None):
"""Hook to write a warning to a file; replace if you like."""
msg = _wm.WarningMessage(message, category, filename, lineno, file, line)
_wm._showwarnmsg_impl(msg)
def formatwarning(message, category, filename, lineno, line=None):
"""Function to format a warning the standard way."""
msg = _wm.WarningMessage(message, category, filename, lineno, None, line)
return _wm._formatwarnmsg_impl(msg)
def _showwarnmsg_impl(msg):
context = _wm._get_context()
if context.log is not None:
context._record_warning(msg)
return
file = msg.file
if file is None:
file = sys.stderr
if file is None:
# sys.stderr is None when run with pythonw.exe:
# warnings get lost
return
text = _wm._formatwarnmsg(msg)
try:
file.write(text)
except OSError:
# the file (probably stderr) is invalid - this warning gets lost.
pass
def _formatwarnmsg_impl(msg):
category = msg.category.__name__
s = f"{msg.filename}:{msg.lineno}: {category}: {msg.message}\n"
if msg.line is None:
try:
import linecache
line = linecache.getline(msg.filename, msg.lineno)
except Exception:
# When a warning is logged during Python shutdown, linecache
# and the import machinery don't work anymore
line = None
linecache = None
else:
line = msg.line
if line:
line = line.strip()
s += " %s\n" % line
if msg.source is not None:
try:
import tracemalloc
# Logging a warning should not raise a new exception:
# catch Exception, not only ImportError and RecursionError.
except Exception:
# don't suggest to enable tracemalloc if it's not available
suggest_tracemalloc = False
tb = None
else:
try:
suggest_tracemalloc = not tracemalloc.is_tracing()
tb = tracemalloc.get_object_traceback(msg.source)
except Exception:
# When a warning is logged during Python shutdown, tracemalloc
# and the import machinery don't work anymore
suggest_tracemalloc = False
tb = None
if tb is not None:
s += 'Object allocated at (most recent call last):\n'
for frame in tb:
s += (' File "%s", lineno %s\n'
% (frame.filename, frame.lineno))
try:
if linecache is not None:
line = linecache.getline(frame.filename, frame.lineno)
else:
line = None
except Exception:
line = None
if line:
line = line.strip()
s += ' %s\n' % line
elif suggest_tracemalloc:
s += (f'{category}: Enable tracemalloc to get the object '
f'allocation traceback\n')
return s
# Keep a reference to check if the function was replaced
_showwarning_orig = showwarning
def _showwarnmsg(msg):
"""Hook to write a warning to a file; replace if you like."""
try:
sw = _wm.showwarning
except AttributeError:
pass
else:
if sw is not _showwarning_orig:
# warnings.showwarning() was replaced
if not callable(sw):
raise TypeError("warnings.showwarning() must be set to a "
"function or method")
sw(msg.message, msg.category, msg.filename, msg.lineno,
msg.file, msg.line)
return
_wm._showwarnmsg_impl(msg)
# Keep a reference to check if the function was replaced
_formatwarning_orig = formatwarning
def _formatwarnmsg(msg):
"""Function to format a warning the standard way."""
try:
fw = _wm.formatwarning
except AttributeError:
pass
else:
if fw is not _formatwarning_orig:
# warnings.formatwarning() was replaced
return fw(msg.message, msg.category,
msg.filename, msg.lineno, msg.line)
return _wm._formatwarnmsg_impl(msg)
def filterwarnings(action, message="", category=Warning, module="", lineno=0,
append=False):
"""Insert an entry into the list of warnings filters (at the front).
'action' -- one of "error", "ignore", "always", "all", "default", "module",
or "once"
'message' -- a regex that the warning message must match
'category' -- a class that the warning must be a subclass of
'module' -- a regex that the module name must match
'lineno' -- an integer line number, 0 matches all warnings
'append' -- if true, append to the list of filters
"""
if action not in {"error", "ignore", "always", "all", "default", "module", "once"}:
raise ValueError(f"invalid action: {action!r}")
if not isinstance(message, str):
raise TypeError("message must be a string")
if not isinstance(category, type) or not issubclass(category, Warning):
raise TypeError("category must be a Warning subclass")
if not isinstance(module, str):
raise TypeError("module must be a string")
if not isinstance(lineno, int):
raise TypeError("lineno must be an int")
if lineno < 0:
raise ValueError("lineno must be an int >= 0")
if message or module:
import re
if message:
message = re.compile(message, re.I)
else:
message = None
if module:
module = re.compile(module)
else:
module = None
_wm._add_filter(action, message, category, module, lineno, append=append)
def simplefilter(action, category=Warning, lineno=0, append=False):
"""Insert a simple entry into the list of warnings filters (at the front).
A simple filter matches all modules and messages.
'action' -- one of "error", "ignore", "always", "all", "default", "module",
or "once"
'category' -- a class that the warning must be a subclass of
'lineno' -- an integer line number, 0 matches all warnings
'append' -- if true, append to the list of filters
"""
if action not in {"error", "ignore", "always", "all", "default", "module", "once"}:
raise ValueError(f"invalid action: {action!r}")
if not isinstance(lineno, int):
raise TypeError("lineno must be an int")
if lineno < 0:
raise ValueError("lineno must be an int >= 0")
_wm._add_filter(action, None, category, None, lineno, append=append)
def _filters_mutated():
# Even though this function is not part of the public API, it's used by
# a fair amount of user code.
with _wm._lock:
_wm._filters_mutated_lock_held()
def _add_filter(*item, append):
with _wm._lock:
filters = _wm._get_filters()
if not append:
# Remove possible duplicate filters, so new one will be placed
# in correct place. If append=True and duplicate exists, do nothing.
try:
filters.remove(item)
except ValueError:
pass
filters.insert(0, item)
else:
if item not in filters:
filters.append(item)
_wm._filters_mutated_lock_held()
def resetwarnings():
"""Clear the list of warning filters, so that no filters are active."""
with _wm._lock:
del _wm._get_filters()[:]
_wm._filters_mutated_lock_held()
class _OptionError(Exception):
"""Exception used by option processing helpers."""
pass
# Helper to process -W options passed via sys.warnoptions
def _processoptions(args):
for arg in args:
try:
_wm._setoption(arg)
except _wm._OptionError as msg:
print("Invalid -W option ignored:", msg, file=sys.stderr)
# Helper for _processoptions()
def _setoption(arg):
parts = arg.split(':')
if len(parts) > 5:
raise _wm._OptionError("too many fields (max 5): %r" % (arg,))
while len(parts) < 5:
parts.append('')
action, message, category, module, lineno = [s.strip()
for s in parts]
action = _wm._getaction(action)
category = _wm._getcategory(category)
if message or module:
import re
if message:
message = re.escape(message)
if module:
module = re.escape(module) + r'\z'
if lineno:
try:
lineno = int(lineno)
if lineno < 0:
raise ValueError
except (ValueError, OverflowError):
raise _wm._OptionError("invalid lineno %r" % (lineno,)) from None
else:
lineno = 0
_wm.filterwarnings(action, message, category, module, lineno)
# Helper for _setoption()
def _getaction(action):
if not action:
return "default"
for a in ('default', 'always', 'all', 'ignore', 'module', 'once', 'error'):
if a.startswith(action):
return a
raise _wm._OptionError("invalid action: %r" % (action,))
# Helper for _setoption()
def _getcategory(category):
if not category:
return Warning
if '.' not in category:
import builtins as m
klass = category
else:
module, _, klass = category.rpartition('.')
try:
m = __import__(module, None, None, [klass])
except ImportError:
raise _wm._OptionError("invalid module name: %r" % (module,)) from None
try:
cat = getattr(m, klass)
except AttributeError:
raise _wm._OptionError("unknown warning category: %r" % (category,)) from None
if not issubclass(cat, Warning):
raise _wm._OptionError("invalid warning category: %r" % (category,))
return cat
def _is_internal_filename(filename):
return 'importlib' in filename and '_bootstrap' in filename
def _is_filename_to_skip(filename, skip_file_prefixes):
return any(filename.startswith(prefix) for prefix in skip_file_prefixes)
def _is_internal_frame(frame):
"""Signal whether the frame is an internal CPython implementation detail."""
return _is_internal_filename(frame.f_code.co_filename)
def _next_external_frame(frame, skip_file_prefixes):
"""Find the next frame that doesn't involve Python or user internals."""
frame = frame.f_back
while frame is not None and (
_is_internal_filename(filename := frame.f_code.co_filename) or
_is_filename_to_skip(filename, skip_file_prefixes)):
frame = frame.f_back
return frame
# Code typically replaced by _warnings
def warn(message, category=None, stacklevel=1, source=None,
*, skip_file_prefixes=()):
"""Issue a warning, or maybe ignore it or raise an exception."""
# Check if message is already a Warning object
if isinstance(message, Warning):
category = message.__class__
# Check category argument
if category is None:
category = UserWarning
if not (isinstance(category, type) and issubclass(category, Warning)):
raise TypeError("category must be a Warning subclass, "
"not '{:s}'".format(type(category).__name__))
if not isinstance(skip_file_prefixes, tuple):
# The C version demands a tuple for implementation performance.
raise TypeError('skip_file_prefixes must be a tuple of strs.')
if skip_file_prefixes:
stacklevel = max(2, stacklevel)
# Get context information
try:
if stacklevel <= 1 or _is_internal_frame(sys._getframe(1)):
# If frame is too small to care or if the warning originated in
# internal code, then do not try to hide any frames.
frame = sys._getframe(stacklevel)
else:
frame = sys._getframe(1)
# Look for one frame less since the above line starts us off.
for x in range(stacklevel-1):
frame = _next_external_frame(frame, skip_file_prefixes)
if frame is None:
raise ValueError
except ValueError:
globals = sys.__dict__
filename = "<sys>"
lineno = 0
else:
globals = frame.f_globals
filename = frame.f_code.co_filename
lineno = frame.f_lineno
if '__name__' in globals:
module = globals['__name__']
else:
module = "<string>"
registry = globals.setdefault("__warningregistry__", {})
_wm.warn_explicit(
message,
category,
filename,
lineno,
module,
registry,
globals,
source=source,
)
def warn_explicit(message, category, filename, lineno,
module=None, registry=None, module_globals=None,
source=None):
lineno = int(lineno)
if module is None:
module = filename or "<unknown>"
if module[-3:].lower() == ".py":
module = module[:-3] # XXX What about leading pathname?
if isinstance(message, Warning):
text = str(message)
category = message.__class__
else:
text = message
message = category(message)
key = (text, category, lineno)
with _wm._lock:
if registry is None:
registry = {}
if registry.get('version', 0) != _wm._filters_version:
registry.clear()
registry['version'] = _wm._filters_version
# Quick test for common case
if registry.get(key):
return
# Search the filters
for item in _wm._get_filters():
action, msg, cat, mod, ln = item
if ((msg is None or msg.match(text)) and
issubclass(category, cat) and
(mod is None or mod.match(module)) and
(ln == 0 or lineno == ln)):
break
else:
action = _wm.defaultaction
# Early exit actions
if action == "ignore":
return
if action == "error":
raise message
# Other actions
if action == "once":
registry[key] = 1
oncekey = (text, category)
if _wm.onceregistry.get(oncekey):
return
_wm.onceregistry[oncekey] = 1
elif action in {"always", "all"}:
pass
elif action == "module":
registry[key] = 1
altkey = (text, category, 0)
if registry.get(altkey):
return
registry[altkey] = 1
elif action == "default":
registry[key] = 1
else:
# Unrecognized actions are errors
raise RuntimeError(
"Unrecognized action (%r) in warnings.filters:\n %s" %
(action, item))
# Prime the linecache for formatting, in case the
# "file" is actually in a zipfile or something.
import linecache
linecache.getlines(filename, module_globals)
# Print message and context
msg = _wm.WarningMessage(message, category, filename, lineno, source=source)
_wm._showwarnmsg(msg)
class WarningMessage(object):
_WARNING_DETAILS = ("message", "category", "filename", "lineno", "file",
"line", "source")
def __init__(self, message, category, filename, lineno, file=None,
line=None, source=None):
self.message = message
self.category = category
self.filename = filename
self.lineno = lineno
self.file = file
self.line = line
self.source = source
self._category_name = category.__name__ if category else None
def __str__(self):
return ("{message : %r, category : %r, filename : %r, lineno : %s, "
"line : %r}" % (self.message, self._category_name,
self.filename, self.lineno, self.line))
def __repr__(self):
return f'<{type(self).__qualname__} {self}>'
class catch_warnings(object):
"""A context manager that copies and restores the warnings filter upon
exiting the context.
The 'record' argument specifies whether warnings should be captured by a
custom implementation of warnings.showwarning() and be appended to a list
returned by the context manager. Otherwise None is returned by the context
manager. The objects appended to the list are arguments whose attributes
mirror the arguments to showwarning().
The 'module' argument is to specify an alternative module to the module
named 'warnings' and imported under that name. This argument is only useful
when testing the warnings module itself.
If the 'action' argument is not None, the remaining arguments are passed
to warnings.simplefilter() as if it were called immediately on entering the
context.
"""
def __init__(self, *, record=False, module=None,
action=None, category=Warning, lineno=0, append=False):
"""Specify whether to record warnings and if an alternative module
should be used other than sys.modules['warnings'].
"""
self._record = record
self._module = sys.modules['warnings'] if module is None else module
self._entered = False
if action is None:
self._filter = None
else:
self._filter = (action, category, lineno, append)
def __repr__(self):
args = []
if self._record:
args.append("record=True")
if self._module is not sys.modules['warnings']:
args.append("module=%r" % self._module)
name = type(self).__name__
return "%s(%s)" % (name, ", ".join(args))
def __enter__(self):
if self._entered:
raise RuntimeError("Cannot enter %r twice" % self)
self._entered = True
with _wm._lock:
if _use_context:
self._saved_context, context = self._module._new_context()
else:
context = None
self._filters = self._module.filters
self._module.filters = self._filters[:]
self._showwarning = self._module.showwarning
self._showwarnmsg_impl = self._module._showwarnmsg_impl
self._module._filters_mutated_lock_held()
if self._record:
if _use_context:
context.log = log = []
else:
log = []
self._module._showwarnmsg_impl = log.append
# Reset showwarning() to the default implementation to make sure
# that _showwarnmsg() calls _showwarnmsg_impl()
self._module.showwarning = self._module._showwarning_orig
else:
log = None
if self._filter is not None:
self._module.simplefilter(*self._filter)
return log
def __exit__(self, *exc_info):
if not self._entered:
raise RuntimeError("Cannot exit %r without entering first" % self)
with _wm._lock:
if _use_context:
self._module._warnings_context.set(self._saved_context)
else:
self._module.filters = self._filters
self._module.showwarning = self._showwarning
self._module._showwarnmsg_impl = self._showwarnmsg_impl
self._module._filters_mutated_lock_held()
class deprecated:
"""Indicate that a class, function or overload is deprecated.
When this decorator is applied to an object, the type checker
will generate a diagnostic on usage of the deprecated object.
Usage:
@deprecated("Use B instead")
class A:
pass
@deprecated("Use g instead")
def f():
pass
@overload
@deprecated("int support is deprecated")
def g(x: int) -> int: ...
@overload
def g(x: str) -> int: ...
The warning specified by *category* will be emitted at runtime
on use of deprecated objects. For functions, that happens on calls;
for classes, on instantiation and on creation of subclasses.
If the *category* is ``None``, no warning is emitted at runtime.
The *stacklevel* determines where the
warning is emitted. If it is ``1`` (the default), the warning
is emitted at the direct caller of the deprecated object; if it
is higher, it is emitted further up the stack.
Static type checker behavior is not affected by the *category*
and *stacklevel* arguments.
The deprecation message passed to the decorator is saved in the
``__deprecated__`` attribute on the decorated object.
If applied to an overload, the decorator
must be after the ``@overload`` decorator for the attribute to
exist on the overload as returned by ``get_overloads()``.
See PEP 702 for details.
"""
def __init__(
self,
message: str,
/,
*,
category: type[Warning] | None = DeprecationWarning,
stacklevel: int = 1,
) -> None:
if not isinstance(message, str):
raise TypeError(
f"Expected an object of type str for 'message', not {type(message).__name__!r}"
)
self.message = message
self.category = category
self.stacklevel = stacklevel
def __call__(self, arg, /):
# Make sure the inner functions created below don't
# retain a reference to self.
msg = self.message
category = self.category
stacklevel = self.stacklevel
if category is None:
arg.__deprecated__ = msg
return arg
elif isinstance(arg, type):
import functools
from types import MethodType
original_new = arg.__new__
@functools.wraps(original_new)
def __new__(cls, /, *args, **kwargs):
if cls is arg:
_wm.warn(msg, category=category, stacklevel=stacklevel + 1)
if original_new is not object.__new__:
return original_new(cls, *args, **kwargs)
# Mirrors a similar check in object.__new__.
elif cls.__init__ is object.__init__ and (args or kwargs):
raise TypeError(f"{cls.__name__}() takes no arguments")
else:
return original_new(cls)
arg.__new__ = staticmethod(__new__)
if "__init_subclass__" in arg.__dict__:
# __init_subclass__ is directly present on the decorated class.
# Synthesize a wrapper that calls this method directly.
original_init_subclass = arg.__init_subclass__
# We need slightly different behavior if __init_subclass__
# is a bound method (likely if it was implemented in Python).
# Otherwise, it likely means it's a builtin such as
# object's implementation of __init_subclass__.
if isinstance(original_init_subclass, MethodType):
original_init_subclass = original_init_subclass.__func__
@functools.wraps(original_init_subclass)
def __init_subclass__(*args, **kwargs):
_wm.warn(msg, category=category, stacklevel=stacklevel + 1)
return original_init_subclass(*args, **kwargs)
else:
def __init_subclass__(cls, *args, **kwargs):
_wm.warn(msg, category=category, stacklevel=stacklevel + 1)
return super(arg, cls).__init_subclass__(*args, **kwargs)
arg.__init_subclass__ = classmethod(__init_subclass__)
arg.__deprecated__ = __new__.__deprecated__ = msg
__init_subclass__.__deprecated__ = msg
return arg
elif callable(arg):
import functools
import inspect
@functools.wraps(arg)
def wrapper(*args, **kwargs):
_wm.warn(msg, category=category, stacklevel=stacklevel + 1)
return arg(*args, **kwargs)
if inspect.iscoroutinefunction(arg):
wrapper = inspect.markcoroutinefunction(wrapper)
arg.__deprecated__ = wrapper.__deprecated__ = msg
return wrapper
else:
raise TypeError(
"@deprecated decorator with non-None category must be applied to "
f"a class or callable, not {arg!r}"
)
_DEPRECATED_MSG = "{name!r} is deprecated and slated for removal in Python {remove}"
def _deprecated(name, message=_DEPRECATED_MSG, *, remove, _version=sys.version_info):
"""Warn that *name* is deprecated or should be removed.
RuntimeError is raised if *remove* specifies a major/minor tuple older than
the current Python version or the same version but past the alpha.
The *message* argument is formatted with *name* and *remove* as a Python
version tuple (e.g. (3, 11)).
"""
remove_formatted = f"{remove[0]}.{remove[1]}"
if (_version[:2] > remove) or (_version[:2] == remove and _version[3] != "alpha"):
msg = f"{name!r} was slated for removal after Python {remove_formatted} alpha"
raise RuntimeError(msg)
else:
msg = message.format(name=name, remove=remove_formatted)
_wm.warn(msg, DeprecationWarning, stacklevel=3)
# Private utility function called by _PyErr_WarnUnawaitedCoroutine
def _warn_unawaited_coroutine(coro):
msg_lines = [
f"coroutine '{coro.__qualname__}' was never awaited\n"
]
if coro.cr_origin is not None:
import linecache, traceback
def extract():
for filename, lineno, funcname in reversed(coro.cr_origin):
line = linecache.getline(filename, lineno)
yield (filename, lineno, funcname, line)
msg_lines.append("Coroutine created at (most recent call last)\n")
msg_lines += traceback.format_list(list(extract()))
msg = "".join(msg_lines).rstrip("\n")
# Passing source= here means that if the user happens to have tracemalloc
# enabled and tracking where the coroutine was created, the warning will
# contain that traceback. This does mean that if they have *both*
# coroutine origin tracking *and* tracemalloc enabled, they'll get two
# partially-redundant tracebacks. If we wanted to be clever we could
# probably detect this case and avoid it, but for now we don't bother.
_wm.warn(
msg, category=RuntimeWarning, stacklevel=2, source=coro
)
def _setup_defaults():
# Several warning categories are ignored by default in regular builds
if hasattr(sys, 'gettotalrefcount'):
return
_wm.filterwarnings("default", category=DeprecationWarning, module="__main__", append=1)
_wm.simplefilter("ignore", category=DeprecationWarning, append=1)
_wm.simplefilter("ignore", category=PendingDeprecationWarning, append=1)
_wm.simplefilter("ignore", category=ImportWarning, append=1)
_wm.simplefilter("ignore", category=ResourceWarning, append=1)

2013
Lib/_pycodecs.py vendored

File diff suppressed because it is too large Load Diff

2723
Lib/_pydatetime.py vendored Normal file

File diff suppressed because it is too large Load Diff

374
Lib/_pydecimal.py vendored
View File

@@ -13,104 +13,7 @@
# bug) and will be backported. At this point the spec is stabilizing
# and the updates are becoming fewer, smaller, and less significant.
"""
This is an implementation of decimal floating point arithmetic based on
the General Decimal Arithmetic Specification:
http://speleotrove.com/decimal/decarith.html
and IEEE standard 854-1987:
http://en.wikipedia.org/wiki/IEEE_854-1987
Decimal floating point has finite precision with arbitrarily large bounds.
The purpose of this module is to support arithmetic using familiar
"schoolhouse" rules and to avoid some of the tricky representation
issues associated with binary floating point. The package is especially
useful for financial applications or for contexts where users have
expectations that are at odds with binary floating point (for instance,
in binary floating point, 1.00 % 0.1 gives 0.09999999999999995 instead
of 0.0; Decimal('1.00') % Decimal('0.1') returns the expected
Decimal('0.00')).
Here are some examples of using the decimal module:
>>> from decimal import *
>>> setcontext(ExtendedContext)
>>> Decimal(0)
Decimal('0')
>>> Decimal('1')
Decimal('1')
>>> Decimal('-.0123')
Decimal('-0.0123')
>>> Decimal(123456)
Decimal('123456')
>>> Decimal('123.45e12345678')
Decimal('1.2345E+12345680')
>>> Decimal('1.33') + Decimal('1.27')
Decimal('2.60')
>>> Decimal('12.34') + Decimal('3.87') - Decimal('18.41')
Decimal('-2.20')
>>> dig = Decimal(1)
>>> print(dig / Decimal(3))
0.333333333
>>> getcontext().prec = 18
>>> print(dig / Decimal(3))
0.333333333333333333
>>> print(dig.sqrt())
1
>>> print(Decimal(3).sqrt())
1.73205080756887729
>>> print(Decimal(3) ** 123)
4.85192780976896427E+58
>>> inf = Decimal(1) / Decimal(0)
>>> print(inf)
Infinity
>>> neginf = Decimal(-1) / Decimal(0)
>>> print(neginf)
-Infinity
>>> print(neginf + inf)
NaN
>>> print(neginf * inf)
-Infinity
>>> print(dig / 0)
Infinity
>>> getcontext().traps[DivisionByZero] = 1
>>> print(dig / 0)
Traceback (most recent call last):
...
...
...
decimal.DivisionByZero: x / 0
>>> c = Context()
>>> c.traps[InvalidOperation] = 0
>>> print(c.flags[InvalidOperation])
0
>>> c.divide(Decimal(0), Decimal(0))
Decimal('NaN')
>>> c.traps[InvalidOperation] = 1
>>> print(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> print(c.flags[InvalidOperation])
0
>>> print(c.divide(Decimal(0), Decimal(0)))
Traceback (most recent call last):
...
...
...
decimal.InvalidOperation: 0 / 0
>>> print(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> c.traps[InvalidOperation] = 0
>>> print(c.divide(Decimal(0), Decimal(0)))
NaN
>>> print(c.flags[InvalidOperation])
1
>>>
"""
"""Python decimal arithmetic module"""
__all__ = [
# Two major classes
@@ -135,13 +38,16 @@ __all__ = [
'ROUND_FLOOR', 'ROUND_UP', 'ROUND_HALF_DOWN', 'ROUND_05UP',
# Functions for manipulating contexts
'setcontext', 'getcontext', 'localcontext',
'setcontext', 'getcontext', 'localcontext', 'IEEEContext',
# Limits for the C version for compatibility
'MAX_PREC', 'MAX_EMAX', 'MIN_EMIN', 'MIN_ETINY',
'MAX_PREC', 'MAX_EMAX', 'MIN_EMIN', 'MIN_ETINY', 'IEEE_CONTEXT_MAX_BITS',
# C version: compile time choice that enables the thread local context
'HAVE_THREADS'
# C version: compile time choice that enables the thread local context (deprecated, now always true)
'HAVE_THREADS',
# C version: compile time choice that enables the coroutine local context
'HAVE_CONTEXTVAR'
]
__xname__ = __name__ # sys.modules lookup (--without-threads)
@@ -156,7 +62,7 @@ import sys
try:
from collections import namedtuple as _namedtuple
DecimalTuple = _namedtuple('DecimalTuple', 'sign digits exponent')
DecimalTuple = _namedtuple('DecimalTuple', 'sign digits exponent', module='decimal')
except ImportError:
DecimalTuple = lambda *args: args
@@ -172,14 +78,17 @@ ROUND_05UP = 'ROUND_05UP'
# Compatibility with the C version
HAVE_THREADS = True
HAVE_CONTEXTVAR = True
if sys.maxsize == 2**63-1:
MAX_PREC = 999999999999999999
MAX_EMAX = 999999999999999999
MIN_EMIN = -999999999999999999
IEEE_CONTEXT_MAX_BITS = 512
else:
MAX_PREC = 425000000
MAX_EMAX = 425000000
MIN_EMIN = -425000000
IEEE_CONTEXT_MAX_BITS = 256
MIN_ETINY = MIN_EMIN - (MAX_PREC-1)
@@ -190,7 +99,7 @@ class DecimalException(ArithmeticError):
Used exceptions derive from this.
If an exception derives from another exception besides this (such as
Underflow (Inexact, Rounded, Subnormal) that indicates that it is only
Underflow (Inexact, Rounded, Subnormal)) that indicates that it is only
called if the others are present. This isn't actually used for
anything, though.
@@ -238,7 +147,7 @@ class InvalidOperation(DecimalException):
x ** (+-)INF
An operand is invalid
The result of the operation after these is a quiet positive NaN,
The result of the operation after this is a quiet positive NaN,
except when the cause is a signaling NaN, in which case the result is
also a quiet NaN, but with the original sign, and an optional
diagnostic information.
@@ -431,82 +340,40 @@ _rounding_modes = (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_CEILING,
##### Context Functions ##################################################
# The getcontext() and setcontext() function manage access to a thread-local
# current context. Py2.4 offers direct support for thread locals. If that
# is not available, use threading.current_thread() which is slower but will
# work for older Pythons. If threads are not part of the build, create a
# mock threading object with threading.local() returning the module namespace.
# current context.
try:
import threading
except ImportError:
# Python was compiled without threads; create a mock object instead
class MockThreading(object):
def local(self, sys=sys):
return sys.modules[__xname__]
threading = MockThreading()
del MockThreading
import contextvars
try:
threading.local
_current_context_var = contextvars.ContextVar('decimal_context')
except AttributeError:
_context_attributes = frozenset(
['prec', 'Emin', 'Emax', 'capitals', 'clamp', 'rounding', 'flags', 'traps']
)
# To fix reloading, force it to create a new context
# Old contexts have different exceptions in their dicts, making problems.
if hasattr(threading.current_thread(), '__decimal_context__'):
del threading.current_thread().__decimal_context__
def getcontext():
"""Returns this thread's context.
def setcontext(context):
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
context = context.copy()
context.clear_flags()
threading.current_thread().__decimal_context__ = context
If this thread does not yet have a context, returns
a new context and sets this thread's context.
New contexts are copies of DefaultContext.
"""
try:
return _current_context_var.get()
except LookupError:
context = Context()
_current_context_var.set(context)
return context
def getcontext():
"""Returns this thread's context.
def setcontext(context):
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
context = context.copy()
context.clear_flags()
_current_context_var.set(context)
If this thread does not yet have a context, returns
a new context and sets this thread's context.
New contexts are copies of DefaultContext.
"""
try:
return threading.current_thread().__decimal_context__
except AttributeError:
context = Context()
threading.current_thread().__decimal_context__ = context
return context
del contextvars # Don't contaminate the namespace
else:
local = threading.local()
if hasattr(local, '__decimal_context__'):
del local.__decimal_context__
def getcontext(_local=local):
"""Returns this thread's context.
If this thread does not yet have a context, returns
a new context and sets this thread's context.
New contexts are copies of DefaultContext.
"""
try:
return _local.__decimal_context__
except AttributeError:
context = Context()
_local.__decimal_context__ = context
return context
def setcontext(context, _local=local):
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
context = context.copy()
context.clear_flags()
_local.__decimal_context__ = context
del threading, local # Don't contaminate the namespace
def localcontext(ctx=None):
def localcontext(ctx=None, **kwargs):
"""Return a context manager for a copy of the supplied context
Uses a copy of the current context if no context is specified
@@ -542,8 +409,35 @@ def localcontext(ctx=None):
>>> print(getcontext().prec)
28
"""
if ctx is None: ctx = getcontext()
return _ContextManager(ctx)
if ctx is None:
ctx = getcontext()
ctx_manager = _ContextManager(ctx)
for key, value in kwargs.items():
if key not in _context_attributes:
raise TypeError(f"'{key}' is an invalid keyword argument for this function")
setattr(ctx_manager.new_context, key, value)
return ctx_manager
def IEEEContext(bits, /):
"""
Return a context object initialized to the proper values for one of the
IEEE interchange formats. The argument must be a multiple of 32 and less
than IEEE_CONTEXT_MAX_BITS.
"""
if bits <= 0 or bits > IEEE_CONTEXT_MAX_BITS or bits % 32:
raise ValueError("argument must be a multiple of 32, "
f"with a maximum of {IEEE_CONTEXT_MAX_BITS}")
ctx = Context()
ctx.prec = 9 * (bits//32) - 2
ctx.Emax = 3 * (1 << (bits//16 + 3))
ctx.Emin = 1 - ctx.Emax
ctx.rounding = ROUND_HALF_EVEN
ctx.clamp = 1
ctx.traps = dict.fromkeys(_signals, False)
return ctx
##### Decimal class #######################################################
@@ -553,7 +447,7 @@ def localcontext(ctx=None):
# numbers.py for more detail.
class Decimal(object):
"""Floating point class for decimal arithmetic."""
"""Floating-point class for decimal arithmetic."""
__slots__ = ('_exp','_int','_sign', '_is_special')
# Generally, the value of the Decimal instance is given by
@@ -711,6 +605,21 @@ class Decimal(object):
raise TypeError("Cannot convert %r to Decimal" % value)
@classmethod
def from_number(cls, number):
"""Converts a real number to a decimal number, exactly.
>>> Decimal.from_number(314) # int
Decimal('314')
>>> Decimal.from_number(0.1) # float
Decimal('0.1000000000000000055511151231257827021181583404541015625')
>>> Decimal.from_number(Decimal('3.14')) # another decimal instance
Decimal('3.14')
"""
if isinstance(number, (int, Decimal, float)):
return cls(number)
raise TypeError("Cannot convert %r to Decimal" % number)
@classmethod
def from_float(cls, f):
"""Converts a float to a decimal number, exactly.
@@ -734,18 +643,23 @@ class Decimal(object):
"""
if isinstance(f, int): # handle integer inputs
return cls(f)
if not isinstance(f, float):
raise TypeError("argument must be int or float.")
if _math.isinf(f) or _math.isnan(f):
return cls(repr(f))
if _math.copysign(1.0, f) == 1.0:
sign = 0
sign = 0 if f >= 0 else 1
k = 0
coeff = str(abs(f))
elif isinstance(f, float):
if _math.isinf(f) or _math.isnan(f):
return cls(repr(f))
if _math.copysign(1.0, f) == 1.0:
sign = 0
else:
sign = 1
n, d = abs(f).as_integer_ratio()
k = d.bit_length() - 1
coeff = str(n*5**k)
else:
sign = 1
n, d = abs(f).as_integer_ratio()
k = d.bit_length() - 1
result = _dec_from_triple(sign, str(n*5**k), -k)
raise TypeError("argument must be int or float.")
result = _dec_from_triple(sign, coeff, -k)
if cls is Decimal:
return result
else:
@@ -988,7 +902,7 @@ class Decimal(object):
if self.is_snan():
raise TypeError('Cannot hash a signaling NaN value.')
elif self.is_nan():
return _PyHASH_NAN
return object.__hash__(self)
else:
if self._sign:
return -_PyHASH_INF
@@ -1669,13 +1583,13 @@ class Decimal(object):
__trunc__ = __int__
@property
def real(self):
return self
real = property(real)
@property
def imag(self):
return Decimal(0)
imag = property(imag)
def conjugate(self):
return self
@@ -2255,10 +2169,16 @@ class Decimal(object):
else:
return None
if xc >= 10**p:
# An exact power of 10 is representable, but can convert to a
# string of any length. But an exact power of 10 shouldn't be
# possible at this point.
assert xc > 1, self
assert xc % 10 != 0, self
strxc = str(xc)
if len(strxc) > p:
return None
xe = -e-xe
return _dec_from_triple(0, str(xc), xe)
return _dec_from_triple(0, strxc, xe)
# now y is positive; find m and n such that y = m/n
if ye >= 0:
@@ -2267,7 +2187,7 @@ class Decimal(object):
if xe != 0 and len(str(abs(yc*xe))) <= -ye:
return None
xc_bits = _nbits(xc)
if xc != 1 and len(str(abs(yc)*xc_bits)) <= -ye:
if len(str(abs(yc)*xc_bits)) <= -ye:
return None
m, n = yc, 10**(-ye)
while m % 2 == n % 2 == 0:
@@ -2280,7 +2200,7 @@ class Decimal(object):
# compute nth root of xc*10**xe
if n > 1:
# if 1 < xc < 2**n then xc isn't an nth power
if xc != 1 and xc_bits <= n:
if xc_bits <= n:
return None
xe, rem = divmod(xe, n)
@@ -2308,13 +2228,18 @@ class Decimal(object):
return None
xc = xc**m
xe *= m
if xc > 10**p:
# An exact power of 10 is representable, but can convert to a string
# of any length. But an exact power of 10 shouldn't be possible at
# this point.
assert xc > 1, self
assert xc % 10 != 0, self
str_xc = str(xc)
if len(str_xc) > p:
return None
# by this point the result *is* exactly representable
# adjust the exponent to get as close as possible to the ideal
# exponent, if necessary
str_xc = str(xc)
if other._isinteger() and other._sign == 0:
ideal_exponent = self._exp*int(other)
zeros = min(xe-ideal_exponent, p-len(str_xc))
@@ -2538,12 +2463,12 @@ class Decimal(object):
return ans
def __rpow__(self, other, context=None):
def __rpow__(self, other, modulo=None, context=None):
"""Swaps self/other and returns __pow__."""
other = _convert_other(other)
if other is NotImplemented:
return other
return other.__pow__(self, context=context)
return other.__pow__(self, modulo, context=context)
def normalize(self, context=None):
"""Normalize- strip trailing 0s, change anything equal to 0 to 0e0"""
@@ -3415,7 +3340,10 @@ class Decimal(object):
return opa, opb
def logical_and(self, other, context=None):
"""Applies an 'and' operation between self and other's digits."""
"""Applies an 'and' operation between self and other's digits.
Both self and other must be logical numbers.
"""
if context is None:
context = getcontext()
@@ -3432,14 +3360,20 @@ class Decimal(object):
return _dec_from_triple(0, result.lstrip('0') or '0', 0)
def logical_invert(self, context=None):
"""Invert all its digits."""
"""Invert all its digits.
The self must be logical number.
"""
if context is None:
context = getcontext()
return self.logical_xor(_dec_from_triple(0,'1'*context.prec,0),
context)
def logical_or(self, other, context=None):
"""Applies an 'or' operation between self and other's digits."""
"""Applies an 'or' operation between self and other's digits.
Both self and other must be logical numbers.
"""
if context is None:
context = getcontext()
@@ -3456,7 +3390,10 @@ class Decimal(object):
return _dec_from_triple(0, result.lstrip('0') or '0', 0)
def logical_xor(self, other, context=None):
"""Applies an 'xor' operation between self and other's digits."""
"""Applies an 'xor' operation between self and other's digits.
Both self and other must be logical numbers.
"""
if context is None:
context = getcontext()
@@ -3832,6 +3769,10 @@ class Decimal(object):
# represented in fixed point; rescale them to 0e0.
if not self and self._exp > 0 and spec['type'] in 'fF%':
self = self._rescale(0, rounding)
if not self and spec['no_neg_0'] and self._sign:
adjusted_sign = 0
else:
adjusted_sign = self._sign
# figure out placement of the decimal point
leftdigits = self._exp + len(self._int)
@@ -3862,7 +3803,7 @@ class Decimal(object):
# done with the decimal-specific stuff; hand over the rest
# of the formatting to the _format_number function
return _format_number(self._sign, intpart, fracpart, exp, spec)
return _format_number(adjusted_sign, intpart, fracpart, exp, spec)
def _dec_from_triple(sign, coefficient, exponent, special=False):
"""Create a decimal instance directly, without any validation,
@@ -5672,8 +5613,6 @@ class _WorkRep(object):
def __repr__(self):
return "(%r, %r, %r)" % (self.sign, self.int, self.exp)
__str__ = __repr__
def _normalize(op1, op2, prec = 0):
@@ -6169,7 +6108,7 @@ _parser = re.compile(r""" # A numeric string consists of:
(?P<diag>\d*) # with (possibly empty) diagnostic info.
)
# \s*
\Z
\z
""", re.VERBOSE | re.IGNORECASE).match
_all_zeros = re.compile('0*$').match
@@ -6182,7 +6121,7 @@ _exact_half = re.compile('50*$').match
#
# A format specifier for Decimal looks like:
#
# [[fill]align][sign][#][0][minimumwidth][,][.precision][type]
# [[fill]align][sign][z][#][0][minimumwidth][,][.precision][type]
_parse_format_specifier_regex = re.compile(r"""\A
(?:
@@ -6190,13 +6129,18 @@ _parse_format_specifier_regex = re.compile(r"""\A
(?P<align>[<>=^])
)?
(?P<sign>[-+ ])?
(?P<no_neg_0>z)?
(?P<alt>\#)?
(?P<zeropad>0)?
(?P<minimumwidth>(?!0)\d+)?
(?P<thousands_sep>,)?
(?:\.(?P<precision>0|(?!0)\d+))?
(?P<minimumwidth>\d+)?
(?P<thousands_sep>[,_])?
(?:\.
(?=[\d,_]) # lookahead for digit or separator
(?P<precision>\d+)?
(?P<frac_separators>[,_])?
)?
(?P<type>[eEfFgGn%])?
\Z
\z
""", re.VERBOSE|re.DOTALL)
del re
@@ -6287,6 +6231,9 @@ def _parse_format_specifier(format_spec, _localeconv=None):
format_dict['grouping'] = [3, 0]
format_dict['decimal_point'] = '.'
if format_dict['frac_separators'] is None:
format_dict['frac_separators'] = ''
return format_dict
def _format_align(sign, body, spec):
@@ -6406,6 +6353,11 @@ def _format_number(is_negative, intpart, fracpart, exp, spec):
sign = _format_sign(is_negative, spec)
frac_sep = spec['frac_separators']
if fracpart and frac_sep:
fracpart = frac_sep.join(fracpart[pos:pos + 3]
for pos in range(0, len(fracpart), 3))
if fracpart or spec['alt']:
fracpart = spec['decimal_point'] + fracpart

331
Lib/_pyio.py vendored
View File

@@ -16,15 +16,16 @@ else:
_setmode = None
import io
from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END)
from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END, Reader, Writer) # noqa: F401
valid_seek_flags = {0, 1, 2} # Hardwired values
if hasattr(os, 'SEEK_HOLE') :
valid_seek_flags.add(os.SEEK_HOLE)
valid_seek_flags.add(os.SEEK_DATA)
# open() uses st_blksize whenever we can
DEFAULT_BUFFER_SIZE = 8 * 1024 # bytes
# open() uses max(min(blocksize, 8 MiB), DEFAULT_BUFFER_SIZE)
# when the device block size is available.
DEFAULT_BUFFER_SIZE = 128 * 1024 # bytes
# NOTE: Base classes defined here are registered with the "official" ABCs
# defined in io.py. We don't use real inheritance though, because we don't want
@@ -33,19 +34,17 @@ DEFAULT_BUFFER_SIZE = 8 * 1024 # bytes
# Rebind for compatibility
BlockingIOError = BlockingIOError
# Does io.IOBase finalizer log the exception if the close() method fails?
# The exception is ignored silently by default in release build.
_IOBASE_EMITS_UNRAISABLE = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
# Does open() check its 'errors' argument?
_CHECK_ERRORS = _IOBASE_EMITS_UNRAISABLE
_CHECK_ERRORS = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
def text_encoding(encoding, stacklevel=2):
"""
A helper function to choose the text encoding.
When encoding is not None, just return it.
Otherwise, return the default text encoding (i.e. "locale").
When encoding is not None, this function returns it.
Otherwise, this function returns the default text encoding
(i.e. "locale" or "utf-8" depends on UTF-8 mode).
This function emits an EncodingWarning if *encoding* is None and
sys.flags.warn_default_encoding is true.
@@ -55,7 +54,10 @@ def text_encoding(encoding, stacklevel=2):
However, please consider using encoding="utf-8" for new APIs.
"""
if encoding is None:
encoding = "locale"
if sys.flags.utf8_mode:
encoding = "utf-8"
else:
encoding = "locale"
if sys.flags.warn_default_encoding:
import warnings
warnings.warn("'encoding' argument not specified.",
@@ -101,7 +103,6 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
'b' binary mode
't' text mode (default)
'+' open a disk file for updating (reading and writing)
'U' universal newline mode (deprecated)
========= ===============================================================
The default mode is 'rt' (open for reading text). For binary random
@@ -117,20 +118,16 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
returned as strings, the bytes having been first decoded using a
platform-dependent encoding or using the specified encoding if given.
'U' mode is deprecated and will raise an exception in future versions
of Python. It has no effect in Python 3. Use newline to control
universal newlines mode.
buffering is an optional integer used to set the buffering policy.
Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
line buffering (only usable in text mode), and an integer > 1 to indicate
the size of a fixed-size chunk buffer. When no buffering argument is
given, the default buffering policy works as follows:
* Binary files are buffered in fixed-size chunks; the size of the buffer
is chosen using a heuristic trying to determine the underlying device's
"block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
On many systems, the buffer will typically be 4096 or 8192 bytes long.
* Binary files are buffered in fixed-size chunks; the size of the buffer
is max(min(blocksize, 8 MiB), DEFAULT_BUFFER_SIZE)
when the device block size is available.
On most systems, the buffer will typically be 128 kilobytes long.
* "Interactive" text files (files for which isatty() returns True)
use line buffering. Other text files use the policy described above
@@ -206,7 +203,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
if errors is not None and not isinstance(errors, str):
raise TypeError("invalid errors: %r" % errors)
modes = set(mode)
if modes - set("axrwb+tU") or len(mode) > len(modes):
if modes - set("axrwb+t") or len(mode) > len(modes):
raise ValueError("invalid mode: %r" % mode)
creating = "x" in modes
reading = "r" in modes
@@ -215,13 +212,6 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
updating = "+" in modes
text = "t" in modes
binary = "b" in modes
if "U" in modes:
if creating or writing or appending or updating:
raise ValueError("mode U cannot be combined with 'x', 'w', 'a', or '+'")
import warnings
warnings.warn("'U' mode is deprecated",
DeprecationWarning, 2)
reading = True
if text and binary:
raise ValueError("can't have text and binary mode at once")
if creating + reading + writing + appending > 1:
@@ -249,18 +239,11 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
result = raw
try:
line_buffering = False
if buffering == 1 or buffering < 0 and raw.isatty():
if buffering == 1 or buffering < 0 and raw._isatty_open_only():
buffering = -1
line_buffering = True
if buffering < 0:
buffering = DEFAULT_BUFFER_SIZE
try:
bs = os.fstat(raw.fileno()).st_blksize
except (OSError, AttributeError):
pass
else:
if bs > 1:
buffering = bs
buffering = max(min(raw._blksize, 8192 * 1024), DEFAULT_BUFFER_SIZE)
if buffering < 0:
raise ValueError("invalid buffering size")
if buffering == 0:
@@ -311,22 +294,6 @@ except AttributeError:
open_code = _open_code_with_warning
def __getattr__(name):
if name == "OpenWrapper":
# bpo-43680: Until Python 3.9, _pyio.open was not a static method and
# builtins.open was set to OpenWrapper to not become a bound method
# when set to a class variable. _io.open is a built-in function whereas
# _pyio.open is a Python function. In Python 3.10, _pyio.open() is now
# a static method, and builtins.open() is now io.open().
import warnings
warnings.warn('OpenWrapper is deprecated, use open instead',
DeprecationWarning, stacklevel=2)
global OpenWrapper
OpenWrapper = open
return OpenWrapper
raise AttributeError(name)
# In normal operation, both `UnsupportedOperation`s should be bound to the
# same object.
try:
@@ -338,8 +305,7 @@ except AttributeError:
class IOBase(metaclass=abc.ABCMeta):
"""The abstract base class for all I/O classes, acting on streams of
bytes. There is no public constructor.
"""The abstract base class for all I/O classes.
This class provides dummy implementations for many methods that
derived classes can override selectively; the default implementations
@@ -441,18 +407,12 @@ class IOBase(metaclass=abc.ABCMeta):
if closed:
return
if _IOBASE_EMITS_UNRAISABLE:
self.close()
else:
# The try/except block is in case this is called at program
# exit time, when it's possible that globals have already been
# deleted, and then the close() call might fail. Since
# there's nothing we can do about such failures and they annoy
# the end users, we suppress the traceback.
try:
self.close()
except:
pass
if dealloc_warn := getattr(self, "_dealloc_warn", None):
dealloc_warn(self)
# If close() fails, the caller logs the exception with
# sys.unraisablehook. close() must be called at the end at __del__().
self.close()
### Inquiries ###
@@ -657,16 +617,15 @@ class RawIOBase(IOBase):
n = self.readinto(b)
if n is None:
return None
if n < 0 or n > len(b):
raise ValueError(f"readinto returned {n} outside buffer size {len(b)}")
del b[n:]
return bytes(b)
def readall(self):
"""Read until EOF, using multiple read() call."""
res = bytearray()
while True:
data = self.read(DEFAULT_BUFFER_SIZE)
if not data:
break
while data := self.read(DEFAULT_BUFFER_SIZE):
res += data
if res:
return bytes(res)
@@ -691,8 +650,6 @@ class RawIOBase(IOBase):
self._unsupported("write")
io.RawIOBase.register(RawIOBase)
from _io import FileIO
RawIOBase.register(FileIO)
class BufferedIOBase(IOBase):
@@ -899,6 +856,10 @@ class _BufferedIOMixin(BufferedIOBase):
else:
return "<{}.{} name={!r}>".format(modname, clsname, name)
def _dealloc_warn(self, source):
if dealloc_warn := getattr(self.raw, "_dealloc_warn", None):
dealloc_warn(source)
### Lower-level APIs ###
def fileno(self):
@@ -974,22 +935,22 @@ class BytesIO(BufferedIOBase):
return self.read(size)
def write(self, b):
if self.closed:
raise ValueError("write to closed file")
if isinstance(b, str):
raise TypeError("can't write str to binary stream")
with memoryview(b) as view:
if self.closed:
raise ValueError("write to closed file")
n = view.nbytes # Size of any bytes-like object
if n == 0:
return 0
pos = self._pos
if pos > len(self._buffer):
# Inserts null bytes between the current end of the file
# and the new write position.
padding = b'\x00' * (pos - len(self._buffer))
self._buffer += padding
self._buffer[pos:pos + n] = b
self._pos += n
if n == 0:
return 0
pos = self._pos
if pos > len(self._buffer):
# Pad buffer to pos with null bytes.
self._buffer.resize(pos)
self._buffer[pos:pos + n] = view
self._pos += n
return n
def seek(self, pos, whence=0):
@@ -1154,6 +1115,7 @@ class BufferedReader(_BufferedIOMixin):
do at most one raw read to satisfy it. We never return more
than self.buffer_size.
"""
self._checkClosed("peek of closed file")
with self._read_lock:
return self._peek_unlocked(size)
@@ -1172,6 +1134,7 @@ class BufferedReader(_BufferedIOMixin):
"""Reads up to size bytes, with at most one read() system call."""
# Returns up to size bytes. If at least one byte is buffered, we
# only return buffered bytes. Otherwise, we do one raw read.
self._checkClosed("read of closed file")
if size < 0:
size = self.buffer_size
if size == 0:
@@ -1189,6 +1152,8 @@ class BufferedReader(_BufferedIOMixin):
def _readinto(self, buf, read1):
"""Read data into *buf* with at most one system call."""
self._checkClosed("readinto of closed file")
# Need to create a memoryview object of type 'b', otherwise
# we may not be able to assign bytes to it, and slicing it
# would create a new object.
@@ -1233,11 +1198,13 @@ class BufferedReader(_BufferedIOMixin):
return written
def tell(self):
return _BufferedIOMixin.tell(self) - len(self._read_buf) + self._read_pos
# GH-95782: Keep return value non-negative
return max(_BufferedIOMixin.tell(self) - len(self._read_buf) + self._read_pos, 0)
def seek(self, pos, whence=0):
if whence not in valid_seek_flags:
raise ValueError("invalid whence value")
self._checkClosed("seek of closed file")
with self._read_lock:
if whence == 1:
pos -= len(self._read_buf) - self._read_pos
@@ -1497,6 +1464,17 @@ class BufferedRandom(BufferedWriter, BufferedReader):
return BufferedWriter.write(self, b)
def _new_buffersize(bytes_read):
# Parallels _io/fileio.c new_buffersize
if bytes_read > 65536:
addend = bytes_read >> 3
else:
addend = 256 + bytes_read
if addend < DEFAULT_BUFFER_SIZE:
addend = DEFAULT_BUFFER_SIZE
return bytes_read + addend
class FileIO(RawIOBase):
_fd = -1
_created = False
@@ -1521,6 +1499,7 @@ class FileIO(RawIOBase):
"""
if self._fd >= 0:
# Have to close the existing file first.
self._stat_atopen = None
try:
if self._closefd:
os.close(self._fd)
@@ -1530,6 +1509,11 @@ class FileIO(RawIOBase):
if isinstance(file, float):
raise TypeError('integer argument expected, got float')
if isinstance(file, int):
if isinstance(file, bool):
import warnings
warnings.warn("bool is used as a file descriptor",
RuntimeWarning, stacklevel=2)
file = int(file)
fd = file
if fd < 0:
raise ValueError('negative file descriptor')
@@ -1588,24 +1572,22 @@ class FileIO(RawIOBase):
if not isinstance(fd, int):
raise TypeError('expected integer from opener')
if fd < 0:
raise OSError('Negative file descriptor')
# bpo-27066: Raise a ValueError for bad value.
raise ValueError(f'opener returned {fd}')
owned_fd = fd
if not noinherit_flag:
os.set_inheritable(fd, False)
self._closefd = closefd
fdfstat = os.fstat(fd)
self._stat_atopen = os.fstat(fd)
try:
if stat.S_ISDIR(fdfstat.st_mode):
if stat.S_ISDIR(self._stat_atopen.st_mode):
raise IsADirectoryError(errno.EISDIR,
os.strerror(errno.EISDIR), file)
except AttributeError:
# Ignore the AttributeError if stat.S_ISDIR or errno.EISDIR
# don't exist.
pass
self._blksize = getattr(fdfstat, 'st_blksize', 0)
if self._blksize <= 1:
self._blksize = DEFAULT_BUFFER_SIZE
if _setmode:
# don't translate newlines (\r\n <=> \n)
@@ -1622,17 +1604,17 @@ class FileIO(RawIOBase):
if e.errno != errno.ESPIPE:
raise
except:
self._stat_atopen = None
if owned_fd is not None:
os.close(owned_fd)
raise
self._fd = fd
def __del__(self):
def _dealloc_warn(self, source):
if self._fd >= 0 and self._closefd and not self.closed:
import warnings
warnings.warn('unclosed file %r' % (self,), ResourceWarning,
warnings.warn(f'unclosed file {source!r}', ResourceWarning,
stacklevel=2, source=self)
self.close()
def __getstate__(self):
raise TypeError(f"cannot pickle {self.__class__.__name__!r} object")
@@ -1651,6 +1633,17 @@ class FileIO(RawIOBase):
return ('<%s name=%r mode=%r closefd=%r>' %
(class_name, name, self.mode, self._closefd))
@property
def _blksize(self):
if self._stat_atopen is None:
return DEFAULT_BUFFER_SIZE
blksize = getattr(self._stat_atopen, "st_blksize", 0)
# WASI sets blsize to 0
if not blksize:
return DEFAULT_BUFFER_SIZE
return blksize
def _checkReadable(self):
if not self._readable:
raise UnsupportedOperation('File not open for reading')
@@ -1662,7 +1655,13 @@ class FileIO(RawIOBase):
def read(self, size=None):
"""Read at most size bytes, returned as bytes.
Only makes one system call, so less data may be returned than requested
If size is less than 0, read all bytes in the file making
multiple read calls. See ``FileIO.readall``.
Attempts to make only one system call, retrying only per
PEP 475 (EINTR). This means less data may be returned than
requested.
In non-blocking mode, returns None if no data is available.
Return an empty bytes object at EOF.
"""
@@ -1678,45 +1677,57 @@ class FileIO(RawIOBase):
def readall(self):
"""Read all data from the file, returned as bytes.
In non-blocking mode, returns as much as is immediately available,
or None if no data is available. Return an empty bytes object at EOF.
Reads until either there is an error or read() returns size 0
(indicates EOF). If the file is already at EOF, returns an
empty bytes object.
In non-blocking mode, returns as much data as could be read
before EAGAIN. If no data is available (EAGAIN is returned
before bytes are read) returns None.
"""
self._checkClosed()
self._checkReadable()
bufsize = DEFAULT_BUFFER_SIZE
if self._stat_atopen is None or self._stat_atopen.st_size <= 0:
bufsize = DEFAULT_BUFFER_SIZE
else:
# In order to detect end of file, need a read() of at least 1
# byte which returns size 0. Oversize the buffer by 1 byte so the
# I/O can be completed with two read() calls (one for all data, one
# for EOF) without needing to resize the buffer.
bufsize = self._stat_atopen.st_size + 1
if self._stat_atopen.st_size > 65536:
try:
pos = os.lseek(self._fd, 0, SEEK_CUR)
if self._stat_atopen.st_size >= pos:
bufsize = self._stat_atopen.st_size - pos + 1
except OSError:
pass
result = bytearray(bufsize)
bytes_read = 0
try:
pos = os.lseek(self._fd, 0, SEEK_CUR)
end = os.fstat(self._fd).st_size
if end >= pos:
bufsize = end - pos + 1
except OSError:
pass
result = bytearray()
while True:
if len(result) >= bufsize:
bufsize = len(result)
bufsize += max(bufsize, DEFAULT_BUFFER_SIZE)
n = bufsize - len(result)
try:
chunk = os.read(self._fd, n)
except BlockingIOError:
if result:
break
while n := os.readinto(self._fd, memoryview(result)[bytes_read:]):
bytes_read += n
if bytes_read >= len(result):
result.resize(_new_buffersize(bytes_read))
except BlockingIOError:
if not bytes_read:
return None
if not chunk: # reached the end of the file
break
result += chunk
assert len(result) - bytes_read >= 1, \
"os.readinto buffer size 0 will result in erroneous EOF / returns 0"
result.resize(bytes_read)
return bytes(result)
def readinto(self, b):
def readinto(self, buffer):
"""Same as RawIOBase.readinto()."""
m = memoryview(b).cast('B')
data = self.read(len(m))
n = len(data)
m[:n] = data
return n
self._checkClosed()
self._checkReadable()
try:
return os.readinto(self._fd, buffer)
except BlockingIOError:
return None
def write(self, b):
"""Write bytes b to file, return number written.
@@ -1766,6 +1777,7 @@ class FileIO(RawIOBase):
if size is None:
size = self.tell()
os.ftruncate(self._fd, size)
self._stat_atopen = None
return size
def close(self):
@@ -1775,8 +1787,9 @@ class FileIO(RawIOBase):
called more than once without error.
"""
if not self.closed:
self._stat_atopen = None
try:
if self._closefd:
if self._closefd and self._fd >= 0:
os.close(self._fd)
finally:
super().close()
@@ -1813,6 +1826,21 @@ class FileIO(RawIOBase):
self._checkClosed()
return os.isatty(self._fd)
def _isatty_open_only(self):
"""Checks whether the file is a TTY using an open-only optimization.
TTYs are always character devices. If the interpreter knows a file is
not a character device when it would call ``isatty``, can skip that
call. Inside ``open()`` there is a fresh stat result that contains that
information. Use the stat result to skip a system call. Outside of that
context TOCTOU issues (the fd could be arbitrarily modified by
surrounding code).
"""
if (self._stat_atopen is not None
and not stat.S_ISCHR(self._stat_atopen.st_mode)):
return False
return os.isatty(self._fd)
@property
def closefd(self):
"""True if the file descriptor will be closed by close()."""
@@ -1845,7 +1873,7 @@ class TextIOBase(IOBase):
"""Base class for text I/O.
This class provides a character and line based interface to stream
I/O. There is no public constructor.
I/O.
"""
def read(self, size=-1):
@@ -1997,7 +2025,7 @@ class TextIOWrapper(TextIOBase):
r"""Character and line based layer over a BufferedIOBase object, buffer.
encoding gives the name of the encoding that the stream will be
decoded or encoded with. It defaults to locale.getpreferredencoding(False).
decoded or encoded with. It defaults to locale.getencoding().
errors determines the strictness of encoding and decoding (see the
codecs.register) and defaults to "strict".
@@ -2031,26 +2059,13 @@ class TextIOWrapper(TextIOBase):
encoding = text_encoding(encoding)
if encoding == "locale":
try:
encoding = os.device_encoding(buffer.fileno()) or "locale"
except (AttributeError, UnsupportedOperation):
pass
if encoding == "locale":
try:
import locale
except ImportError:
# Importing locale may fail if Python is being built
encoding = "utf-8"
else:
encoding = locale.getpreferredencoding(False)
encoding = self._get_locale_encoding()
if not isinstance(encoding, str):
raise ValueError("invalid encoding: %r" % encoding)
if not codecs.lookup(encoding)._is_text_encoding:
msg = ("%r is not a text encoding; "
"use codecs.open() to handle arbitrary codecs")
msg = "%r is not a text encoding"
raise LookupError(msg % encoding)
if errors is None:
@@ -2176,6 +2191,8 @@ class TextIOWrapper(TextIOBase):
else:
if not isinstance(encoding, str):
raise TypeError("invalid encoding: %r" % encoding)
if encoding == "locale":
encoding = self._get_locale_encoding()
if newline is Ellipsis:
newline = self._readnl
@@ -2243,8 +2260,9 @@ class TextIOWrapper(TextIOBase):
self.buffer.write(b)
if self._line_buffering and (haslf or "\r" in s):
self.flush()
self._set_decoded_chars('')
self._snapshot = None
if self._snapshot is not None:
self._set_decoded_chars('')
self._snapshot = None
if self._decoder:
self._decoder.reset()
return length
@@ -2280,6 +2298,15 @@ class TextIOWrapper(TextIOBase):
self._decoded_chars_used += len(chars)
return chars
def _get_locale_encoding(self):
try:
import locale
except ImportError:
# Importing locale may fail if Python is being built
return "utf-8"
else:
return locale.getencoding()
def _rewind_decoded_chars(self, n):
"""Rewind the _decoded_chars buffer."""
if self._decoded_chars_used < n:
@@ -2546,11 +2573,15 @@ class TextIOWrapper(TextIOBase):
size = size_index()
decoder = self._decoder or self._get_decoder()
if size < 0:
chunk = self.buffer.read()
if chunk is None:
raise BlockingIOError("Read returned None.")
# Read everything.
result = (self._get_decoded_chars() +
decoder.decode(self.buffer.read(), final=True))
self._set_decoded_chars('')
self._snapshot = None
decoder.decode(chunk, final=True))
if self._snapshot is not None:
self._set_decoded_chars('')
self._snapshot = None
return result
else:
# Keep reading chunks until we have size characters to return.
@@ -2667,6 +2698,10 @@ class TextIOWrapper(TextIOBase):
def newlines(self):
return self._decoder.newlines if self._decoder else None
def _dealloc_warn(self, source):
if dealloc_warn := getattr(self.buffer, "_dealloc_warn", None):
dealloc_warn(source)
class StringIO(TextIOWrapper):
"""Text I/O implementation using an in-memory buffer.

729
Lib/_pylong.py vendored Normal file
View File

@@ -0,0 +1,729 @@
"""Python implementations of some algorithms for use by longobject.c.
The goal is to provide asymptotically faster algorithms that can be
used for operations on integers with many digits. In those cases, the
performance overhead of the Python implementation is not significant
since the asymptotic behavior is what dominates runtime. Functions
provided by this module should be considered private and not part of any
public API.
Note: for ease of maintainability, please prefer clear code and avoid
"micro-optimizations". This module will only be imported and used for
integers with a huge number of digits. Saving a few microseconds with
tricky or non-obvious code is not worth it. For people looking for
maximum performance, they should use something like gmpy2."""
import re
import decimal
try:
import _decimal
except ImportError:
_decimal = None
# A number of functions have this form, where `w` is a desired number of
# digits in base `base`:
#
# def inner(...w...):
# if w <= LIMIT:
# return something
# lo = w >> 1
# hi = w - lo
# something involving base**lo, inner(...lo...), j, and inner(...hi...)
# figure out largest w needed
# result = inner(w)
#
# They all had some on-the-fly scheme to cache `base**lo` results for reuse.
# Power is costly.
#
# This routine aims to compute all amd only the needed powers in advance, as
# efficiently as reasonably possible. This isn't trivial, and all the
# on-the-fly methods did needless work in many cases. The driving code above
# changes to:
#
# figure out largest w needed
# mycache = compute_powers(w, base, LIMIT)
# result = inner(w)
#
# and `mycache[lo]` replaces `base**lo` in the inner function.
#
# If an algorithm wants the powers of ceiling(w/2) instead of the floor,
# pass keyword argument `need_hi=True`.
#
# While this does give minor speedups (a few percent at best), the
# primary intent is to simplify the functions using this, by eliminating
# the need for them to craft their own ad-hoc caching schemes.
#
# See code near end of file for a block of code that can be enabled to
# run millions of tests.
def compute_powers(w, base, more_than, *, need_hi=False, show=False):
seen = set()
need = set()
ws = {w}
while ws:
w = ws.pop() # any element is fine to use next
if w in seen or w <= more_than:
continue
seen.add(w)
lo = w >> 1
hi = w - lo
# only _need_ one here; the other may, or may not, be needed
which = hi if need_hi else lo
need.add(which)
ws.add(which)
if lo != hi:
ws.add(w - which)
# `need` is the set of exponents needed. To compute them all
# efficiently, possibly add other exponents to `extra`. The goal is
# to ensure that each exponent can be gotten from a smaller one via
# multiplying by the base, squaring it, or squaring and then
# multiplying by the base.
#
# If need_hi is False, this is already the case (w can always be
# gotten from w >> 1 via one of the squaring strategies). But we do
# the work anyway, just in case ;-)
#
# Note that speed is irrelevant. These loops are working on little
# ints (exponents) and go around O(log w) times. The total cost is
# insignificant compared to just one of the bigint multiplies.
cands = need.copy()
extra = set()
while cands:
w = max(cands)
cands.remove(w)
lo = w >> 1
if lo > more_than and w-1 not in cands and lo not in cands:
extra.add(lo)
cands.add(lo)
assert need_hi or not extra
d = {}
for n in sorted(need | extra):
lo = n >> 1
hi = n - lo
if n-1 in d:
if show:
print("* base", end="")
result = d[n-1] * base # cheap!
elif lo in d:
# Multiplying a bigint by itself is about twice as fast
# in CPython provided it's the same object.
if show:
print("square", end="")
result = d[lo] * d[lo] # same object
if hi != lo:
if show:
print(" * base", end="")
assert 2 * lo + 1 == n
result *= base
else: # rare
if show:
print("pow", end='')
result = base ** n
if show:
print(" at", n, "needed" if n in need else "extra")
d[n] = result
assert need <= d.keys()
if excess := d.keys() - need:
assert need_hi
for n in excess:
del d[n]
return d
_unbounded_dec_context = decimal.getcontext().copy()
_unbounded_dec_context.prec = decimal.MAX_PREC
_unbounded_dec_context.Emax = decimal.MAX_EMAX
_unbounded_dec_context.Emin = decimal.MIN_EMIN
_unbounded_dec_context.traps[decimal.Inexact] = 1 # sanity check
def int_to_decimal(n):
"""Asymptotically fast conversion of an 'int' to Decimal."""
# Function due to Tim Peters. See GH issue #90716 for details.
# https://github.com/python/cpython/issues/90716
#
# The implementation in longobject.c of base conversion algorithms
# between power-of-2 and non-power-of-2 bases are quadratic time.
# This function implements a divide-and-conquer algorithm that is
# faster for large numbers. Builds an equal decimal.Decimal in a
# "clever" recursive way. If we want a string representation, we
# apply str to _that_.
from decimal import Decimal as D
BITLIM = 200
# Don't bother caching the "lo" mask in this; the time to compute it is
# tiny compared to the multiply.
def inner(n, w):
if w <= BITLIM:
return D(n)
w2 = w >> 1
hi = n >> w2
lo = n & ((1 << w2) - 1)
return inner(lo, w2) + inner(hi, w - w2) * w2pow[w2]
with decimal.localcontext(_unbounded_dec_context):
nbits = n.bit_length()
w2pow = compute_powers(nbits, D(2), BITLIM)
if n < 0:
negate = True
n = -n
else:
negate = False
result = inner(n, nbits)
if negate:
result = -result
return result
def int_to_decimal_string(n):
"""Asymptotically fast conversion of an 'int' to a decimal string."""
w = n.bit_length()
if w > 450_000 and _decimal is not None:
# It is only usable with the C decimal implementation.
# _pydecimal.py calls str() on very large integers, which in its
# turn calls int_to_decimal_string(), causing very deep recursion.
return str(int_to_decimal(n))
# Fallback algorithm for the case when the C decimal module isn't
# available. This algorithm is asymptotically worse than the algorithm
# using the decimal module, but better than the quadratic time
# implementation in longobject.c.
DIGLIM = 1000
def inner(n, w):
if w <= DIGLIM:
return str(n)
w2 = w >> 1
hi, lo = divmod(n, pow10[w2])
return inner(hi, w - w2) + inner(lo, w2).zfill(w2)
# The estimation of the number of decimal digits.
# There is no harm in small error. If we guess too large, there may
# be leading 0's that need to be stripped. If we guess too small, we
# may need to call str() recursively for the remaining highest digits,
# which can still potentially be a large integer. This is manifested
# only if the number has way more than 10**15 digits, that exceeds
# the 52-bit physical address limit in both Intel64 and AMD64.
w = int(w * 0.3010299956639812 + 1) # log10(2)
pow10 = compute_powers(w, 5, DIGLIM)
for k, v in pow10.items():
pow10[k] = v << k # 5**k << k == 5**k * 2**k == 10**k
if n < 0:
n = -n
sign = '-'
else:
sign = ''
s = inner(n, w)
if s[0] == '0' and n:
# If our guess of w is too large, there may be leading 0's that
# need to be stripped.
s = s.lstrip('0')
return sign + s
def _str_to_int_inner(s):
"""Asymptotically fast conversion of a 'str' to an 'int'."""
# Function due to Bjorn Martinsson. See GH issue #90716 for details.
# https://github.com/python/cpython/issues/90716
#
# The implementation in longobject.c of base conversion algorithms
# between power-of-2 and non-power-of-2 bases are quadratic time.
# This function implements a divide-and-conquer algorithm making use
# of Python's built in big int multiplication. Since Python uses the
# Karatsuba algorithm for multiplication, the time complexity
# of this function is O(len(s)**1.58).
DIGLIM = 2048
def inner(a, b):
if b - a <= DIGLIM:
return int(s[a:b])
mid = (a + b + 1) >> 1
return (inner(mid, b)
+ ((inner(a, mid) * w5pow[b - mid])
<< (b - mid)))
w5pow = compute_powers(len(s), 5, DIGLIM)
return inner(0, len(s))
# Asymptotically faster version, using the C decimal module. See
# comments at the end of the file. This uses decimal arithmetic to
# convert from base 10 to base 256. The latter is just a string of
# bytes, which CPython can convert very efficiently to a Python int.
# log of 10 to base 256 with best-possible 53-bit precision. Obtained
# via:
# from mpmath import mp
# mp.prec = 1000
# print(float(mp.log(10, 256)).hex())
_LOG_10_BASE_256 = float.fromhex('0x1.a934f0979a371p-2') # about 0.415
# _spread is for internal testing. It maps a key to the number of times
# that condition obtained in _dec_str_to_int_inner:
# key 0 - quotient guess was right
# key 1 - quotient had to be boosted by 1, one time
# key 999 - one adjustment wasn't enough, so fell back to divmod
from collections import defaultdict
_spread = defaultdict(int)
del defaultdict
def _dec_str_to_int_inner(s, *, GUARD=8):
# Yes, BYTELIM is "large". Large enough that CPython will usually
# use the Karatsuba _str_to_int_inner to convert the string. This
# allowed reducing the cutoff for calling _this_ function from 3.5M
# to 2M digits. We could almost certainly do even better by
# fine-tuning this and/or using a larger output base than 256.
BYTELIM = 100_000
D = decimal.Decimal
result = bytearray()
# See notes at end of file for discussion of GUARD.
assert GUARD > 0 # if 0, `decimal` can blow up - .prec 0 not allowed
def inner(n, w):
#assert n < D256 ** w # required, but too expensive to check
if w <= BYTELIM:
# XXX Stefan Pochmann discovered that, for 1024-bit ints,
# `int(Decimal)` took 2.5x longer than `int(str(Decimal))`.
# Worse, `int(Decimal) is still quadratic-time for much
# larger ints. So unless/until all that is repaired, the
# seemingly redundant `str(Decimal)` is crucial to speed.
result.extend(int(str(n)).to_bytes(w)) # big-endian default
return
w1 = w >> 1
w2 = w - w1
if 0:
# This is maximally clear, but "too slow". `decimal`
# division is asymptotically fast, but we have no way to
# tell it to reuse the high-precision reciprocal it computes
# for pow256[w2], so it has to recompute it over & over &
# over again :-(
hi, lo = divmod(n, pow256[w2][0])
else:
p256, recip = pow256[w2]
# The integer part will have a number of digits about equal
# to the difference between the log10s of `n` and `pow256`
# (which, since these are integers, is roughly approximated
# by `.adjusted()`). That's the working precision we need,
ctx.prec = max(n.adjusted() - p256.adjusted(), 0) + GUARD
hi = +n * +recip # unary `+` chops back to ctx.prec digits
ctx.prec = decimal.MAX_PREC
hi = hi.to_integral_value() # lose the fractional digits
lo = n - hi * p256
# Because we've been uniformly rounding down, `hi` is a
# lower bound on the correct quotient.
assert lo >= 0
# Adjust quotient up if needed. It usually isn't. In random
# testing on inputs through 5 billion digit strings, the
# test triggered once in about 200 thousand tries.
count = 0
if lo >= p256:
count = 1
lo -= p256
hi += 1
if lo >= p256:
# Complete correction via an exact computation. I
# believe it's not possible to get here provided
# GUARD >= 3. It's tested by reducing GUARD below
# that.
count = 999
hi2, lo = divmod(lo, p256)
hi += hi2
_spread[count] += 1
# The assert should always succeed, but way too slow to keep
# enabled.
#assert hi, lo == divmod(n, pow256[w2][0])
inner(hi, w1)
del hi # at top levels, can free a lot of RAM "early"
inner(lo, w2)
# How many base 256 digits are needed?. Mathematically, exactly
# floor(log256(int(s))) + 1. There is no cheap way to compute this.
# But we can get an upper bound, and that's necessary for our error
# analysis to make sense. int(s) < 10**len(s), so the log needed is
# < log256(10**len(s)) = len(s) * log256(10). However, using
# finite-precision floating point for this, it's possible that the
# computed value is a little less than the true value. If the true
# value is at - or a little higher than - an integer, we can get an
# off-by-1 error too low. So we add 2 instead of 1 if chopping lost
# a fraction > 0.9.
# The "WASI" test platform can complain about `len(s)` if it's too
# large to fit in its idea of "an index-sized integer".
lenS = s.__len__()
log_ub = lenS * _LOG_10_BASE_256
log_ub_as_int = int(log_ub)
w = log_ub_as_int + 1 + (log_ub - log_ub_as_int > 0.9)
# And what if we've plain exhausted the limits of HW floats? We
# could compute the log to any desired precision using `decimal`,
# but it's not plausible that anyone will pass a string requiring
# trillions of bytes (unless they're just trying to "break things").
if w.bit_length() >= 46:
# "Only" had < 53 - 46 = 7 bits to spare in IEEE-754 double.
raise ValueError(f"cannot convert string of len {lenS} to int")
with decimal.localcontext(_unbounded_dec_context) as ctx:
D256 = D(256)
pow256 = compute_powers(w, D256, BYTELIM, need_hi=True)
rpow256 = compute_powers(w, 1 / D256, BYTELIM, need_hi=True)
# We're going to do inexact, chopped arithmetic, multiplying by
# an approximation to the reciprocal of 256**i. We chop to get a
# lower bound on the true integer quotient. Our approximation is
# a lower bound, the multiplication is chopped too, and
# to_integral_value() is also chopped.
ctx.traps[decimal.Inexact] = 0
ctx.rounding = decimal.ROUND_DOWN
for k, v in pow256.items():
# No need to save much more precision in the reciprocal than
# the power of 256 has, plus some guard digits to absorb
# most relevant rounding errors. This is highly significant:
# 1/2**i has the same number of significant decimal digits
# as 5**i, generally over twice the number in 2**i,
ctx.prec = v.adjusted() + GUARD + 1
# The unary "+" chops the reciprocal back to that precision.
pow256[k] = v, +rpow256[k]
del rpow256 # exact reciprocals no longer needed
ctx.prec = decimal.MAX_PREC
inner(D(s), w)
return int.from_bytes(result)
def int_from_string(s):
"""Asymptotically fast version of PyLong_FromString(), conversion
of a string of decimal digits into an 'int'."""
# PyLong_FromString() has already removed leading +/-, checked for invalid
# use of underscore characters, checked that string consists of only digits
# and underscores, and stripped leading whitespace. The input can still
# contain underscores and have trailing whitespace.
s = s.rstrip().replace('_', '')
func = _str_to_int_inner
if len(s) >= 2_000_000 and _decimal is not None:
func = _dec_str_to_int_inner
return func(s)
def str_to_int(s):
"""Asymptotically fast version of decimal string to 'int' conversion."""
# FIXME: this doesn't support the full syntax that int() supports.
m = re.match(r'\s*([+-]?)([0-9_]+)\s*', s)
if not m:
raise ValueError('invalid literal for int() with base 10')
v = int_from_string(m.group(2))
if m.group(1) == '-':
v = -v
return v
# Fast integer division, based on code from Mark Dickinson, fast_div.py
# GH-47701. Additional refinements and optimizations by Bjorn Martinsson. The
# algorithm is due to Burnikel and Ziegler, in their paper "Fast Recursive
# Division".
_DIV_LIMIT = 4000
def _div2n1n(a, b, n):
"""Divide a 2n-bit nonnegative integer a by an n-bit positive integer
b, using a recursive divide-and-conquer algorithm.
Inputs:
n is a positive integer
b is a positive integer with exactly n bits
a is a nonnegative integer such that a < 2**n * b
Output:
(q, r) such that a = b*q+r and 0 <= r < b.
"""
if a.bit_length() - n <= _DIV_LIMIT:
return divmod(a, b)
pad = n & 1
if pad:
a <<= 1
b <<= 1
n += 1
half_n = n >> 1
mask = (1 << half_n) - 1
b1, b2 = b >> half_n, b & mask
q1, r = _div3n2n(a >> n, (a >> half_n) & mask, b, b1, b2, half_n)
q2, r = _div3n2n(r, a & mask, b, b1, b2, half_n)
if pad:
r >>= 1
return q1 << half_n | q2, r
def _div3n2n(a12, a3, b, b1, b2, n):
"""Helper function for _div2n1n; not intended to be called directly."""
if a12 >> n == b1:
q, r = (1 << n) - 1, a12 - (b1 << n) + b1
else:
q, r = _div2n1n(a12, b1, n)
r = (r << n | a3) - q * b2
while r < 0:
q -= 1
r += b
return q, r
def _int2digits(a, n):
"""Decompose non-negative int a into base 2**n
Input:
a is a non-negative integer
Output:
List of the digits of a in base 2**n in little-endian order,
meaning the most significant digit is last. The most
significant digit is guaranteed to be non-zero.
If a is 0 then the output is an empty list.
"""
a_digits = [0] * ((a.bit_length() + n - 1) // n)
def inner(x, L, R):
if L + 1 == R:
a_digits[L] = x
return
mid = (L + R) >> 1
shift = (mid - L) * n
upper = x >> shift
lower = x ^ (upper << shift)
inner(lower, L, mid)
inner(upper, mid, R)
if a:
inner(a, 0, len(a_digits))
return a_digits
def _digits2int(digits, n):
"""Combine base-2**n digits into an int. This function is the
inverse of `_int2digits`. For more details, see _int2digits.
"""
def inner(L, R):
if L + 1 == R:
return digits[L]
mid = (L + R) >> 1
shift = (mid - L) * n
return (inner(mid, R) << shift) + inner(L, mid)
return inner(0, len(digits)) if digits else 0
def _divmod_pos(a, b):
"""Divide a non-negative integer a by a positive integer b, giving
quotient and remainder."""
# Use grade-school algorithm in base 2**n, n = nbits(b)
n = b.bit_length()
a_digits = _int2digits(a, n)
r = 0
q_digits = []
for a_digit in reversed(a_digits):
q_digit, r = _div2n1n((r << n) + a_digit, b, n)
q_digits.append(q_digit)
q_digits.reverse()
q = _digits2int(q_digits, n)
return q, r
def int_divmod(a, b):
"""Asymptotically fast replacement for divmod, for 'int'.
Its time complexity is O(n**1.58), where n = #bits(a) + #bits(b).
"""
if b == 0:
raise ZeroDivisionError('division by zero')
elif b < 0:
q, r = int_divmod(-a, -b)
return q, -r
elif a < 0:
q, r = int_divmod(~a, b)
return ~q, b + ~r
else:
return _divmod_pos(a, b)
# Notes on _dec_str_to_int_inner:
#
# Stefan Pochmann worked up a str->int function that used the decimal
# module to, in effect, convert from base 10 to base 256. This is
# "unnatural", in that it requires multiplying and dividing by large
# powers of 2, which `decimal` isn't naturally suited to. But
# `decimal`'s `*` and `/` are asymptotically superior to CPython's, so
# at _some_ point it could be expected to win.
#
# Alas, the crossover point was too high to be of much real interest. I
# (Tim) then worked on ways to replace its division with multiplication
# by a cached reciprocal approximation instead, fixing up errors
# afterwards. This reduced the crossover point significantly,
#
# I revisited the code, and found ways to improve and simplify it. The
# crossover point is at about 3.4 million digits now.
#
# About .adjusted()
# -----------------
# Restrict to Decimal values x > 0. We don't use negative numbers in the
# code, and I don't want to have to keep typing, e.g., "absolute value".
#
# For convenience, I'll use `x.a` to mean `x.adjusted()`. x.a doesn't
# look at the digits of x, but instead returns an integer giving x's
# order of magnitude. These are equivalent:
#
# - x.a is the power-of-10 exponent of x's most significant digit.
# - x.a = the infinitely precise floor(log10(x))
# - x can be written in this form, where f is a real with 1 <= f < 10:
# x = f * 10**x.a
#
# Observation; if x is an integer, len(str(x)) = x.a + 1.
#
# Lemma 1: (x * y).a = x.a + y.a, or one larger
#
# Proof: Write x = f * 10**x.a and y = g * 10**y.a, where f and g are in
# [1, 10). Then x*y = f*g * 10**(x.a + y.a), where 1 <= f*g < 100. If
# f*g < 10, (x*y).a is x.a+y.a. Else divide f*g by 10 to bring it back
# into [1, 10], and add 1 to the exponent to compensate. Then (x*y).a is
# x.a+y.a+1.
#
# Lemma 2: ceiling(log10(x/y)) <= x.a - y.a + 1
#
# Proof: Express x and y as in Lemma 1. Then x/y = f/g * 10**(x.a -
# y.a), where 1/10 < f/g < 10. If 1 <= f/g, (x/y).a is x.a-y.a. Else
# multiply f/g by 10 to bring it back into [1, 10], and subtract 1 from
# the exponent to compensate. Then (x/y).a is x.a-y.a-1. So the largest
# (x/y).a can be is x.a-y.a. Since that's the floor of log10(x/y). the
# ceiling is at most 1 larger (with equality iff f/g = 1 exactly).
#
# GUARD digits
# ------------
# We only want the integer part of divisions, so don't need to build
# the full multiplication tree. But using _just_ the number of
# digits expected in the integer part ignores too much. What's left
# out can have a very significant effect on the quotient. So we use
# GUARD additional digits.
#
# The default 8 is more than enough so no more than 1 correction step
# was ever needed for all inputs tried through 2.5 billion digits. In
# fact, I believe 3 guard digits are always enough - but the proof is
# very involved, so better safe than sorry.
#
# Short course:
#
# If prec is the decimal precision in effect, and we're rounding down,
# the result of an operation is exactly equal to the infinitely precise
# result times 1-e for some real e with 0 <= e < 10**(1-prec). In
#
# ctx.prec = max(n.adjusted() - p256.adjusted(), 0) + GUARD
# hi = +n * +recip # unary `+` chops to ctx.prec digits
#
# we have 3 visible chopped operations, but there's also a 4th:
# precomputing a truncated `recip` as part of setup.
#
# So the computed product is exactly equal to the true product times
# (1-e1)*(1-e2)*(1-e3)*(1-e4); since the e's are all very small, an
# excellent approximation to the second factor is 1-(e1+e2+e3+e4) (the
# 2nd and higher order terms in the expanded product are too tiny to
# matter). If they're all as large as possible, that's
#
# 1 - 4*10**(1-prec). This, BTW, is all bog-standard FP error analysis.
#
# That implies the computed product is within 1 of the true product
# provided prec >= log10(true_product) + 1.602.
#
# Here are telegraphic details, rephrasing the initial condition in
# equivalent ways, step by step:
#
# prod - prod * (1 - 4*10**(1-prec)) <= 1
# prod - prod + prod * 4*10**(1-prec)) <= 1
# prod * 4*10**(1-prec)) <= 1
# 10**(log10(prod)) * 4*10**(1-prec)) <= 1
# 4*10**(1-prec+log10(prod))) <= 1
# 10**(1-prec+log10(prod))) <= 1/4
# 1-prec+log10(prod) <= log10(1/4) = -0.602
# -prec <= -1.602 - log10(prod)
# prec >= log10(prod) + 1.602
#
# The true product is the same as the true ratio n/p256. By Lemma 2
# above, n.a - p256.a + 1 is an upper bound on the ceiling of
# log10(prod). Then 2 is the ceiling of 1.602. so n.a - p256.a + 3 is an
# upper bound on the right hand side of the inequality. Any prec >= that
# will work.
#
# But since this is just a sketch of a proof ;-), the code uses the
# empirically tested 8 instead of 3. 5 digits more or less makes no
# practical difference to speed - these ints are huge. And while
# increasing GUARD above 3 may not be necessary, every increase cuts the
# percentage of cases that need a correction at all.
#
# On Computing Reciprocals
# ------------------------
# In general, the exact reciprocals we compute have over twice as many
# significant digits as needed. 1/256**i has the same number of
# significant decimal digits as 5**i. It's a significant waste of RAM
# to store all those unneeded digits.
#
# So we cut exact reciprocals back to the least precision that can
# be needed so that the error analysis above is valid,
#
# [Note: turns out it's very significantly faster to do it this way than
# to compute 1 / 256**i directly to the desired precision, because the
# power method doesn't require division. It's also faster than computing
# (1/256)**i directly to the desired precision - no material division
# there, but `compute_powers()` is much smarter about _how_ to compute
# all the powers needed than repeated applications of `**` - that
# function invokes `**` for at most the few smallest powers needed.]
#
# The hard part is that chopping back to a shorter width occurs
# _outside_ of `inner`. We can't know then what `prec` `inner()` will
# need. We have to pick, for each value of `w2`, the largest possible
# value `prec` can become when `inner()` is working on `w2`.
#
# This is the `prec` inner() uses:
# max(n.a - p256.a, 0) + GUARD
# and what setup uses (renaming its `v` to `p256` - same thing):
# p256.a + GUARD + 1
#
# We need that the second is always at least as large as the first,
# which is the same as requiring
#
# n.a - 2 * p256.a <= 1
#
# What's the largest n can be? n < 255**w = 256**(w2 + (w - w2)). The
# worst case in this context is when w ix even. and then w = 2*w2, so
# n < 256**(2*w2) = (256**w2)**2 = p256**2. By Lemma 1, then, n.a
# is at most p256.a + p256.a + 1.
#
# So the most n.a - 2 * p256.a can be is
# p256.a + p256.a + 1 - 2 * p256.a = 1. QED
#
# Note: an earlier version of the code split on floor(e/2) instead of on
# the ceiling. The worst case then is odd `w`, and a more involved proof
# was needed to show that adding 4 (instead of 1) may be necessary.
# Basically because, in that case, n may be up to 256 times larger than
# p256**2. Curiously enough, by splitting on the ceiling instead,
# nothing in any proof here actually depends on the output base (256).
# Enable for brute-force testing of compute_powers(). This takes about a
# minute, because it tries millions of cases.
if 0:
def consumer(w, limit, need_hi):
seen = set()
need = set()
def inner(w):
if w <= limit:
return
if w in seen:
return
seen.add(w)
lo = w >> 1
hi = w - lo
need.add(hi if need_hi else lo)
inner(lo)
inner(hi)
inner(w)
exp = compute_powers(w, 1, limit, need_hi=need_hi)
assert exp.keys() == need
from itertools import chain
for need_hi in (False, True):
for limit in (0, 1, 10, 100, 1_000, 10_000, 100_000):
for w in chain(range(1, 100_000),
(10**i for i in range(5, 30))):
consumer(w, limit, need_hi)

19
Lib/_pyrepl/__init__.py vendored Normal file
View File

@@ -0,0 +1,19 @@
# Copyright 2000-2008 Michael Hudson-Doyle <micahel@gmail.com>
# Armin Rigo
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

6
Lib/_pyrepl/__main__.py vendored Normal file
View File

@@ -0,0 +1,6 @@
# Important: don't add things to this module, as they will end up in the REPL's
# default globals. Use _pyrepl.main instead.
if __name__ == "__main__":
from .main import interactive_console as __pyrepl_interactive_console
__pyrepl_interactive_console()

68
Lib/_pyrepl/_minimal_curses.py vendored Normal file
View File

@@ -0,0 +1,68 @@
"""Minimal '_curses' module, the low-level interface for curses module
which is not meant to be used directly.
Based on ctypes. It's too incomplete to be really called '_curses', so
to use it, you have to import it and stick it in sys.modules['_curses']
manually.
Note that there is also a built-in module _minimal_curses which will
hide this one if compiled in.
"""
import ctypes
import ctypes.util
class error(Exception):
pass
def _find_clib() -> str:
trylibs = ["ncursesw", "ncurses", "curses"]
for lib in trylibs:
path = ctypes.util.find_library(lib)
if path:
return path
raise ModuleNotFoundError("curses library not found", name="_pyrepl._minimal_curses")
_clibpath = _find_clib()
clib = ctypes.cdll.LoadLibrary(_clibpath)
clib.setupterm.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.POINTER(ctypes.c_int)]
clib.setupterm.restype = ctypes.c_int
clib.tigetstr.argtypes = [ctypes.c_char_p]
clib.tigetstr.restype = ctypes.c_ssize_t
clib.tparm.argtypes = [ctypes.c_char_p] + 9 * [ctypes.c_int] # type: ignore[operator]
clib.tparm.restype = ctypes.c_char_p
OK = 0
ERR = -1
# ____________________________________________________________
def setupterm(termstr, fd):
err = ctypes.c_int(0)
result = clib.setupterm(termstr, fd, ctypes.byref(err))
if result == ERR:
raise error("setupterm() failed (err=%d)" % err.value)
def tigetstr(cap):
if not isinstance(cap, bytes):
cap = cap.encode("ascii")
result = clib.tigetstr(cap)
if result == ERR:
return None
return ctypes.cast(result, ctypes.c_char_p).value
def tparm(str, i1=0, i2=0, i3=0, i4=0, i5=0, i6=0, i7=0, i8=0, i9=0):
result = clib.tparm(str, i1, i2, i3, i4, i5, i6, i7, i8, i9)
if result is None:
raise error("tparm() returned NULL")
return result

74
Lib/_pyrepl/_threading_handler.py vendored Normal file
View File

@@ -0,0 +1,74 @@
from __future__ import annotations
from dataclasses import dataclass, field
import traceback
TYPE_CHECKING = False
if TYPE_CHECKING:
from threading import Thread
from types import TracebackType
from typing import Protocol
class ExceptHookArgs(Protocol):
@property
def exc_type(self) -> type[BaseException]: ...
@property
def exc_value(self) -> BaseException | None: ...
@property
def exc_traceback(self) -> TracebackType | None: ...
@property
def thread(self) -> Thread | None: ...
class ShowExceptions(Protocol):
def __call__(self) -> int: ...
def add(self, s: str) -> None: ...
from .reader import Reader
def install_threading_hook(reader: Reader) -> None:
import threading
@dataclass
class ExceptHookHandler:
lock: threading.Lock = field(default_factory=threading.Lock)
messages: list[str] = field(default_factory=list)
def show(self) -> int:
count = 0
with self.lock:
if not self.messages:
return 0
reader.restore()
for tb in self.messages:
count += 1
if tb:
print(tb)
self.messages.clear()
reader.scheduled_commands.append("ctrl-c")
reader.prepare()
return count
def add(self, s: str) -> None:
with self.lock:
self.messages.append(s)
def exception(self, args: ExceptHookArgs) -> None:
lines = traceback.format_exception(
args.exc_type,
args.exc_value,
args.exc_traceback,
colorize=reader.can_colorize,
) # type: ignore[call-overload]
pre = f"\nException in {args.thread.name}:\n" if args.thread else "\n"
tb = pre + "".join(lines)
self.add(tb)
def __call__(self) -> int:
return self.show()
handler = ExceptHookHandler()
reader.threading_hook = handler
threading.excepthook = handler.exception

489
Lib/_pyrepl/commands.py vendored Normal file
View File

@@ -0,0 +1,489 @@
# Copyright 2000-2010 Michael Hudson-Doyle <micahel@gmail.com>
# Antonio Cuni
# Armin Rigo
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import annotations
import os
# Categories of actions:
# killing
# yanking
# motion
# editing
# history
# finishing
# [completion]
# types
if False:
from .historical_reader import HistoricalReader
class Command:
finish: bool = False
kills_digit_arg: bool = True
def __init__(
self, reader: HistoricalReader, event_name: str, event: list[str]
) -> None:
# Reader should really be "any reader" but there's too much usage of
# HistoricalReader methods and fields in the code below for us to
# refactor at the moment.
self.reader = reader
self.event = event
self.event_name = event_name
def do(self) -> None:
pass
class KillCommand(Command):
def kill_range(self, start: int, end: int) -> None:
if start == end:
return
r = self.reader
b = r.buffer
text = b[start:end]
del b[start:end]
if is_kill(r.last_command):
if start < r.pos:
r.kill_ring[-1] = text + r.kill_ring[-1]
else:
r.kill_ring[-1] = r.kill_ring[-1] + text
else:
r.kill_ring.append(text)
r.pos = start
r.dirty = True
class YankCommand(Command):
pass
class MotionCommand(Command):
pass
class EditCommand(Command):
pass
class FinishCommand(Command):
finish = True
pass
def is_kill(command: type[Command] | None) -> bool:
return command is not None and issubclass(command, KillCommand)
def is_yank(command: type[Command] | None) -> bool:
return command is not None and issubclass(command, YankCommand)
# etc
class digit_arg(Command):
kills_digit_arg = False
def do(self) -> None:
r = self.reader
c = self.event[-1]
if c == "-":
if r.arg is not None:
r.arg = -r.arg
else:
r.arg = -1
else:
d = int(c)
if r.arg is None:
r.arg = d
else:
if r.arg < 0:
r.arg = 10 * r.arg - d
else:
r.arg = 10 * r.arg + d
r.dirty = True
class clear_screen(Command):
def do(self) -> None:
r = self.reader
r.console.clear()
r.dirty = True
class refresh(Command):
def do(self) -> None:
self.reader.dirty = True
class repaint(Command):
def do(self) -> None:
self.reader.dirty = True
self.reader.console.repaint()
class kill_line(KillCommand):
def do(self) -> None:
r = self.reader
b = r.buffer
eol = r.eol()
for c in b[r.pos : eol]:
if not c.isspace():
self.kill_range(r.pos, eol)
return
else:
self.kill_range(r.pos, eol + 1)
class unix_line_discard(KillCommand):
def do(self) -> None:
r = self.reader
self.kill_range(r.bol(), r.pos)
class unix_word_rubout(KillCommand):
def do(self) -> None:
r = self.reader
for i in range(r.get_arg()):
self.kill_range(r.bow(), r.pos)
class kill_word(KillCommand):
def do(self) -> None:
r = self.reader
for i in range(r.get_arg()):
self.kill_range(r.pos, r.eow())
class backward_kill_word(KillCommand):
def do(self) -> None:
r = self.reader
for i in range(r.get_arg()):
self.kill_range(r.bow(), r.pos)
class yank(YankCommand):
def do(self) -> None:
r = self.reader
if not r.kill_ring:
r.error("nothing to yank")
return
r.insert(r.kill_ring[-1])
class yank_pop(YankCommand):
def do(self) -> None:
r = self.reader
b = r.buffer
if not r.kill_ring:
r.error("nothing to yank")
return
if not is_yank(r.last_command):
r.error("previous command was not a yank")
return
repl = len(r.kill_ring[-1])
r.kill_ring.insert(0, r.kill_ring.pop())
t = r.kill_ring[-1]
b[r.pos - repl : r.pos] = t
r.pos = r.pos - repl + len(t)
r.dirty = True
class interrupt(FinishCommand):
def do(self) -> None:
import signal
self.reader.console.finish()
self.reader.finish()
os.kill(os.getpid(), signal.SIGINT)
class ctrl_c(Command):
def do(self) -> None:
self.reader.console.finish()
self.reader.finish()
raise KeyboardInterrupt
class suspend(Command):
def do(self) -> None:
import signal
r = self.reader
p = r.pos
r.console.finish()
os.kill(os.getpid(), signal.SIGSTOP)
## this should probably be done
## in a handler for SIGCONT?
r.console.prepare()
r.pos = p
# r.posxy = 0, 0 # XXX this is invalid
r.dirty = True
r.console.screen = []
class up(MotionCommand):
def do(self) -> None:
r = self.reader
for _ in range(r.get_arg()):
x, y = r.pos2xy()
new_y = y - 1
if r.bol() == 0:
if r.historyi > 0:
r.select_item(r.historyi - 1)
return
r.pos = 0
r.error("start of buffer")
return
if (
x
> (
new_x := r.max_column(new_y)
) # we're past the end of the previous line
or x == r.max_column(y)
and any(
not i.isspace() for i in r.buffer[r.bol() :]
) # move between eols
):
x = new_x
r.setpos_from_xy(x, new_y)
class down(MotionCommand):
def do(self) -> None:
r = self.reader
b = r.buffer
for _ in range(r.get_arg()):
x, y = r.pos2xy()
new_y = y + 1
if r.eol() == len(b):
if r.historyi < len(r.history):
r.select_item(r.historyi + 1)
r.pos = r.eol(0)
return
r.pos = len(b)
r.error("end of buffer")
return
if (
x
> (
new_x := r.max_column(new_y)
) # we're past the end of the previous line
or x == r.max_column(y)
and any(
not i.isspace() for i in r.buffer[r.bol() :]
) # move between eols
):
x = new_x
r.setpos_from_xy(x, new_y)
class left(MotionCommand):
def do(self) -> None:
r = self.reader
for _ in range(r.get_arg()):
p = r.pos - 1
if p >= 0:
r.pos = p
else:
self.reader.error("start of buffer")
class right(MotionCommand):
def do(self) -> None:
r = self.reader
b = r.buffer
for _ in range(r.get_arg()):
p = r.pos + 1
if p <= len(b):
r.pos = p
else:
self.reader.error("end of buffer")
class beginning_of_line(MotionCommand):
def do(self) -> None:
self.reader.pos = self.reader.bol()
class end_of_line(MotionCommand):
def do(self) -> None:
self.reader.pos = self.reader.eol()
class home(MotionCommand):
def do(self) -> None:
self.reader.pos = 0
class end(MotionCommand):
def do(self) -> None:
self.reader.pos = len(self.reader.buffer)
class forward_word(MotionCommand):
def do(self) -> None:
r = self.reader
for i in range(r.get_arg()):
r.pos = r.eow()
class backward_word(MotionCommand):
def do(self) -> None:
r = self.reader
for i in range(r.get_arg()):
r.pos = r.bow()
class self_insert(EditCommand):
def do(self) -> None:
r = self.reader
text = self.event * r.get_arg()
r.insert(text)
class insert_nl(EditCommand):
def do(self) -> None:
r = self.reader
r.insert("\n" * r.get_arg())
class transpose_characters(EditCommand):
def do(self) -> None:
r = self.reader
b = r.buffer
s = r.pos - 1
if s < 0:
r.error("cannot transpose at start of buffer")
else:
if s == len(b):
s -= 1
t = min(s + r.get_arg(), len(b) - 1)
c = b[s]
del b[s]
b.insert(t, c)
r.pos = t
r.dirty = True
class backspace(EditCommand):
def do(self) -> None:
r = self.reader
b = r.buffer
for i in range(r.get_arg()):
if r.pos > 0:
r.pos -= 1
del b[r.pos]
r.dirty = True
else:
self.reader.error("can't backspace at start")
class delete(EditCommand):
def do(self) -> None:
r = self.reader
b = r.buffer
if (
r.pos == 0
and len(b) == 0 # this is something of a hack
and self.event[-1] == "\004"
):
r.update_screen()
r.console.finish()
raise EOFError
for i in range(r.get_arg()):
if r.pos != len(b):
del b[r.pos]
r.dirty = True
else:
self.reader.error("end of buffer")
class accept(FinishCommand):
def do(self) -> None:
pass
class help(Command):
def do(self) -> None:
import _sitebuiltins
with self.reader.suspend():
self.reader.msg = _sitebuiltins._Helper()() # type: ignore[assignment, call-arg]
class invalid_key(Command):
def do(self) -> None:
pending = self.reader.console.getpending()
s = "".join(self.event) + pending.data
self.reader.error("`%r' not bound" % s)
class invalid_command(Command):
def do(self) -> None:
s = self.event_name
self.reader.error("command `%s' not known" % s)
class show_history(Command):
def do(self) -> None:
from .pager import get_pager
from site import gethistoryfile # type: ignore[attr-defined]
history = os.linesep.join(self.reader.history[:])
self.reader.console.restore()
pager = get_pager()
pager(history, gethistoryfile())
self.reader.console.prepare()
# We need to copy over the state so that it's consistent between
# console and reader, and console does not overwrite/append stuff
self.reader.console.screen = self.reader.screen.copy()
self.reader.console.posxy = self.reader.cxy
class paste_mode(Command):
def do(self) -> None:
self.reader.paste_mode = not self.reader.paste_mode
self.reader.dirty = True
class enable_bracketed_paste(Command):
def do(self) -> None:
self.reader.paste_mode = True
self.reader.in_bracketed_paste = True
class disable_bracketed_paste(Command):
def do(self) -> None:
self.reader.paste_mode = False
self.reader.in_bracketed_paste = False
self.reader.dirty = True

295
Lib/_pyrepl/completing_reader.py vendored Normal file
View File

@@ -0,0 +1,295 @@
# Copyright 2000-2010 Michael Hudson-Doyle <micahel@gmail.com>
# Antonio Cuni
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import annotations
from dataclasses import dataclass, field
import re
from . import commands, console, reader
from .reader import Reader
# types
Command = commands.Command
if False:
from .types import KeySpec, CommandName
def prefix(wordlist: list[str], j: int = 0) -> str:
d = {}
i = j
try:
while 1:
for word in wordlist:
d[word[i]] = 1
if len(d) > 1:
return wordlist[0][j:i]
i += 1
d = {}
except IndexError:
return wordlist[0][j:i]
return ""
STRIPCOLOR_REGEX = re.compile(r"\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[m|K]")
def stripcolor(s: str) -> str:
return STRIPCOLOR_REGEX.sub('', s)
def real_len(s: str) -> int:
return len(stripcolor(s))
def left_align(s: str, maxlen: int) -> str:
stripped = stripcolor(s)
if len(stripped) > maxlen:
# too bad, we remove the color
return stripped[:maxlen]
padding = maxlen - len(stripped)
return s + ' '*padding
def build_menu(
cons: console.Console,
wordlist: list[str],
start: int,
use_brackets: bool,
sort_in_column: bool,
) -> tuple[list[str], int]:
if use_brackets:
item = "[ %s ]"
padding = 4
else:
item = "%s "
padding = 2
maxlen = min(max(map(real_len, wordlist)), cons.width - padding)
cols = int(cons.width / (maxlen + padding))
rows = int((len(wordlist) - 1)/cols + 1)
if sort_in_column:
# sort_in_column=False (default) sort_in_column=True
# A B C A D G
# D E F B E
# G C F
#
# "fill" the table with empty words, so we always have the same amout
# of rows for each column
missing = cols*rows - len(wordlist)
wordlist = wordlist + ['']*missing
indexes = [(i % cols) * rows + i // cols for i in range(len(wordlist))]
wordlist = [wordlist[i] for i in indexes]
menu = []
i = start
for r in range(rows):
row = []
for col in range(cols):
row.append(item % left_align(wordlist[i], maxlen))
i += 1
if i >= len(wordlist):
break
menu.append(''.join(row))
if i >= len(wordlist):
i = 0
break
if r + 5 > cons.height:
menu.append(" %d more... " % (len(wordlist) - i))
break
return menu, i
# this gets somewhat user interface-y, and as a result the logic gets
# very convoluted.
#
# To summarise the summary of the summary:- people are a problem.
# -- The Hitch-Hikers Guide to the Galaxy, Episode 12
#### Desired behaviour of the completions commands.
# the considerations are:
# (1) how many completions are possible
# (2) whether the last command was a completion
# (3) if we can assume that the completer is going to return the same set of
# completions: this is controlled by the ``assume_immutable_completions``
# variable on the reader, which is True by default to match the historical
# behaviour of pyrepl, but e.g. False in the ReadlineAlikeReader to match
# more closely readline's semantics (this is needed e.g. by
# fancycompleter)
#
# if there's no possible completion, beep at the user and point this out.
# this is easy.
#
# if there's only one possible completion, stick it in. if the last thing
# user did was a completion, point out that he isn't getting anywhere, but
# only if the ``assume_immutable_completions`` is True.
#
# now it gets complicated.
#
# for the first press of a completion key:
# if there's a common prefix, stick it in.
# irrespective of whether anything got stuck in, if the word is now
# complete, show the "complete but not unique" message
# if there's no common prefix and if the word is not now complete,
# beep.
# common prefix -> yes no
# word complete \/
# yes "cbnu" "cbnu"
# no - beep
# for the second bang on the completion key
# there will necessarily be no common prefix
# show a menu of the choices.
# for subsequent bangs, rotate the menu around (if there are sufficient
# choices).
class complete(commands.Command):
def do(self) -> None:
r: CompletingReader
r = self.reader # type: ignore[assignment]
last_is_completer = r.last_command_is(self.__class__)
immutable_completions = r.assume_immutable_completions
completions_unchangable = last_is_completer and immutable_completions
stem = r.get_stem()
if not completions_unchangable:
r.cmpltn_menu_choices = r.get_completions(stem)
completions = r.cmpltn_menu_choices
if not completions:
r.error("no matches")
elif len(completions) == 1:
if completions_unchangable and len(completions[0]) == len(stem):
r.msg = "[ sole completion ]"
r.dirty = True
r.insert(completions[0][len(stem):])
else:
p = prefix(completions, len(stem))
if p:
r.insert(p)
if last_is_completer:
r.cmpltn_menu_visible = True
r.cmpltn_message_visible = False
r.cmpltn_menu, r.cmpltn_menu_end = build_menu(
r.console, completions, r.cmpltn_menu_end,
r.use_brackets, r.sort_in_column)
r.dirty = True
elif not r.cmpltn_menu_visible:
r.cmpltn_message_visible = True
if stem + p in completions:
r.msg = "[ complete but not unique ]"
r.dirty = True
else:
r.msg = "[ not unique ]"
r.dirty = True
class self_insert(commands.self_insert):
def do(self) -> None:
r: CompletingReader
r = self.reader # type: ignore[assignment]
commands.self_insert.do(self)
if r.cmpltn_menu_visible:
stem = r.get_stem()
if len(stem) < 1:
r.cmpltn_reset()
else:
completions = [w for w in r.cmpltn_menu_choices
if w.startswith(stem)]
if completions:
r.cmpltn_menu, r.cmpltn_menu_end = build_menu(
r.console, completions, 0,
r.use_brackets, r.sort_in_column)
else:
r.cmpltn_reset()
@dataclass
class CompletingReader(Reader):
"""Adds completion support"""
### Class variables
# see the comment for the complete command
assume_immutable_completions = True
use_brackets = True # display completions inside []
sort_in_column = False
### Instance variables
cmpltn_menu: list[str] = field(init=False)
cmpltn_menu_visible: bool = field(init=False)
cmpltn_message_visible: bool = field(init=False)
cmpltn_menu_end: int = field(init=False)
cmpltn_menu_choices: list[str] = field(init=False)
def __post_init__(self) -> None:
super().__post_init__()
self.cmpltn_reset()
for c in (complete, self_insert):
self.commands[c.__name__] = c
self.commands[c.__name__.replace('_', '-')] = c
def collect_keymap(self) -> tuple[tuple[KeySpec, CommandName], ...]:
return super().collect_keymap() + (
(r'\t', 'complete'),)
def after_command(self, cmd: Command) -> None:
super().after_command(cmd)
if not isinstance(cmd, (complete, self_insert)):
self.cmpltn_reset()
def calc_screen(self) -> list[str]:
screen = super().calc_screen()
if self.cmpltn_menu_visible:
# We display the completions menu below the current prompt
ly = self.lxy[1] + 1
screen[ly:ly] = self.cmpltn_menu
# If we're not in the middle of multiline edit, don't append to screeninfo
# since that screws up the position calculation in pos2xy function.
# This is a hack to prevent the cursor jumping
# into the completions menu when pressing left or down arrow.
if self.pos != len(self.buffer):
self.screeninfo[ly:ly] = [(0, [])]*len(self.cmpltn_menu)
return screen
def finish(self) -> None:
super().finish()
self.cmpltn_reset()
def cmpltn_reset(self) -> None:
self.cmpltn_menu = []
self.cmpltn_menu_visible = False
self.cmpltn_message_visible = False
self.cmpltn_menu_end = 0
self.cmpltn_menu_choices = []
def get_stem(self) -> str:
st = self.syntax_table
SW = reader.SYNTAX_WORD
b = self.buffer
p = self.pos - 1
while p >= 0 and st.get(b[p], SW) == SW:
p -= 1
return ''.join(b[p+1:self.pos])
def get_completions(self, stem: str) -> list[str]:
return []

213
Lib/_pyrepl/console.py vendored Normal file
View File

@@ -0,0 +1,213 @@
# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import annotations
import _colorize # type: ignore[import-not-found]
from abc import ABC, abstractmethod
import ast
import code
from dataclasses import dataclass, field
import os.path
import sys
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import IO
from typing import Callable
@dataclass
class Event:
evt: str
data: str
raw: bytes = b""
@dataclass
class Console(ABC):
posxy: tuple[int, int]
screen: list[str] = field(default_factory=list)
height: int = 25
width: int = 80
def __init__(
self,
f_in: IO[bytes] | int = 0,
f_out: IO[bytes] | int = 1,
term: str = "",
encoding: str = "",
):
self.encoding = encoding or sys.getdefaultencoding()
if isinstance(f_in, int):
self.input_fd = f_in
else:
self.input_fd = f_in.fileno()
if isinstance(f_out, int):
self.output_fd = f_out
else:
self.output_fd = f_out.fileno()
@abstractmethod
def refresh(self, screen: list[str], xy: tuple[int, int]) -> None: ...
@abstractmethod
def prepare(self) -> None: ...
@abstractmethod
def restore(self) -> None: ...
@abstractmethod
def move_cursor(self, x: int, y: int) -> None: ...
@abstractmethod
def set_cursor_vis(self, visible: bool) -> None: ...
@abstractmethod
def getheightwidth(self) -> tuple[int, int]:
"""Return (height, width) where height and width are the height
and width of the terminal window in characters."""
...
@abstractmethod
def get_event(self, block: bool = True) -> Event | None:
"""Return an Event instance. Returns None if |block| is false
and there is no event pending, otherwise waits for the
completion of an event."""
...
@abstractmethod
def push_char(self, char: int | bytes) -> None:
"""
Push a character to the console event queue.
"""
...
@abstractmethod
def beep(self) -> None: ...
@abstractmethod
def clear(self) -> None:
"""Wipe the screen"""
...
@abstractmethod
def finish(self) -> None:
"""Move the cursor to the end of the display and otherwise get
ready for end. XXX could be merged with restore? Hmm."""
...
@abstractmethod
def flushoutput(self) -> None:
"""Flush all output to the screen (assuming there's some
buffering going on somewhere)."""
...
@abstractmethod
def forgetinput(self) -> None:
"""Forget all pending, but not yet processed input."""
...
@abstractmethod
def getpending(self) -> Event:
"""Return the characters that have been typed but not yet
processed."""
...
@abstractmethod
def wait(self, timeout: float | None) -> bool:
"""Wait for an event. The return value is True if an event is
available, False if the timeout has been reached. If timeout is
None, wait forever. The timeout is in milliseconds."""
...
@property
def input_hook(self) -> Callable[[], int] | None:
"""Returns the current input hook."""
...
@abstractmethod
def repaint(self) -> None: ...
class InteractiveColoredConsole(code.InteractiveConsole):
def __init__(
self,
locals: dict[str, object] | None = None,
filename: str = "<console>",
*,
local_exit: bool = False,
) -> None:
super().__init__(locals=locals, filename=filename, local_exit=local_exit) # type: ignore[call-arg]
self.can_colorize = _colorize.can_colorize()
def showsyntaxerror(self, filename=None, **kwargs):
super().showsyntaxerror(filename=filename, **kwargs)
def _excepthook(self, typ, value, tb):
import traceback
lines = traceback.format_exception(
typ, value, tb,
colorize=self.can_colorize,
limit=traceback.BUILTIN_EXCEPTION_LIMIT)
self.write(''.join(lines))
def runsource(self, source, filename="<input>", symbol="single"):
try:
tree = self.compile.compiler(
source,
filename,
"exec",
ast.PyCF_ONLY_AST,
incomplete_input=False,
)
except (SyntaxError, OverflowError, ValueError):
self.showsyntaxerror(filename, source=source)
return False
if tree.body:
*_, last_stmt = tree.body
for stmt in tree.body:
wrapper = ast.Interactive if stmt is last_stmt else ast.Module
the_symbol = symbol if stmt is last_stmt else "exec"
item = wrapper([stmt])
try:
code = self.compile.compiler(item, filename, the_symbol)
except SyntaxError as e:
if e.args[0] == "'await' outside function":
python = os.path.basename(sys.executable)
e.add_note(
f"Try the asyncio REPL ({python} -m asyncio) to use"
f" top-level 'await' and run background asyncio tasks."
)
self.showsyntaxerror(filename, source=source)
return False
except (OverflowError, ValueError):
self.showsyntaxerror(filename, source=source)
return False
if code is None:
return True
self.runcode(code)
return False

33
Lib/_pyrepl/curses.py vendored Normal file
View File

@@ -0,0 +1,33 @@
# Copyright 2000-2010 Michael Hudson-Doyle <micahel@gmail.com>
# Armin Rigo
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
try:
import _curses
except ImportError:
try:
import curses as _curses # type: ignore[no-redef]
except ImportError:
from . import _minimal_curses as _curses # type: ignore[no-redef]
setupterm = _curses.setupterm
tigetstr = _curses.tigetstr
tparm = _curses.tparm
error = _curses.error

76
Lib/_pyrepl/fancy_termios.py vendored Normal file
View File

@@ -0,0 +1,76 @@
# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import termios
class TermState:
def __init__(self, tuples):
(
self.iflag,
self.oflag,
self.cflag,
self.lflag,
self.ispeed,
self.ospeed,
self.cc,
) = tuples
def as_list(self):
return [
self.iflag,
self.oflag,
self.cflag,
self.lflag,
self.ispeed,
self.ospeed,
# Always return a copy of the control characters list to ensure
# there are not any additional references to self.cc
self.cc[:],
]
def copy(self):
return self.__class__(self.as_list())
def tcgetattr(fd):
return TermState(termios.tcgetattr(fd))
def tcsetattr(fd, when, attrs):
termios.tcsetattr(fd, when, attrs.as_list())
class Term(TermState):
TS__init__ = TermState.__init__
def __init__(self, fd=0):
self.TS__init__(termios.tcgetattr(fd))
self.fd = fd
self.stack = []
def save(self):
self.stack.append(self.as_list())
def set(self, when=termios.TCSANOW):
termios.tcsetattr(self.fd, when, self.as_list())
def restore(self):
self.TS__init__(self.stack.pop())
self.set()

419
Lib/_pyrepl/historical_reader.py vendored Normal file
View File

@@ -0,0 +1,419 @@
# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import annotations
from contextlib import contextmanager
from dataclasses import dataclass, field
from . import commands, input
from .reader import Reader
if False:
from .types import SimpleContextManager, KeySpec, CommandName
isearch_keymap: tuple[tuple[KeySpec, CommandName], ...] = tuple(
[("\\%03o" % c, "isearch-end") for c in range(256) if chr(c) != "\\"]
+ [(c, "isearch-add-character") for c in map(chr, range(32, 127)) if c != "\\"]
+ [
("\\%03o" % c, "isearch-add-character")
for c in range(256)
if chr(c).isalpha() and chr(c) != "\\"
]
+ [
("\\\\", "self-insert"),
(r"\C-r", "isearch-backwards"),
(r"\C-s", "isearch-forwards"),
(r"\C-c", "isearch-cancel"),
(r"\C-g", "isearch-cancel"),
(r"\<backspace>", "isearch-backspace"),
]
)
ISEARCH_DIRECTION_NONE = ""
ISEARCH_DIRECTION_BACKWARDS = "r"
ISEARCH_DIRECTION_FORWARDS = "f"
class next_history(commands.Command):
def do(self) -> None:
r = self.reader
if r.historyi == len(r.history):
r.error("end of history list")
return
r.select_item(r.historyi + 1)
class previous_history(commands.Command):
def do(self) -> None:
r = self.reader
if r.historyi == 0:
r.error("start of history list")
return
r.select_item(r.historyi - 1)
class history_search_backward(commands.Command):
def do(self) -> None:
r = self.reader
r.search_next(forwards=False)
class history_search_forward(commands.Command):
def do(self) -> None:
r = self.reader
r.search_next(forwards=True)
class restore_history(commands.Command):
def do(self) -> None:
r = self.reader
if r.historyi != len(r.history):
if r.get_unicode() != r.history[r.historyi]:
r.buffer = list(r.history[r.historyi])
r.pos = len(r.buffer)
r.dirty = True
class first_history(commands.Command):
def do(self) -> None:
self.reader.select_item(0)
class last_history(commands.Command):
def do(self) -> None:
self.reader.select_item(len(self.reader.history))
class operate_and_get_next(commands.FinishCommand):
def do(self) -> None:
self.reader.next_history = self.reader.historyi + 1
class yank_arg(commands.Command):
def do(self) -> None:
r = self.reader
if r.last_command is self.__class__:
r.yank_arg_i += 1
else:
r.yank_arg_i = 0
if r.historyi < r.yank_arg_i:
r.error("beginning of history list")
return
a = r.get_arg(-1)
# XXX how to split?
words = r.get_item(r.historyi - r.yank_arg_i - 1).split()
if a < -len(words) or a >= len(words):
r.error("no such arg")
return
w = words[a]
b = r.buffer
if r.yank_arg_i > 0:
o = len(r.yank_arg_yanked)
else:
o = 0
b[r.pos - o : r.pos] = list(w)
r.yank_arg_yanked = w
r.pos += len(w) - o
r.dirty = True
class forward_history_isearch(commands.Command):
def do(self) -> None:
r = self.reader
r.isearch_direction = ISEARCH_DIRECTION_FORWARDS
r.isearch_start = r.historyi, r.pos
r.isearch_term = ""
r.dirty = True
r.push_input_trans(r.isearch_trans)
class reverse_history_isearch(commands.Command):
def do(self) -> None:
r = self.reader
r.isearch_direction = ISEARCH_DIRECTION_BACKWARDS
r.dirty = True
r.isearch_term = ""
r.push_input_trans(r.isearch_trans)
r.isearch_start = r.historyi, r.pos
class isearch_cancel(commands.Command):
def do(self) -> None:
r = self.reader
r.isearch_direction = ISEARCH_DIRECTION_NONE
r.pop_input_trans()
r.select_item(r.isearch_start[0])
r.pos = r.isearch_start[1]
r.dirty = True
class isearch_add_character(commands.Command):
def do(self) -> None:
r = self.reader
b = r.buffer
r.isearch_term += self.event[-1]
r.dirty = True
p = r.pos + len(r.isearch_term) - 1
if b[p : p + 1] != [r.isearch_term[-1]]:
r.isearch_next()
class isearch_backspace(commands.Command):
def do(self) -> None:
r = self.reader
if len(r.isearch_term) > 0:
r.isearch_term = r.isearch_term[:-1]
r.dirty = True
else:
r.error("nothing to rubout")
class isearch_forwards(commands.Command):
def do(self) -> None:
r = self.reader
r.isearch_direction = ISEARCH_DIRECTION_FORWARDS
r.isearch_next()
class isearch_backwards(commands.Command):
def do(self) -> None:
r = self.reader
r.isearch_direction = ISEARCH_DIRECTION_BACKWARDS
r.isearch_next()
class isearch_end(commands.Command):
def do(self) -> None:
r = self.reader
r.isearch_direction = ISEARCH_DIRECTION_NONE
r.console.forgetinput()
r.pop_input_trans()
r.dirty = True
@dataclass
class HistoricalReader(Reader):
"""Adds history support (with incremental history searching) to the
Reader class.
"""
history: list[str] = field(default_factory=list)
historyi: int = 0
next_history: int | None = None
transient_history: dict[int, str] = field(default_factory=dict)
isearch_term: str = ""
isearch_direction: str = ISEARCH_DIRECTION_NONE
isearch_start: tuple[int, int] = field(init=False)
isearch_trans: input.KeymapTranslator = field(init=False)
yank_arg_i: int = 0
yank_arg_yanked: str = ""
def __post_init__(self) -> None:
super().__post_init__()
for c in [
next_history,
previous_history,
restore_history,
first_history,
last_history,
yank_arg,
forward_history_isearch,
reverse_history_isearch,
isearch_end,
isearch_add_character,
isearch_cancel,
isearch_add_character,
isearch_backspace,
isearch_forwards,
isearch_backwards,
operate_and_get_next,
history_search_backward,
history_search_forward,
]:
self.commands[c.__name__] = c
self.commands[c.__name__.replace("_", "-")] = c
self.isearch_start = self.historyi, self.pos
self.isearch_trans = input.KeymapTranslator(
isearch_keymap, invalid_cls=isearch_end, character_cls=isearch_add_character
)
def collect_keymap(self) -> tuple[tuple[KeySpec, CommandName], ...]:
return super().collect_keymap() + (
(r"\C-n", "next-history"),
(r"\C-p", "previous-history"),
(r"\C-o", "operate-and-get-next"),
(r"\C-r", "reverse-history-isearch"),
(r"\C-s", "forward-history-isearch"),
(r"\M-r", "restore-history"),
(r"\M-.", "yank-arg"),
(r"\<page down>", "history-search-forward"),
(r"\x1b[6~", "history-search-forward"),
(r"\<page up>", "history-search-backward"),
(r"\x1b[5~", "history-search-backward"),
)
def select_item(self, i: int) -> None:
self.transient_history[self.historyi] = self.get_unicode()
buf = self.transient_history.get(i)
if buf is None:
buf = self.history[i].rstrip()
self.buffer = list(buf)
self.historyi = i
self.pos = len(self.buffer)
self.dirty = True
self.last_refresh_cache.invalidated = True
def get_item(self, i: int) -> str:
if i != len(self.history):
return self.transient_history.get(i, self.history[i])
else:
return self.transient_history.get(i, self.get_unicode())
@contextmanager
def suspend(self) -> SimpleContextManager:
with super().suspend(), self.suspend_history():
yield
@contextmanager
def suspend_history(self) -> SimpleContextManager:
try:
old_history = self.history[:]
del self.history[:]
yield
finally:
self.history[:] = old_history
def prepare(self) -> None:
super().prepare()
try:
self.transient_history = {}
if self.next_history is not None and self.next_history < len(self.history):
self.historyi = self.next_history
self.buffer[:] = list(self.history[self.next_history])
self.pos = len(self.buffer)
self.transient_history[len(self.history)] = ""
else:
self.historyi = len(self.history)
self.next_history = None
except:
self.restore()
raise
def get_prompt(self, lineno: int, cursor_on_line: bool) -> str:
if cursor_on_line and self.isearch_direction != ISEARCH_DIRECTION_NONE:
d = "rf"[self.isearch_direction == ISEARCH_DIRECTION_FORWARDS]
return "(%s-search `%s') " % (d, self.isearch_term)
else:
return super().get_prompt(lineno, cursor_on_line)
def search_next(self, *, forwards: bool) -> None:
"""Search history for the current line contents up to the cursor.
Selects the first item found. If nothing is under the cursor, any next
item in history is selected.
"""
pos = self.pos
s = self.get_unicode()
history_index = self.historyi
# In multiline contexts, we're only interested in the current line.
nl_index = s.rfind('\n', 0, pos)
prefix = s[nl_index + 1:pos]
pos = len(prefix)
match_prefix = len(prefix)
len_item = 0
if history_index < len(self.history):
len_item = len(self.get_item(history_index))
if len_item and pos == len_item:
match_prefix = False
elif not pos:
match_prefix = False
while 1:
if forwards:
out_of_bounds = history_index >= len(self.history) - 1
else:
out_of_bounds = history_index == 0
if out_of_bounds:
if forwards and not match_prefix:
self.pos = 0
self.buffer = []
self.dirty = True
else:
self.error("not found")
return
history_index += 1 if forwards else -1
s = self.get_item(history_index)
if not match_prefix:
self.select_item(history_index)
return
len_acc = 0
for i, line in enumerate(s.splitlines(keepends=True)):
if line.startswith(prefix):
self.select_item(history_index)
self.pos = pos + len_acc
return
len_acc += len(line)
def isearch_next(self) -> None:
st = self.isearch_term
p = self.pos
i = self.historyi
s = self.get_unicode()
forwards = self.isearch_direction == ISEARCH_DIRECTION_FORWARDS
while 1:
if forwards:
p = s.find(st, p + 1)
else:
p = s.rfind(st, 0, p + len(st) - 1)
if p != -1:
self.select_item(i)
self.pos = p
return
elif (forwards and i >= len(self.history) - 1) or (not forwards and i == 0):
self.error("not found")
return
else:
if forwards:
i += 1
s = self.get_item(i)
p = -1
else:
i -= 1
s = self.get_item(i)
p = len(s)
def finish(self) -> None:
super().finish()
ret = self.get_unicode()
for i, t in self.transient_history.items():
if i < len(self.history) and i != self.historyi:
self.history[i] = t
if ret and should_auto_add_history:
self.history.append(ret)
should_auto_add_history = True

114
Lib/_pyrepl/input.py vendored Normal file
View File

@@ -0,0 +1,114 @@
# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# (naming modules after builtin functions is not such a hot idea...)
# an KeyTrans instance translates Event objects into Command objects
# hmm, at what level do we want [C-i] and [tab] to be equivalent?
# [meta-a] and [esc a]? obviously, these are going to be equivalent
# for the UnixConsole, but should they be for PygameConsole?
# it would in any situation seem to be a bad idea to bind, say, [tab]
# and [C-i] to *different* things... but should binding one bind the
# other?
# executive, temporary decision: [tab] and [C-i] are distinct, but
# [meta-key] is identified with [esc key]. We demand that any console
# class does quite a lot towards emulating a unix terminal.
from __future__ import annotations
from abc import ABC, abstractmethod
import unicodedata
from collections import deque
# types
if False:
from .types import EventTuple
class InputTranslator(ABC):
@abstractmethod
def push(self, evt: EventTuple) -> None:
pass
@abstractmethod
def get(self) -> EventTuple | None:
return None
@abstractmethod
def empty(self) -> bool:
return True
class KeymapTranslator(InputTranslator):
def __init__(self, keymap, verbose=False, invalid_cls=None, character_cls=None):
self.verbose = verbose
from .keymap import compile_keymap, parse_keys
self.keymap = keymap
self.invalid_cls = invalid_cls
self.character_cls = character_cls
d = {}
for keyspec, command in keymap:
keyseq = tuple(parse_keys(keyspec))
d[keyseq] = command
if self.verbose:
print(d)
self.k = self.ck = compile_keymap(d, ())
self.results = deque()
self.stack = []
def push(self, evt):
if self.verbose:
print("pushed", evt.data, end="")
key = evt.data
d = self.k.get(key)
if isinstance(d, dict):
if self.verbose:
print("transition")
self.stack.append(key)
self.k = d
else:
if d is None:
if self.verbose:
print("invalid")
if self.stack or len(key) > 1 or unicodedata.category(key) == "C":
self.results.append((self.invalid_cls, self.stack + [key]))
else:
# small optimization:
self.k[key] = self.character_cls
self.results.append((self.character_cls, [key]))
else:
if self.verbose:
print("matched", d)
self.results.append((d, self.stack + [key]))
self.stack = []
self.k = self.ck
def get(self):
if self.results:
return self.results.popleft()
else:
return None
def empty(self) -> bool:
return not self.results

213
Lib/_pyrepl/keymap.py vendored Normal file
View File

@@ -0,0 +1,213 @@
# Copyright 2000-2008 Michael Hudson-Doyle <micahel@gmail.com>
# Armin Rigo
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""
Keymap contains functions for parsing keyspecs and turning keyspecs into
appropriate sequences.
A keyspec is a string representing a sequence of key presses that can
be bound to a command. All characters other than the backslash represent
themselves. In the traditional manner, a backslash introduces an escape
sequence.
pyrepl uses its own keyspec format that is meant to be a strict superset of
readline's KEYSEQ format. This means that if a spec is found that readline
accepts that this doesn't, it should be logged as a bug. Note that this means
we're using the `\\C-o' style of readline's keyspec, not the `Control-o' sort.
The extension to readline is that the sequence \\<KEY> denotes the
sequence of characters produced by hitting KEY.
Examples:
`a' - what you get when you hit the `a' key
`\\EOA' - Escape - O - A (up, on my terminal)
`\\<UP>' - the up arrow key
`\\<up>' - ditto (keynames are case-insensitive)
`\\C-o', `\\c-o' - control-o
`\\M-.' - meta-period
`\\E.' - ditto (that's how meta works for pyrepl)
`\\<tab>', `\\<TAB>', `\\t', `\\011', '\\x09', '\\X09', '\\C-i', '\\C-I'
- all of these are the tab character.
"""
_escapes = {
"\\": "\\",
"'": "'",
'"': '"',
"a": "\a",
"b": "\b",
"e": "\033",
"f": "\f",
"n": "\n",
"r": "\r",
"t": "\t",
"v": "\v",
}
_keynames = {
"backspace": "backspace",
"delete": "delete",
"down": "down",
"end": "end",
"enter": "\r",
"escape": "\033",
"f1": "f1",
"f2": "f2",
"f3": "f3",
"f4": "f4",
"f5": "f5",
"f6": "f6",
"f7": "f7",
"f8": "f8",
"f9": "f9",
"f10": "f10",
"f11": "f11",
"f12": "f12",
"f13": "f13",
"f14": "f14",
"f15": "f15",
"f16": "f16",
"f17": "f17",
"f18": "f18",
"f19": "f19",
"f20": "f20",
"home": "home",
"insert": "insert",
"left": "left",
"page down": "page down",
"page up": "page up",
"return": "\r",
"right": "right",
"space": " ",
"tab": "\t",
"up": "up",
}
class KeySpecError(Exception):
pass
def parse_keys(keys: str) -> list[str]:
"""Parse keys in keyspec format to a sequence of keys."""
s = 0
r: list[str] = []
while s < len(keys):
k, s = _parse_single_key_sequence(keys, s)
r.extend(k)
return r
def _parse_single_key_sequence(key: str, s: int) -> tuple[list[str], int]:
ctrl = 0
meta = 0
ret = ""
while not ret and s < len(key):
if key[s] == "\\":
c = key[s + 1].lower()
if c in _escapes:
ret = _escapes[c]
s += 2
elif c == "c":
if key[s + 2] != "-":
raise KeySpecError(
"\\C must be followed by `-' (char %d of %s)"
% (s + 2, repr(key))
)
if ctrl:
raise KeySpecError(
"doubled \\C- (char %d of %s)" % (s + 1, repr(key))
)
ctrl = 1
s += 3
elif c == "m":
if key[s + 2] != "-":
raise KeySpecError(
"\\M must be followed by `-' (char %d of %s)"
% (s + 2, repr(key))
)
if meta:
raise KeySpecError(
"doubled \\M- (char %d of %s)" % (s + 1, repr(key))
)
meta = 1
s += 3
elif c.isdigit():
n = key[s + 1 : s + 4]
ret = chr(int(n, 8))
s += 4
elif c == "x":
n = key[s + 2 : s + 4]
ret = chr(int(n, 16))
s += 4
elif c == "<":
t = key.find(">", s)
if t == -1:
raise KeySpecError(
"unterminated \\< starting at char %d of %s"
% (s + 1, repr(key))
)
ret = key[s + 2 : t].lower()
if ret not in _keynames:
raise KeySpecError(
"unrecognised keyname `%s' at char %d of %s"
% (ret, s + 2, repr(key))
)
ret = _keynames[ret]
s = t + 1
else:
raise KeySpecError(
"unknown backslash escape %s at char %d of %s"
% (repr(c), s + 2, repr(key))
)
else:
ret = key[s]
s += 1
if ctrl:
if len(ret) == 1:
ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl()
elif ret in {"left", "right"}:
ret = f"ctrl {ret}"
else:
raise KeySpecError("\\C- followed by invalid key")
result = [ret], s
if meta:
result[0].insert(0, "\033")
return result
def compile_keymap(keymap, empty=b""):
r = {}
for key, value in keymap.items():
if isinstance(key, bytes):
first = key[:1]
else:
first = key[0]
r.setdefault(first, {})[key[1:]] = value
for key, value in r.items():
if empty in value:
if len(value) != 1:
raise KeySpecError("key definitions for %s clash" % (value.values(),))
else:
r[key] = value[empty]
else:
r[key] = compile_keymap(value, empty)
return r

59
Lib/_pyrepl/main.py vendored Normal file
View File

@@ -0,0 +1,59 @@
import errno
import os
import sys
CAN_USE_PYREPL: bool
FAIL_REASON: str
try:
if sys.platform == "win32" and sys.getwindowsversion().build < 10586:
raise RuntimeError("Windows 10 TH2 or later required")
if not os.isatty(sys.stdin.fileno()):
raise OSError(errno.ENOTTY, "tty required", "stdin")
from .simple_interact import check
if err := check():
raise RuntimeError(err)
except Exception as e:
CAN_USE_PYREPL = False
FAIL_REASON = f"warning: can't use pyrepl: {e}"
else:
CAN_USE_PYREPL = True
FAIL_REASON = ""
def interactive_console(mainmodule=None, quiet=False, pythonstartup=False):
if not CAN_USE_PYREPL:
if not os.getenv('PYTHON_BASIC_REPL') and FAIL_REASON:
from .trace import trace
trace(FAIL_REASON)
print(FAIL_REASON, file=sys.stderr)
return sys._baserepl()
if mainmodule:
namespace = mainmodule.__dict__
else:
import __main__
namespace = __main__.__dict__
namespace.pop("__pyrepl_interactive_console", None)
# sys._baserepl() above does this internally, we do it here
startup_path = os.getenv("PYTHONSTARTUP")
if pythonstartup and startup_path:
sys.audit("cpython.run_startup", startup_path)
import tokenize
with tokenize.open(startup_path) as f:
startup_code = compile(f.read(), startup_path, "exec")
exec(startup_code, namespace)
# set sys.{ps1,ps2} just before invoking the interactive interpreter. This
# mimics what CPython does in pythonrun.c
if not hasattr(sys, "ps1"):
sys.ps1 = ">>> "
if not hasattr(sys, "ps2"):
sys.ps2 = "... "
from .console import InteractiveColoredConsole
from .simple_interact import run_multiline_interactive_console
console = InteractiveColoredConsole(namespace, filename="<stdin>")
run_multiline_interactive_console(console)

24
Lib/_pyrepl/mypy.ini vendored Normal file
View File

@@ -0,0 +1,24 @@
# Config file for running mypy on _pyrepl.
# Run mypy by invoking `mypy --config-file Lib/_pyrepl/mypy.ini`
# on the command-line from the repo root
[mypy]
files = Lib/_pyrepl
explicit_package_bases = True
python_version = 3.12
platform = linux
pretty = True
# Enable most stricter settings
enable_error_code = ignore-without-code,redundant-expr
strict = True
# Various stricter settings that we can't yet enable
# Try to enable these in the following order:
disallow_untyped_calls = False
disallow_untyped_defs = False
check_untyped_defs = False
# Various internal modules that typeshed deliberately doesn't have stubs for:
[mypy-_abc.*,_opcode.*,_overlapped.*,_testcapi.*,_testinternalcapi.*,test.*]
ignore_missing_imports = True

175
Lib/_pyrepl/pager.py vendored Normal file
View File

@@ -0,0 +1,175 @@
from __future__ import annotations
import io
import os
import re
import sys
# types
if False:
from typing import Protocol
class Pager(Protocol):
def __call__(self, text: str, title: str = "") -> None:
...
def get_pager() -> Pager:
"""Decide what method to use for paging through text."""
if not hasattr(sys.stdin, "isatty"):
return plain_pager
if not hasattr(sys.stdout, "isatty"):
return plain_pager
if not sys.stdin.isatty() or not sys.stdout.isatty():
return plain_pager
if sys.platform == "emscripten":
return plain_pager
use_pager = os.environ.get('MANPAGER') or os.environ.get('PAGER')
if use_pager:
if sys.platform == 'win32': # pipes completely broken in Windows
return lambda text, title='': tempfile_pager(plain(text), use_pager)
elif os.environ.get('TERM') in ('dumb', 'emacs'):
return lambda text, title='': pipe_pager(plain(text), use_pager, title)
else:
return lambda text, title='': pipe_pager(text, use_pager, title)
if os.environ.get('TERM') in ('dumb', 'emacs'):
return plain_pager
if sys.platform == 'win32':
return lambda text, title='': tempfile_pager(plain(text), 'more <')
if hasattr(os, 'system') and os.system('(pager) 2>/dev/null') == 0:
return lambda text, title='': pipe_pager(text, 'pager', title)
if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
return lambda text, title='': pipe_pager(text, 'less', title)
import tempfile
(fd, filename) = tempfile.mkstemp()
os.close(fd)
try:
if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:
return lambda text, title='': pipe_pager(text, 'more', title)
else:
return tty_pager
finally:
os.unlink(filename)
def escape_stdout(text: str) -> str:
# Escape non-encodable characters to avoid encoding errors later
encoding = getattr(sys.stdout, 'encoding', None) or 'utf-8'
return text.encode(encoding, 'backslashreplace').decode(encoding)
def escape_less(s: str) -> str:
return re.sub(r'([?:.%\\])', r'\\\1', s)
def plain(text: str) -> str:
"""Remove boldface formatting from text."""
return re.sub('.\b', '', text)
def tty_pager(text: str, title: str = '') -> None:
"""Page through text on a text terminal."""
lines = plain(escape_stdout(text)).split('\n')
has_tty = False
try:
import tty
import termios
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
tty.setcbreak(fd)
has_tty = True
def getchar() -> str:
return sys.stdin.read(1)
except (ImportError, AttributeError, io.UnsupportedOperation):
def getchar() -> str:
return sys.stdin.readline()[:-1][:1]
try:
try:
h = int(os.environ.get('LINES', 0))
except ValueError:
h = 0
if h <= 1:
h = 25
r = inc = h - 1
sys.stdout.write('\n'.join(lines[:inc]) + '\n')
while lines[r:]:
sys.stdout.write('-- more --')
sys.stdout.flush()
c = getchar()
if c in ('q', 'Q'):
sys.stdout.write('\r \r')
break
elif c in ('\r', '\n'):
sys.stdout.write('\r \r' + lines[r] + '\n')
r = r + 1
continue
if c in ('b', 'B', '\x1b'):
r = r - inc - inc
if r < 0: r = 0
sys.stdout.write('\n' + '\n'.join(lines[r:r+inc]) + '\n')
r = r + inc
finally:
if has_tty:
termios.tcsetattr(fd, termios.TCSAFLUSH, old)
def plain_pager(text: str, title: str = '') -> None:
"""Simply print unformatted text. This is the ultimate fallback."""
sys.stdout.write(plain(escape_stdout(text)))
def pipe_pager(text: str, cmd: str, title: str = '') -> None:
"""Page through text by feeding it to another program."""
import subprocess
env = os.environ.copy()
if title:
title += ' '
esc_title = escape_less(title)
prompt_string = (
f' {esc_title}' +
'?ltline %lt?L/%L.'
':byte %bB?s/%s.'
'.'
'?e (END):?pB %pB\\%..'
' (press h for help or q to quit)')
env['LESS'] = '-RmPm{0}$PM{0}$'.format(prompt_string)
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
errors='backslashreplace', env=env)
assert proc.stdin is not None
try:
with proc.stdin as pipe:
try:
pipe.write(text)
except KeyboardInterrupt:
# We've hereby abandoned whatever text hasn't been written,
# but the pager is still in control of the terminal.
pass
except OSError:
pass # Ignore broken pipes caused by quitting the pager program.
while True:
try:
proc.wait()
break
except KeyboardInterrupt:
# Ignore ctl-c like the pager itself does. Otherwise the pager is
# left running and the terminal is in raw mode and unusable.
pass
def tempfile_pager(text: str, cmd: str, title: str = '') -> None:
"""Page through text by invoking a program on a temporary file."""
import tempfile
with tempfile.TemporaryDirectory() as tempdir:
filename = os.path.join(tempdir, 'pydoc.out')
with open(filename, 'w', errors='backslashreplace',
encoding=os.device_encoding(0) if
sys.platform == 'win32' else None
) as file:
file.write(text)
os.system(cmd + ' "' + filename + '"')

816
Lib/_pyrepl/reader.py vendored Normal file
View File

@@ -0,0 +1,816 @@
# Copyright 2000-2010 Michael Hudson-Doyle <micahel@gmail.com>
# Antonio Cuni
# Armin Rigo
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import annotations
import sys
from contextlib import contextmanager
from dataclasses import dataclass, field, fields
import unicodedata
from _colorize import can_colorize, ANSIColors # type: ignore[import-not-found]
from . import commands, console, input
from .utils import ANSI_ESCAPE_SEQUENCE, wlen, str_width
from .trace import trace
# types
Command = commands.Command
from .types import Callback, SimpleContextManager, KeySpec, CommandName
def disp_str(buffer: str) -> tuple[str, list[int]]:
"""disp_str(buffer:string) -> (string, [int])
Return the string that should be the printed representation of
|buffer| and a list detailing where the characters of |buffer|
get used up. E.g.:
>>> disp_str(chr(3))
('^C', [1, 0])
"""
b: list[int] = []
s: list[str] = []
for c in buffer:
if c == '\x1a':
s.append(c)
b.append(2)
elif ord(c) < 128:
s.append(c)
b.append(1)
elif unicodedata.category(c).startswith("C"):
c = r"\u%04x" % ord(c)
s.append(c)
b.extend([0] * (len(c) - 1))
else:
s.append(c)
b.append(str_width(c))
return "".join(s), b
# syntax classes:
SYNTAX_WHITESPACE, SYNTAX_WORD, SYNTAX_SYMBOL = range(3)
def make_default_syntax_table() -> dict[str, int]:
# XXX perhaps should use some unicodedata here?
st: dict[str, int] = {}
for c in map(chr, range(256)):
st[c] = SYNTAX_SYMBOL
for c in [a for a in map(chr, range(256)) if a.isalnum()]:
st[c] = SYNTAX_WORD
st["\n"] = st[" "] = SYNTAX_WHITESPACE
return st
def make_default_commands() -> dict[CommandName, type[Command]]:
result: dict[CommandName, type[Command]] = {}
for v in vars(commands).values():
if isinstance(v, type) and issubclass(v, Command) and v.__name__[0].islower():
result[v.__name__] = v
result[v.__name__.replace("_", "-")] = v
return result
default_keymap: tuple[tuple[KeySpec, CommandName], ...] = tuple(
[
(r"\C-a", "beginning-of-line"),
(r"\C-b", "left"),
(r"\C-c", "interrupt"),
(r"\C-d", "delete"),
(r"\C-e", "end-of-line"),
(r"\C-f", "right"),
(r"\C-g", "cancel"),
(r"\C-h", "backspace"),
(r"\C-j", "accept"),
(r"\<return>", "accept"),
(r"\C-k", "kill-line"),
(r"\C-l", "clear-screen"),
(r"\C-m", "accept"),
(r"\C-t", "transpose-characters"),
(r"\C-u", "unix-line-discard"),
(r"\C-w", "unix-word-rubout"),
(r"\C-x\C-u", "upcase-region"),
(r"\C-y", "yank"),
*(() if sys.platform == "win32" else ((r"\C-z", "suspend"), )),
(r"\M-b", "backward-word"),
(r"\M-c", "capitalize-word"),
(r"\M-d", "kill-word"),
(r"\M-f", "forward-word"),
(r"\M-l", "downcase-word"),
(r"\M-t", "transpose-words"),
(r"\M-u", "upcase-word"),
(r"\M-y", "yank-pop"),
(r"\M--", "digit-arg"),
(r"\M-0", "digit-arg"),
(r"\M-1", "digit-arg"),
(r"\M-2", "digit-arg"),
(r"\M-3", "digit-arg"),
(r"\M-4", "digit-arg"),
(r"\M-5", "digit-arg"),
(r"\M-6", "digit-arg"),
(r"\M-7", "digit-arg"),
(r"\M-8", "digit-arg"),
(r"\M-9", "digit-arg"),
(r"\M-\n", "accept"),
("\\\\", "self-insert"),
(r"\x1b[200~", "enable_bracketed_paste"),
(r"\x1b[201~", "disable_bracketed_paste"),
(r"\x03", "ctrl-c"),
]
+ [(c, "self-insert") for c in map(chr, range(32, 127)) if c != "\\"]
+ [(c, "self-insert") for c in map(chr, range(128, 256)) if c.isalpha()]
+ [
(r"\<up>", "up"),
(r"\<down>", "down"),
(r"\<left>", "left"),
(r"\C-\<left>", "backward-word"),
(r"\<right>", "right"),
(r"\C-\<right>", "forward-word"),
(r"\<delete>", "delete"),
(r"\x1b[3~", "delete"),
(r"\<backspace>", "backspace"),
(r"\M-\<backspace>", "backward-kill-word"),
(r"\<end>", "end-of-line"), # was 'end'
(r"\<home>", "beginning-of-line"), # was 'home'
(r"\<f1>", "help"),
(r"\<f2>", "show-history"),
(r"\<f3>", "paste-mode"),
(r"\EOF", "end"), # the entries in the terminfo database for xterms
(r"\EOH", "home"), # seem to be wrong. this is a less than ideal
# workaround
]
)
@dataclass(slots=True)
class Reader:
"""The Reader class implements the bare bones of a command reader,
handling such details as editing and cursor motion. What it does
not support are such things as completion or history support -
these are implemented elsewhere.
Instance variables of note include:
* buffer:
A *list* (*not* a string at the moment :-) containing all the
characters that have been entered.
* console:
Hopefully encapsulates the OS dependent stuff.
* pos:
A 0-based index into `buffer' for where the insertion point
is.
* screeninfo:
Ahem. This list contains some info needed to move the
insertion point around reasonably efficiently.
* cxy, lxy:
the position of the insertion point in screen ...
* syntax_table:
Dictionary mapping characters to `syntax class'; read the
emacs docs to see what this means :-)
* commands:
Dictionary mapping command names to command classes.
* arg:
The emacs-style prefix argument. It will be None if no such
argument has been provided.
* dirty:
True if we need to refresh the display.
* kill_ring:
The emacs-style kill-ring; manipulated with yank & yank-pop
* ps1, ps2, ps3, ps4:
prompts. ps1 is the prompt for a one-line input; for a
multiline input it looks like:
ps2> first line of input goes here
ps3> second and further
ps3> lines get ps3
...
ps4> and the last one gets ps4
As with the usual top-level, you can set these to instances if
you like; str() will be called on them (once) at the beginning
of each command. Don't put really long or newline containing
strings here, please!
This is just the default policy; you can change it freely by
overriding get_prompt() (and indeed some standard subclasses
do).
* finished:
handle1 will set this to a true value if a command signals
that we're done.
"""
console: console.Console
## state
buffer: list[str] = field(default_factory=list)
pos: int = 0
ps1: str = "->> "
ps2: str = "/>> "
ps3: str = "|.. "
ps4: str = R"\__ "
kill_ring: list[list[str]] = field(default_factory=list)
msg: str = ""
arg: int | None = None
dirty: bool = False
finished: bool = False
paste_mode: bool = False
in_bracketed_paste: bool = False
commands: dict[str, type[Command]] = field(default_factory=make_default_commands)
last_command: type[Command] | None = None
syntax_table: dict[str, int] = field(default_factory=make_default_syntax_table)
keymap: tuple[tuple[str, str], ...] = ()
input_trans: input.KeymapTranslator = field(init=False)
input_trans_stack: list[input.KeymapTranslator] = field(default_factory=list)
screen: list[str] = field(default_factory=list)
screeninfo: list[tuple[int, list[int]]] = field(init=False)
cxy: tuple[int, int] = field(init=False)
lxy: tuple[int, int] = field(init=False)
scheduled_commands: list[str] = field(default_factory=list)
can_colorize: bool = False
threading_hook: Callback | None = None
## cached metadata to speed up screen refreshes
@dataclass
class RefreshCache:
in_bracketed_paste: bool = False
screen: list[str] = field(default_factory=list)
screeninfo: list[tuple[int, list[int]]] = field(init=False)
line_end_offsets: list[int] = field(default_factory=list)
pos: int = field(init=False)
cxy: tuple[int, int] = field(init=False)
dimensions: tuple[int, int] = field(init=False)
invalidated: bool = False
def update_cache(self,
reader: Reader,
screen: list[str],
screeninfo: list[tuple[int, list[int]]],
) -> None:
self.in_bracketed_paste = reader.in_bracketed_paste
self.screen = screen.copy()
self.screeninfo = screeninfo.copy()
self.pos = reader.pos
self.cxy = reader.cxy
self.dimensions = reader.console.width, reader.console.height
self.invalidated = False
def valid(self, reader: Reader) -> bool:
if self.invalidated:
return False
dimensions = reader.console.width, reader.console.height
dimensions_changed = dimensions != self.dimensions
paste_changed = reader.in_bracketed_paste != self.in_bracketed_paste
return not (dimensions_changed or paste_changed)
def get_cached_location(self, reader: Reader) -> tuple[int, int]:
if self.invalidated:
raise ValueError("Cache is invalidated")
offset = 0
earliest_common_pos = min(reader.pos, self.pos)
num_common_lines = len(self.line_end_offsets)
while num_common_lines > 0:
offset = self.line_end_offsets[num_common_lines - 1]
if earliest_common_pos > offset:
break
num_common_lines -= 1
else:
offset = 0
return offset, num_common_lines
last_refresh_cache: RefreshCache = field(default_factory=RefreshCache)
def __post_init__(self) -> None:
# Enable the use of `insert` without a `prepare` call - necessary to
# facilitate the tab completion hack implemented for
# <https://bugs.python.org/issue25660>.
self.keymap = self.collect_keymap()
self.input_trans = input.KeymapTranslator(
self.keymap, invalid_cls="invalid-key", character_cls="self-insert"
)
self.screeninfo = [(0, [])]
self.cxy = self.pos2xy()
self.lxy = (self.pos, 0)
self.can_colorize = can_colorize()
self.last_refresh_cache.screeninfo = self.screeninfo
self.last_refresh_cache.pos = self.pos
self.last_refresh_cache.cxy = self.cxy
self.last_refresh_cache.dimensions = (0, 0)
def collect_keymap(self) -> tuple[tuple[KeySpec, CommandName], ...]:
return default_keymap
def calc_screen(self) -> list[str]:
"""Translate changes in self.buffer into changes in self.console.screen."""
# Since the last call to calc_screen:
# screen and screeninfo may differ due to a completion menu being shown
# pos and cxy may differ due to edits, cursor movements, or completion menus
# Lines that are above both the old and new cursor position can't have changed,
# unless the terminal has been resized (which might cause reflowing) or we've
# entered or left paste mode (which changes prompts, causing reflowing).
num_common_lines = 0
offset = 0
if self.last_refresh_cache.valid(self):
offset, num_common_lines = self.last_refresh_cache.get_cached_location(self)
screen = self.last_refresh_cache.screen
del screen[num_common_lines:]
screeninfo = self.last_refresh_cache.screeninfo
del screeninfo[num_common_lines:]
last_refresh_line_end_offsets = self.last_refresh_cache.line_end_offsets
del last_refresh_line_end_offsets[num_common_lines:]
pos = self.pos
pos -= offset
prompt_from_cache = (offset and self.buffer[offset - 1] != "\n")
lines = "".join(self.buffer[offset:]).split("\n")
cursor_found = False
lines_beyond_cursor = 0
for ln, line in enumerate(lines, num_common_lines):
ll = len(line)
if 0 <= pos <= ll:
self.lxy = pos, ln
cursor_found = True
elif cursor_found:
lines_beyond_cursor += 1
if lines_beyond_cursor > self.console.height:
# No need to keep formatting lines.
# The console can't show them.
break
if prompt_from_cache:
# Only the first line's prompt can come from the cache
prompt_from_cache = False
prompt = ""
else:
prompt = self.get_prompt(ln, ll >= pos >= 0)
while "\n" in prompt:
pre_prompt, _, prompt = prompt.partition("\n")
last_refresh_line_end_offsets.append(offset)
screen.append(pre_prompt)
screeninfo.append((0, []))
pos -= ll + 1
prompt, lp = self.process_prompt(prompt)
l, l2 = disp_str(line)
wrapcount = (wlen(l) + lp) // self.console.width
if wrapcount == 0:
offset += ll + 1 # Takes all of the line plus the newline
last_refresh_line_end_offsets.append(offset)
screen.append(prompt + l)
screeninfo.append((lp, l2))
else:
i = 0
while l:
prelen = lp if i == 0 else 0
index_to_wrap_before = 0
column = 0
for character_width in l2:
if column + character_width >= self.console.width - prelen:
break
index_to_wrap_before += 1
column += character_width
pre = prompt if i == 0 else ""
if len(l) > index_to_wrap_before:
offset += index_to_wrap_before
post = "\\"
after = [1]
else:
offset += index_to_wrap_before + 1 # Takes the newline
post = ""
after = []
last_refresh_line_end_offsets.append(offset)
screen.append(pre + l[:index_to_wrap_before] + post)
screeninfo.append((prelen, l2[:index_to_wrap_before] + after))
l = l[index_to_wrap_before:]
l2 = l2[index_to_wrap_before:]
i += 1
self.screeninfo = screeninfo
self.cxy = self.pos2xy()
if self.msg:
for mline in self.msg.split("\n"):
screen.append(mline)
screeninfo.append((0, []))
self.last_refresh_cache.update_cache(self, screen, screeninfo)
return screen
@staticmethod
def process_prompt(prompt: str) -> tuple[str, int]:
"""Process the prompt.
This means calculate the length of the prompt. The character \x01
and \x02 are used to bracket ANSI control sequences and need to be
excluded from the length calculation. So also a copy of the prompt
is returned with these control characters removed."""
# The logic below also ignores the length of common escape
# sequences if they were not explicitly within \x01...\x02.
# They are CSI (or ANSI) sequences ( ESC [ ... LETTER )
# wlen from utils already excludes ANSI_ESCAPE_SEQUENCE chars,
# which breaks the logic below so we redefine it here.
def wlen(s: str) -> int:
return sum(str_width(i) for i in s)
out_prompt = ""
l = wlen(prompt)
pos = 0
while True:
s = prompt.find("\x01", pos)
if s == -1:
break
e = prompt.find("\x02", s)
if e == -1:
break
# Found start and end brackets, subtract from string length
l = l - (e - s + 1)
keep = prompt[pos:s]
l -= sum(map(wlen, ANSI_ESCAPE_SEQUENCE.findall(keep)))
out_prompt += keep + prompt[s + 1 : e]
pos = e + 1
keep = prompt[pos:]
l -= sum(map(wlen, ANSI_ESCAPE_SEQUENCE.findall(keep)))
out_prompt += keep
return out_prompt, l
def bow(self, p: int | None = None) -> int:
"""Return the 0-based index of the word break preceding p most
immediately.
p defaults to self.pos; word boundaries are determined using
self.syntax_table."""
if p is None:
p = self.pos
st = self.syntax_table
b = self.buffer
p -= 1
while p >= 0 and st.get(b[p], SYNTAX_WORD) != SYNTAX_WORD:
p -= 1
while p >= 0 and st.get(b[p], SYNTAX_WORD) == SYNTAX_WORD:
p -= 1
return p + 1
def eow(self, p: int | None = None) -> int:
"""Return the 0-based index of the word break following p most
immediately.
p defaults to self.pos; word boundaries are determined using
self.syntax_table."""
if p is None:
p = self.pos
st = self.syntax_table
b = self.buffer
while p < len(b) and st.get(b[p], SYNTAX_WORD) != SYNTAX_WORD:
p += 1
while p < len(b) and st.get(b[p], SYNTAX_WORD) == SYNTAX_WORD:
p += 1
return p
def bol(self, p: int | None = None) -> int:
"""Return the 0-based index of the line break preceding p most
immediately.
p defaults to self.pos."""
if p is None:
p = self.pos
b = self.buffer
p -= 1
while p >= 0 and b[p] != "\n":
p -= 1
return p + 1
def eol(self, p: int | None = None) -> int:
"""Return the 0-based index of the line break following p most
immediately.
p defaults to self.pos."""
if p is None:
p = self.pos
b = self.buffer
while p < len(b) and b[p] != "\n":
p += 1
return p
def max_column(self, y: int) -> int:
"""Return the last x-offset for line y"""
return self.screeninfo[y][0] + sum(self.screeninfo[y][1])
def max_row(self) -> int:
return len(self.screeninfo) - 1
def get_arg(self, default: int = 1) -> int:
"""Return any prefix argument that the user has supplied,
returning `default' if there is None. Defaults to 1.
"""
if self.arg is None:
return default
return self.arg
def get_prompt(self, lineno: int, cursor_on_line: bool) -> str:
"""Return what should be in the left-hand margin for line
`lineno'."""
if self.arg is not None and cursor_on_line:
prompt = f"(arg: {self.arg}) "
elif self.paste_mode and not self.in_bracketed_paste:
prompt = "(paste) "
elif "\n" in self.buffer:
if lineno == 0:
prompt = self.ps2
elif self.ps4 and lineno == self.buffer.count("\n"):
prompt = self.ps4
else:
prompt = self.ps3
else:
prompt = self.ps1
if self.can_colorize:
prompt = f"{ANSIColors.BOLD_MAGENTA}{prompt}{ANSIColors.RESET}"
return prompt
def push_input_trans(self, itrans: input.KeymapTranslator) -> None:
self.input_trans_stack.append(self.input_trans)
self.input_trans = itrans
def pop_input_trans(self) -> None:
self.input_trans = self.input_trans_stack.pop()
def setpos_from_xy(self, x: int, y: int) -> None:
"""Set pos according to coordinates x, y"""
pos = 0
i = 0
while i < y:
prompt_len, character_widths = self.screeninfo[i]
offset = len(character_widths) - character_widths.count(0)
in_wrapped_line = prompt_len + sum(character_widths) >= self.console.width
if in_wrapped_line:
pos += offset - 1 # -1 cause backslash is not in buffer
else:
pos += offset + 1 # +1 cause newline is in buffer
i += 1
j = 0
cur_x = self.screeninfo[i][0]
while cur_x < x:
if self.screeninfo[i][1][j] == 0:
continue
cur_x += self.screeninfo[i][1][j]
j += 1
pos += 1
self.pos = pos
def pos2xy(self) -> tuple[int, int]:
"""Return the x, y coordinates of position 'pos'."""
# this *is* incomprehensible, yes.
p, y = 0, 0
l2: list[int] = []
pos = self.pos
assert 0 <= pos <= len(self.buffer)
if pos == len(self.buffer) and len(self.screeninfo) > 0:
y = len(self.screeninfo) - 1
p, l2 = self.screeninfo[y]
return p + sum(l2) + l2.count(0), y
for p, l2 in self.screeninfo:
l = len(l2) - l2.count(0)
in_wrapped_line = p + sum(l2) >= self.console.width
offset = l - 1 if in_wrapped_line else l # need to remove backslash
if offset >= pos:
break
if p + sum(l2) >= self.console.width:
pos -= l - 1 # -1 cause backslash is not in buffer
else:
pos -= l + 1 # +1 cause newline is in buffer
y += 1
return p + sum(l2[:pos]), y
def insert(self, text: str | list[str]) -> None:
"""Insert 'text' at the insertion point."""
self.buffer[self.pos : self.pos] = list(text)
self.pos += len(text)
self.dirty = True
def update_cursor(self) -> None:
"""Move the cursor to reflect changes in self.pos"""
self.cxy = self.pos2xy()
self.console.move_cursor(*self.cxy)
def after_command(self, cmd: Command) -> None:
"""This function is called to allow post command cleanup."""
if getattr(cmd, "kills_digit_arg", True):
if self.arg is not None:
self.dirty = True
self.arg = None
def prepare(self) -> None:
"""Get ready to run. Call restore when finished. You must not
write to the console in between the calls to prepare and
restore."""
try:
self.console.prepare()
self.arg = None
self.finished = False
del self.buffer[:]
self.pos = 0
self.dirty = True
self.last_command = None
self.calc_screen()
except BaseException:
self.restore()
raise
while self.scheduled_commands:
cmd = self.scheduled_commands.pop()
self.do_cmd((cmd, []))
def last_command_is(self, cls: type) -> bool:
if not self.last_command:
return False
return issubclass(cls, self.last_command)
def restore(self) -> None:
"""Clean up after a run."""
self.console.restore()
@contextmanager
def suspend(self) -> SimpleContextManager:
"""A context manager to delegate to another reader."""
prev_state = {f.name: getattr(self, f.name) for f in fields(self)}
try:
self.restore()
yield
finally:
for arg in ("msg", "ps1", "ps2", "ps3", "ps4", "paste_mode"):
setattr(self, arg, prev_state[arg])
self.prepare()
def finish(self) -> None:
"""Called when a command signals that we're finished."""
pass
def error(self, msg: str = "none") -> None:
self.msg = "! " + msg + " "
self.dirty = True
self.console.beep()
def update_screen(self) -> None:
if self.dirty:
self.refresh()
def refresh(self) -> None:
"""Recalculate and refresh the screen."""
if self.in_bracketed_paste and self.buffer and not self.buffer[-1] == "\n":
return
# this call sets up self.cxy, so call it first.
self.screen = self.calc_screen()
self.console.refresh(self.screen, self.cxy)
self.dirty = False
def do_cmd(self, cmd: tuple[str, list[str]]) -> None:
"""`cmd` is a tuple of "event_name" and "event", which in the current
implementation is always just the "buffer" which happens to be a list
of single-character strings."""
trace("received command {cmd}", cmd=cmd)
if isinstance(cmd[0], str):
command_type = self.commands.get(cmd[0], commands.invalid_command)
elif isinstance(cmd[0], type):
command_type = cmd[0]
else:
return # nothing to do
command = command_type(self, *cmd) # type: ignore[arg-type]
command.do()
self.after_command(command)
if self.dirty:
self.refresh()
else:
self.update_cursor()
if not isinstance(cmd, commands.digit_arg):
self.last_command = command_type
self.finished = bool(command.finish)
if self.finished:
self.console.finish()
self.finish()
def run_hooks(self) -> None:
threading_hook = self.threading_hook
if threading_hook is None and 'threading' in sys.modules:
from ._threading_handler import install_threading_hook
install_threading_hook(self)
if threading_hook is not None:
try:
threading_hook()
except Exception:
pass
input_hook = self.console.input_hook
if input_hook:
try:
input_hook()
except Exception:
pass
def handle1(self, block: bool = True) -> bool:
"""Handle a single event. Wait as long as it takes if block
is true (the default), otherwise return False if no event is
pending."""
if self.msg:
self.msg = ""
self.dirty = True
while True:
# We use the same timeout as in readline.c: 100ms
self.run_hooks()
self.console.wait(100)
event = self.console.get_event(block=False)
if not event:
if block:
continue
return False
translate = True
if event.evt == "key":
self.input_trans.push(event)
elif event.evt == "scroll":
self.refresh()
elif event.evt == "resize":
self.refresh()
else:
translate = False
if translate:
cmd = self.input_trans.get()
else:
cmd = [event.evt, event.data]
if cmd is None:
if block:
continue
return False
self.do_cmd(cmd)
return True
def push_char(self, char: int | bytes) -> None:
self.console.push_char(char)
self.handle1(block=False)
def readline(self, startup_hook: Callback | None = None) -> str:
"""Read a line. The implementation of this method also shows
how to drive Reader if you want more control over the event
loop."""
self.prepare()
try:
if startup_hook is not None:
startup_hook()
self.refresh()
while not self.finished:
self.handle1()
return self.get_unicode()
finally:
self.restore()
def bind(self, spec: KeySpec, command: CommandName) -> None:
self.keymap = self.keymap + ((spec, command),)
self.input_trans = input.KeymapTranslator(
self.keymap, invalid_cls="invalid-key", character_cls="self-insert"
)
def get_unicode(self) -> str:
"""Return the current buffer as a unicode string."""
return "".join(self.buffer)

598
Lib/_pyrepl/readline.py vendored Normal file
View File

@@ -0,0 +1,598 @@
# Copyright 2000-2010 Michael Hudson-Doyle <micahel@gmail.com>
# Alex Gaynor
# Antonio Cuni
# Armin Rigo
# Holger Krekel
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""A compatibility wrapper reimplementing the 'readline' standard module
on top of pyrepl. Not all functionalities are supported. Contains
extensions for multiline input.
"""
from __future__ import annotations
import warnings
from dataclasses import dataclass, field
import os
from site import gethistoryfile # type: ignore[attr-defined]
import sys
from rlcompleter import Completer as RLCompleter
from . import commands, historical_reader
from .completing_reader import CompletingReader
from .console import Console as ConsoleType
Console: type[ConsoleType]
_error: tuple[type[Exception], ...] | type[Exception]
try:
from .unix_console import UnixConsole as Console, _error
except ImportError:
from .windows_console import WindowsConsole as Console, _error
ENCODING = sys.getdefaultencoding() or "latin1"
# types
Command = commands.Command
from collections.abc import Callable, Collection
from .types import Callback, Completer, KeySpec, CommandName
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any, Mapping
MoreLinesCallable = Callable[[str], bool]
__all__ = [
"add_history",
"clear_history",
"get_begidx",
"get_completer",
"get_completer_delims",
"get_current_history_length",
"get_endidx",
"get_history_item",
"get_history_length",
"get_line_buffer",
"insert_text",
"parse_and_bind",
"read_history_file",
# "read_init_file",
# "redisplay",
"remove_history_item",
"replace_history_item",
"set_auto_history",
"set_completer",
"set_completer_delims",
"set_history_length",
# "set_pre_input_hook",
"set_startup_hook",
"write_history_file",
# ---- multiline extensions ----
"multiline_input",
]
# ____________________________________________________________
@dataclass
class ReadlineConfig:
readline_completer: Completer | None = None
completer_delims: frozenset[str] = frozenset(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?")
@dataclass(kw_only=True)
class ReadlineAlikeReader(historical_reader.HistoricalReader, CompletingReader):
# Class fields
assume_immutable_completions = False
use_brackets = False
sort_in_column = True
# Instance fields
config: ReadlineConfig
more_lines: MoreLinesCallable | None = None
last_used_indentation: str | None = None
def __post_init__(self) -> None:
super().__post_init__()
self.commands["maybe_accept"] = maybe_accept
self.commands["maybe-accept"] = maybe_accept
self.commands["backspace_dedent"] = backspace_dedent
self.commands["backspace-dedent"] = backspace_dedent
def error(self, msg: str = "none") -> None:
pass # don't show error messages by default
def get_stem(self) -> str:
b = self.buffer
p = self.pos - 1
completer_delims = self.config.completer_delims
while p >= 0 and b[p] not in completer_delims:
p -= 1
return "".join(b[p + 1 : self.pos])
def get_completions(self, stem: str) -> list[str]:
if len(stem) == 0 and self.more_lines is not None:
b = self.buffer
p = self.pos
while p > 0 and b[p - 1] != "\n":
p -= 1
num_spaces = 4 - ((self.pos - p) % 4)
return [" " * num_spaces]
result = []
function = self.config.readline_completer
if function is not None:
try:
stem = str(stem) # rlcompleter.py seems to not like unicode
except UnicodeEncodeError:
pass # but feed unicode anyway if we have no choice
state = 0
while True:
try:
next = function(stem, state)
except Exception:
break
if not isinstance(next, str):
break
result.append(next)
state += 1
# emulate the behavior of the standard readline that sorts
# the completions before displaying them.
result.sort()
return result
def get_trimmed_history(self, maxlength: int) -> list[str]:
if maxlength >= 0:
cut = len(self.history) - maxlength
if cut < 0:
cut = 0
else:
cut = 0
return self.history[cut:]
def update_last_used_indentation(self) -> None:
indentation = _get_first_indentation(self.buffer)
if indentation is not None:
self.last_used_indentation = indentation
# --- simplified support for reading multiline Python statements ---
def collect_keymap(self) -> tuple[tuple[KeySpec, CommandName], ...]:
return super().collect_keymap() + (
(r"\n", "maybe-accept"),
(r"\<backspace>", "backspace-dedent"),
)
def after_command(self, cmd: Command) -> None:
super().after_command(cmd)
if self.more_lines is None:
# Force single-line input if we are in raw_input() mode.
# Although there is no direct way to add a \n in this mode,
# multiline buffers can still show up using various
# commands, e.g. navigating the history.
try:
index = self.buffer.index("\n")
except ValueError:
pass
else:
self.buffer = self.buffer[:index]
if self.pos > len(self.buffer):
self.pos = len(self.buffer)
def set_auto_history(_should_auto_add_history: bool) -> None:
"""Enable or disable automatic history"""
historical_reader.should_auto_add_history = bool(_should_auto_add_history)
def _get_this_line_indent(buffer: list[str], pos: int) -> int:
indent = 0
while pos > 0 and buffer[pos - 1] in " \t":
indent += 1
pos -= 1
if pos > 0 and buffer[pos - 1] == "\n":
return indent
return 0
def _get_previous_line_indent(buffer: list[str], pos: int) -> tuple[int, int | None]:
prevlinestart = pos
while prevlinestart > 0 and buffer[prevlinestart - 1] != "\n":
prevlinestart -= 1
prevlinetext = prevlinestart
while prevlinetext < pos and buffer[prevlinetext] in " \t":
prevlinetext += 1
if prevlinetext == pos:
indent = None
else:
indent = prevlinetext - prevlinestart
return prevlinestart, indent
def _get_first_indentation(buffer: list[str]) -> str | None:
indented_line_start = None
for i in range(len(buffer)):
if (i < len(buffer) - 1
and buffer[i] == "\n"
and buffer[i + 1] in " \t"
):
indented_line_start = i + 1
elif indented_line_start is not None and buffer[i] not in " \t\n":
return ''.join(buffer[indented_line_start : i])
return None
def _should_auto_indent(buffer: list[str], pos: int) -> bool:
# check if last character before "pos" is a colon, ignoring
# whitespaces and comments.
last_char = None
while pos > 0:
pos -= 1
if last_char is None:
if buffer[pos] not in " \t\n#": # ignore whitespaces and comments
last_char = buffer[pos]
else:
# even if we found a non-whitespace character before
# original pos, we keep going back until newline is reached
# to make sure we ignore comments
if buffer[pos] == "\n":
break
if buffer[pos] == "#":
last_char = None
return last_char == ":"
class maybe_accept(commands.Command):
def do(self) -> None:
r: ReadlineAlikeReader
r = self.reader # type: ignore[assignment]
r.dirty = True # this is needed to hide the completion menu, if visible
if self.reader.in_bracketed_paste:
r.insert("\n")
return
# if there are already several lines and the cursor
# is not on the last one, always insert a new \n.
text = r.get_unicode()
if "\n" in r.buffer[r.pos :] or (
r.more_lines is not None and r.more_lines(text)
):
def _newline_before_pos():
before_idx = r.pos - 1
while before_idx > 0 and text[before_idx].isspace():
before_idx -= 1
return text[before_idx : r.pos].count("\n") > 0
# if there's already a new line before the cursor then
# even if the cursor is followed by whitespace, we assume
# the user is trying to terminate the block
if _newline_before_pos() and text[r.pos:].isspace():
self.finish = True
return
# auto-indent the next line like the previous line
prevlinestart, indent = _get_previous_line_indent(r.buffer, r.pos)
r.insert("\n")
if not self.reader.paste_mode:
if indent:
for i in range(prevlinestart, prevlinestart + indent):
r.insert(r.buffer[i])
r.update_last_used_indentation()
if _should_auto_indent(r.buffer, r.pos):
if r.last_used_indentation is not None:
indentation = r.last_used_indentation
else:
# default
indentation = " " * 4
r.insert(indentation)
elif not self.reader.paste_mode:
self.finish = True
else:
r.insert("\n")
class backspace_dedent(commands.Command):
def do(self) -> None:
r = self.reader
b = r.buffer
if r.pos > 0:
repeat = 1
if b[r.pos - 1] != "\n":
indent = _get_this_line_indent(b, r.pos)
if indent > 0:
ls = r.pos - indent
while ls > 0:
ls, pi = _get_previous_line_indent(b, ls - 1)
if pi is not None and pi < indent:
repeat = indent - pi
break
r.pos -= repeat
del b[r.pos : r.pos + repeat]
r.dirty = True
else:
self.reader.error("can't backspace at start")
# ____________________________________________________________
@dataclass(slots=True)
class _ReadlineWrapper:
f_in: int = -1
f_out: int = -1
reader: ReadlineAlikeReader | None = field(default=None, repr=False)
saved_history_length: int = -1
startup_hook: Callback | None = None
config: ReadlineConfig = field(default_factory=ReadlineConfig, repr=False)
def __post_init__(self) -> None:
if self.f_in == -1:
self.f_in = os.dup(0)
if self.f_out == -1:
self.f_out = os.dup(1)
def get_reader(self) -> ReadlineAlikeReader:
if self.reader is None:
console = Console(self.f_in, self.f_out, encoding=ENCODING)
self.reader = ReadlineAlikeReader(console=console, config=self.config)
return self.reader
def input(self, prompt: object = "") -> str:
try:
reader = self.get_reader()
except _error:
assert raw_input is not None
return raw_input(prompt)
prompt_str = str(prompt)
reader.ps1 = prompt_str
sys.audit("builtins.input", prompt_str)
result = reader.readline(startup_hook=self.startup_hook)
sys.audit("builtins.input/result", result)
return result
def multiline_input(self, more_lines: MoreLinesCallable, ps1: str, ps2: str) -> str:
"""Read an input on possibly multiple lines, asking for more
lines as long as 'more_lines(unicodetext)' returns an object whose
boolean value is true.
"""
reader = self.get_reader()
saved = reader.more_lines
try:
reader.more_lines = more_lines
reader.ps1 = ps1
reader.ps2 = ps1
reader.ps3 = ps2
reader.ps4 = ""
with warnings.catch_warnings(action="ignore"):
return reader.readline()
finally:
reader.more_lines = saved
reader.paste_mode = False
def parse_and_bind(self, string: str) -> None:
pass # XXX we don't support parsing GNU-readline-style init files
def set_completer(self, function: Completer | None = None) -> None:
self.config.readline_completer = function
def get_completer(self) -> Completer | None:
return self.config.readline_completer
def set_completer_delims(self, delimiters: Collection[str]) -> None:
self.config.completer_delims = frozenset(delimiters)
def get_completer_delims(self) -> str:
return "".join(sorted(self.config.completer_delims))
def _histline(self, line: str) -> str:
line = line.rstrip("\n")
return line
def get_history_length(self) -> int:
return self.saved_history_length
def set_history_length(self, length: int) -> None:
self.saved_history_length = length
def get_current_history_length(self) -> int:
return len(self.get_reader().history)
def read_history_file(self, filename: str = gethistoryfile()) -> None:
# multiline extension (really a hack) for the end of lines that
# are actually continuations inside a single multiline_input()
# history item: we use \r\n instead of just \n. If the history
# file is passed to GNU readline, the extra \r are just ignored.
history = self.get_reader().history
with open(os.path.expanduser(filename), 'rb') as f:
is_editline = f.readline().startswith(b"_HiStOrY_V2_")
if is_editline:
encoding = "unicode-escape"
else:
f.seek(0)
encoding = "utf-8"
lines = [line.decode(encoding, errors='replace') for line in f.read().split(b'\n')]
buffer = []
for line in lines:
if line.endswith("\r"):
buffer.append(line+'\n')
else:
line = self._histline(line)
if buffer:
line = self._histline("".join(buffer).replace("\r", "") + line)
del buffer[:]
if line:
history.append(line)
def write_history_file(self, filename: str = gethistoryfile()) -> None:
maxlength = self.saved_history_length
history = self.get_reader().get_trimmed_history(maxlength)
f = open(os.path.expanduser(filename), "w",
encoding="utf-8", newline="\n")
with f:
for entry in history:
entry = entry.replace("\n", "\r\n") # multiline history support
f.write(entry + "\n")
def clear_history(self) -> None:
del self.get_reader().history[:]
def get_history_item(self, index: int) -> str | None:
history = self.get_reader().history
if 1 <= index <= len(history):
return history[index - 1]
else:
return None # like readline.c
def remove_history_item(self, index: int) -> None:
history = self.get_reader().history
if 0 <= index < len(history):
del history[index]
else:
raise ValueError("No history item at position %d" % index)
# like readline.c
def replace_history_item(self, index: int, line: str) -> None:
history = self.get_reader().history
if 0 <= index < len(history):
history[index] = self._histline(line)
else:
raise ValueError("No history item at position %d" % index)
# like readline.c
def add_history(self, line: str) -> None:
self.get_reader().history.append(self._histline(line))
def set_startup_hook(self, function: Callback | None = None) -> None:
self.startup_hook = function
def get_line_buffer(self) -> str:
return self.get_reader().get_unicode()
def _get_idxs(self) -> tuple[int, int]:
start = cursor = self.get_reader().pos
buf = self.get_line_buffer()
for i in range(cursor - 1, -1, -1):
if buf[i] in self.get_completer_delims():
break
start = i
return start, cursor
def get_begidx(self) -> int:
return self._get_idxs()[0]
def get_endidx(self) -> int:
return self._get_idxs()[1]
def insert_text(self, text: str) -> None:
self.get_reader().insert(text)
_wrapper = _ReadlineWrapper()
# ____________________________________________________________
# Public API
parse_and_bind = _wrapper.parse_and_bind
set_completer = _wrapper.set_completer
get_completer = _wrapper.get_completer
set_completer_delims = _wrapper.set_completer_delims
get_completer_delims = _wrapper.get_completer_delims
get_history_length = _wrapper.get_history_length
set_history_length = _wrapper.set_history_length
get_current_history_length = _wrapper.get_current_history_length
read_history_file = _wrapper.read_history_file
write_history_file = _wrapper.write_history_file
clear_history = _wrapper.clear_history
get_history_item = _wrapper.get_history_item
remove_history_item = _wrapper.remove_history_item
replace_history_item = _wrapper.replace_history_item
add_history = _wrapper.add_history
set_startup_hook = _wrapper.set_startup_hook
get_line_buffer = _wrapper.get_line_buffer
get_begidx = _wrapper.get_begidx
get_endidx = _wrapper.get_endidx
insert_text = _wrapper.insert_text
# Extension
multiline_input = _wrapper.multiline_input
# Internal hook
_get_reader = _wrapper.get_reader
# ____________________________________________________________
# Stubs
def _make_stub(_name: str, _ret: object) -> None:
def stub(*args: object, **kwds: object) -> None:
import warnings
warnings.warn("readline.%s() not implemented" % _name, stacklevel=2)
stub.__name__ = _name
globals()[_name] = stub
for _name, _ret in [
("read_init_file", None),
("redisplay", None),
("set_pre_input_hook", None),
]:
assert _name not in globals(), _name
_make_stub(_name, _ret)
# ____________________________________________________________
def _setup(namespace: Mapping[str, Any]) -> None:
global raw_input
if raw_input is not None:
return # don't run _setup twice
try:
f_in = sys.stdin.fileno()
f_out = sys.stdout.fileno()
except (AttributeError, ValueError):
return
if not os.isatty(f_in) or not os.isatty(f_out):
return
_wrapper.f_in = f_in
_wrapper.f_out = f_out
# set up namespace in rlcompleter, which requires it to be a bona fide dict
if not isinstance(namespace, dict):
namespace = dict(namespace)
_wrapper.config.readline_completer = RLCompleter(namespace).complete
# this is not really what readline.c does. Better than nothing I guess
import builtins
raw_input = builtins.input
builtins.input = _wrapper.input
raw_input: Callable[[object], str] | None = None

167
Lib/_pyrepl/simple_interact.py vendored Normal file
View File

@@ -0,0 +1,167 @@
# Copyright 2000-2010 Michael Hudson-Doyle <micahel@gmail.com>
# Armin Rigo
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""This is an alternative to python_reader which tries to emulate
the CPython prompt as closely as possible, with the exception of
allowing multiline input and multiline history entries.
"""
from __future__ import annotations
import _sitebuiltins
import linecache
import functools
import os
import sys
import code
from .readline import _get_reader, multiline_input
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any
_error: tuple[type[Exception], ...] | type[Exception]
try:
from .unix_console import _error
except ModuleNotFoundError:
from .windows_console import _error
def check() -> str:
"""Returns the error message if there is a problem initializing the state."""
try:
_get_reader()
except _error as e:
if term := os.environ.get("TERM", ""):
term = f"; TERM={term}"
return str(str(e) or repr(e) or "unknown error") + term
return ""
def _strip_final_indent(text: str) -> str:
# kill spaces and tabs at the end, but only if they follow '\n'.
# meant to remove the auto-indentation only (although it would of
# course also remove explicitly-added indentation).
short = text.rstrip(" \t")
n = len(short)
if n > 0 and text[n - 1] == "\n":
return short
return text
def _clear_screen():
reader = _get_reader()
reader.scheduled_commands.append("clear_screen")
REPL_COMMANDS = {
"exit": _sitebuiltins.Quitter('exit', ''),
"quit": _sitebuiltins.Quitter('quit' ,''),
"copyright": _sitebuiltins._Printer('copyright', sys.copyright),
"help": _sitebuiltins._Helper(),
"clear": _clear_screen,
"\x1a": _sitebuiltins.Quitter('\x1a', ''),
}
def _more_lines(console: code.InteractiveConsole, unicodetext: str) -> bool:
# ooh, look at the hack:
src = _strip_final_indent(unicodetext)
try:
code = console.compile(src, "<stdin>", "single")
except (OverflowError, SyntaxError, ValueError):
lines = src.splitlines(keepends=True)
if len(lines) == 1:
return False
last_line = lines[-1]
was_indented = last_line.startswith((" ", "\t"))
not_empty = last_line.strip() != ""
incomplete = not last_line.endswith("\n")
return (was_indented or not_empty) and incomplete
else:
return code is None
def run_multiline_interactive_console(
console: code.InteractiveConsole,
*,
future_flags: int = 0,
) -> None:
from .readline import _setup
_setup(console.locals)
if future_flags:
console.compile.compiler.flags |= future_flags
more_lines = functools.partial(_more_lines, console)
input_n = 0
def maybe_run_command(statement: str) -> bool:
statement = statement.strip()
if statement in console.locals or statement not in REPL_COMMANDS:
return False
reader = _get_reader()
reader.history.pop() # skip internal commands in history
command = REPL_COMMANDS[statement]
if callable(command):
# Make sure that history does not change because of commands
with reader.suspend_history():
command()
return True
return False
while 1:
try:
try:
sys.stdout.flush()
except Exception:
pass
ps1 = getattr(sys, "ps1", ">>> ")
ps2 = getattr(sys, "ps2", "... ")
try:
statement = multiline_input(more_lines, ps1, ps2)
except EOFError:
break
if maybe_run_command(statement):
continue
input_name = f"<python-input-{input_n}>"
linecache._register_code(input_name, statement, "<stdin>") # type: ignore[attr-defined]
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
assert not more
input_n += 1
except KeyboardInterrupt:
r = _get_reader()
if r.input_trans is r.isearch_trans:
r.do_cmd(("isearch-end", [""]))
r.pos = len(r.get_unicode())
r.dirty = True
r.refresh()
r.in_bracketed_paste = False
console.write("\nKeyboardInterrupt\n")
console.resetbuffer()
except MemoryError:
console.write("\nMemoryError\n")
console.resetbuffer()

21
Lib/_pyrepl/trace.py vendored Normal file
View File

@@ -0,0 +1,21 @@
from __future__ import annotations
import os
# types
if False:
from typing import IO
trace_file: IO[str] | None = None
if trace_filename := os.environ.get("PYREPL_TRACE"):
trace_file = open(trace_filename, "a")
def trace(line: str, *k: object, **kw: object) -> None:
if trace_file is None:
return
if k or kw:
line = line.format(*k, **kw)
trace_file.write(line + "\n")
trace_file.flush()

8
Lib/_pyrepl/types.py vendored Normal file
View File

@@ -0,0 +1,8 @@
from collections.abc import Callable, Iterator
Callback = Callable[[], object]
SimpleContextManager = Iterator[None]
KeySpec = str # like r"\C-c"
CommandName = str # like "interrupt"
EventTuple = tuple[CommandName, str]
Completer = Callable[[str, int], str | None]

810
Lib/_pyrepl/unix_console.py vendored Normal file
View File

@@ -0,0 +1,810 @@
# Copyright 2000-2010 Michael Hudson-Doyle <micahel@gmail.com>
# Antonio Cuni
# Armin Rigo
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import annotations
import errno
import os
import re
import select
import signal
import struct
import termios
import time
import platform
from fcntl import ioctl
from . import curses
from .console import Console, Event
from .fancy_termios import tcgetattr, tcsetattr
from .trace import trace
from .unix_eventqueue import EventQueue
from .utils import wlen
TYPE_CHECKING = False
# types
if TYPE_CHECKING:
from typing import IO, Literal, overload
else:
overload = lambda func: None
class InvalidTerminal(RuntimeError):
pass
_error = (termios.error, curses.error, InvalidTerminal)
SIGWINCH_EVENT = "repaint"
FIONREAD = getattr(termios, "FIONREAD", None)
TIOCGWINSZ = getattr(termios, "TIOCGWINSZ", None)
# ------------ start of baudrate definitions ------------
# Add (possibly) missing baudrates (check termios man page) to termios
def add_baudrate_if_supported(dictionary: dict[int, int], rate: int) -> None:
baudrate_name = "B%d" % rate
if hasattr(termios, baudrate_name):
dictionary[getattr(termios, baudrate_name)] = rate
# Check the termios man page (Line speed) to know where these
# values come from.
potential_baudrates = [
0,
110,
115200,
1200,
134,
150,
1800,
19200,
200,
230400,
2400,
300,
38400,
460800,
4800,
50,
57600,
600,
75,
9600,
]
ratedict: dict[int, int] = {}
for rate in potential_baudrates:
add_baudrate_if_supported(ratedict, rate)
# Clean up variables to avoid unintended usage
del rate, add_baudrate_if_supported
# ------------ end of baudrate definitions ------------
delayprog = re.compile(b"\\$<([0-9]+)((?:/|\\*){0,2})>")
try:
poll: type[select.poll] = select.poll
except AttributeError:
# this is exactly the minumum necessary to support what we
# do with poll objects
class MinimalPoll:
def __init__(self):
pass
def register(self, fd, flag):
self.fd = fd
# note: The 'timeout' argument is received as *milliseconds*
def poll(self, timeout: float | None = None) -> list[int]:
if timeout is None:
r, w, e = select.select([self.fd], [], [])
else:
r, w, e = select.select([self.fd], [], [], timeout/1000)
return r
poll = MinimalPoll # type: ignore[assignment]
class UnixConsole(Console):
def __init__(
self,
f_in: IO[bytes] | int = 0,
f_out: IO[bytes] | int = 1,
term: str = "",
encoding: str = "",
):
"""
Initialize the UnixConsole.
Parameters:
- f_in (int or file-like object): Input file descriptor or object.
- f_out (int or file-like object): Output file descriptor or object.
- term (str): Terminal name.
- encoding (str): Encoding to use for I/O operations.
"""
super().__init__(f_in, f_out, term, encoding)
self.pollob = poll()
self.pollob.register(self.input_fd, select.POLLIN)
self.input_buffer = b""
self.input_buffer_pos = 0
curses.setupterm(term or None, self.output_fd)
self.term = term
@overload
def _my_getstr(cap: str, optional: Literal[False] = False) -> bytes: ...
@overload
def _my_getstr(cap: str, optional: bool) -> bytes | None: ...
def _my_getstr(cap: str, optional: bool = False) -> bytes | None:
r = curses.tigetstr(cap)
if not optional and r is None:
raise InvalidTerminal(
f"terminal doesn't have the required {cap} capability"
)
return r
self._bel = _my_getstr("bel")
self._civis = _my_getstr("civis", optional=True)
self._clear = _my_getstr("clear")
self._cnorm = _my_getstr("cnorm", optional=True)
self._cub = _my_getstr("cub", optional=True)
self._cub1 = _my_getstr("cub1", optional=True)
self._cud = _my_getstr("cud", optional=True)
self._cud1 = _my_getstr("cud1", optional=True)
self._cuf = _my_getstr("cuf", optional=True)
self._cuf1 = _my_getstr("cuf1", optional=True)
self._cup = _my_getstr("cup")
self._cuu = _my_getstr("cuu", optional=True)
self._cuu1 = _my_getstr("cuu1", optional=True)
self._dch1 = _my_getstr("dch1", optional=True)
self._dch = _my_getstr("dch", optional=True)
self._el = _my_getstr("el")
self._hpa = _my_getstr("hpa", optional=True)
self._ich = _my_getstr("ich", optional=True)
self._ich1 = _my_getstr("ich1", optional=True)
self._ind = _my_getstr("ind", optional=True)
self._pad = _my_getstr("pad", optional=True)
self._ri = _my_getstr("ri", optional=True)
self._rmkx = _my_getstr("rmkx", optional=True)
self._smkx = _my_getstr("smkx", optional=True)
self.__setup_movement()
self.event_queue = EventQueue(self.input_fd, self.encoding)
self.cursor_visible = 1
def more_in_buffer(self) -> bool:
return bool(
self.input_buffer
and self.input_buffer_pos < len(self.input_buffer)
)
def __read(self, n: int) -> bytes:
if not self.more_in_buffer():
self.input_buffer = os.read(self.input_fd, 10000)
ret = self.input_buffer[self.input_buffer_pos : self.input_buffer_pos + n]
self.input_buffer_pos += len(ret)
if self.input_buffer_pos >= len(self.input_buffer):
self.input_buffer = b""
self.input_buffer_pos = 0
return ret
def change_encoding(self, encoding: str) -> None:
"""
Change the encoding used for I/O operations.
Parameters:
- encoding (str): New encoding to use.
"""
self.encoding = encoding
def refresh(self, screen, c_xy):
"""
Refresh the console screen.
Parameters:
- screen (list): List of strings representing the screen contents.
- c_xy (tuple): Cursor position (x, y) on the screen.
"""
cx, cy = c_xy
if not self.__gone_tall:
while len(self.screen) < min(len(screen), self.height):
self.__hide_cursor()
self.__move(0, len(self.screen) - 1)
self.__write("\n")
self.posxy = 0, len(self.screen)
self.screen.append("")
else:
while len(self.screen) < len(screen):
self.screen.append("")
if len(screen) > self.height:
self.__gone_tall = 1
self.__move = self.__move_tall
px, py = self.posxy
old_offset = offset = self.__offset
height = self.height
# we make sure the cursor is on the screen, and that we're
# using all of the screen if we can
if cy < offset:
offset = cy
elif cy >= offset + height:
offset = cy - height + 1
elif offset > 0 and len(screen) < offset + height:
offset = max(len(screen) - height, 0)
screen.append("")
oldscr = self.screen[old_offset : old_offset + height]
newscr = screen[offset : offset + height]
# use hardware scrolling if we have it.
if old_offset > offset and self._ri:
self.__hide_cursor()
self.__write_code(self._cup, 0, 0)
self.posxy = 0, old_offset
for i in range(old_offset - offset):
self.__write_code(self._ri)
oldscr.pop(-1)
oldscr.insert(0, "")
elif old_offset < offset and self._ind:
self.__hide_cursor()
self.__write_code(self._cup, self.height - 1, 0)
self.posxy = 0, old_offset + self.height - 1
for i in range(offset - old_offset):
self.__write_code(self._ind)
oldscr.pop(0)
oldscr.append("")
self.__offset = offset
for (
y,
oldline,
newline,
) in zip(range(offset, offset + height), oldscr, newscr):
if oldline != newline:
self.__write_changed_line(y, oldline, newline, px)
y = len(newscr)
while y < len(oldscr):
self.__hide_cursor()
self.__move(0, y)
self.posxy = 0, y
self.__write_code(self._el)
y += 1
self.__show_cursor()
self.screen = screen.copy()
self.move_cursor(cx, cy)
self.flushoutput()
def move_cursor(self, x, y):
"""
Move the cursor to the specified position on the screen.
Parameters:
- x (int): X coordinate.
- y (int): Y coordinate.
"""
if y < self.__offset or y >= self.__offset + self.height:
self.event_queue.insert(Event("scroll", None))
else:
self.__move(x, y)
self.posxy = x, y
self.flushoutput()
def prepare(self):
"""
Prepare the console for input/output operations.
"""
self.__svtermstate = tcgetattr(self.input_fd)
raw = self.__svtermstate.copy()
raw.iflag &= ~(termios.INPCK | termios.ISTRIP | termios.IXON)
raw.oflag &= ~(termios.OPOST)
raw.cflag &= ~(termios.CSIZE | termios.PARENB)
raw.cflag |= termios.CS8
raw.iflag |= termios.BRKINT
raw.lflag &= ~(termios.ICANON | termios.ECHO | termios.IEXTEN)
raw.lflag |= termios.ISIG
raw.cc[termios.VMIN] = 1
raw.cc[termios.VTIME] = 0
tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
# In macOS terminal we need to deactivate line wrap via ANSI escape code
if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal":
os.write(self.output_fd, b"\033[?7l")
self.screen = []
self.height, self.width = self.getheightwidth()
self.__buffer = []
self.posxy = 0, 0
self.__gone_tall = 0
self.__move = self.__move_short
self.__offset = 0
self.__maybe_write_code(self._smkx)
try:
self.old_sigwinch = signal.signal(signal.SIGWINCH, self.__sigwinch)
except ValueError:
pass
self.__enable_bracketed_paste()
def restore(self):
"""
Restore the console to the default state
"""
self.__disable_bracketed_paste()
self.__maybe_write_code(self._rmkx)
self.flushoutput()
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal":
os.write(self.output_fd, b"\033[?7h")
if hasattr(self, "old_sigwinch"):
signal.signal(signal.SIGWINCH, self.old_sigwinch)
del self.old_sigwinch
def push_char(self, char: int | bytes) -> None:
"""
Push a character to the console event queue.
"""
trace("push char {char!r}", char=char)
self.event_queue.push(char)
def get_event(self, block: bool = True) -> Event | None:
"""
Get an event from the console event queue.
Parameters:
- block (bool): Whether to block until an event is available.
Returns:
- Event: Event object from the event queue.
"""
if not block and not self.wait(timeout=0):
return None
while self.event_queue.empty():
while True:
try:
self.push_char(self.__read(1))
except OSError as err:
if err.errno == errno.EINTR:
if not self.event_queue.empty():
return self.event_queue.get()
else:
continue
else:
raise
else:
break
return self.event_queue.get()
def wait(self, timeout: float | None = None) -> bool:
"""
Wait for events on the console.
"""
return (
not self.event_queue.empty()
or self.more_in_buffer()
or bool(self.pollob.poll(timeout))
)
def set_cursor_vis(self, visible):
"""
Set the visibility of the cursor.
Parameters:
- visible (bool): Visibility flag.
"""
if visible:
self.__show_cursor()
else:
self.__hide_cursor()
if TIOCGWINSZ:
def getheightwidth(self):
"""
Get the height and width of the console.
Returns:
- tuple: Height and width of the console.
"""
try:
return int(os.environ["LINES"]), int(os.environ["COLUMNS"])
except (KeyError, TypeError, ValueError):
try:
size = ioctl(self.input_fd, TIOCGWINSZ, b"\000" * 8)
except OSError:
return 25, 80
height, width = struct.unpack("hhhh", size)[0:2]
if not height:
return 25, 80
return height, width
else:
def getheightwidth(self):
"""
Get the height and width of the console.
Returns:
- tuple: Height and width of the console.
"""
try:
return int(os.environ["LINES"]), int(os.environ["COLUMNS"])
except (KeyError, TypeError, ValueError):
return 25, 80
def forgetinput(self):
"""
Discard any pending input on the console.
"""
termios.tcflush(self.input_fd, termios.TCIFLUSH)
def flushoutput(self):
"""
Flush the output buffer.
"""
for text, iscode in self.__buffer:
if iscode:
self.__tputs(text)
else:
os.write(self.output_fd, text.encode(self.encoding, "replace"))
del self.__buffer[:]
def finish(self):
"""
Finish console operations and flush the output buffer.
"""
y = len(self.screen) - 1
while y >= 0 and not self.screen[y]:
y -= 1
self.__move(0, min(y, self.height + self.__offset - 1))
self.__write("\n\r")
self.flushoutput()
def beep(self):
"""
Emit a beep sound.
"""
self.__maybe_write_code(self._bel)
self.flushoutput()
if FIONREAD:
def getpending(self):
"""
Get pending events from the console event queue.
Returns:
- Event: Pending event from the event queue.
"""
e = Event("key", "", b"")
while not self.event_queue.empty():
e2 = self.event_queue.get()
e.data += e2.data
e.raw += e.raw
amount = struct.unpack("i", ioctl(self.input_fd, FIONREAD, b"\0\0\0\0"))[0]
raw = self.__read(amount)
data = str(raw, self.encoding, "replace")
e.data += data
e.raw += raw
return e
else:
def getpending(self):
"""
Get pending events from the console event queue.
Returns:
- Event: Pending event from the event queue.
"""
e = Event("key", "", b"")
while not self.event_queue.empty():
e2 = self.event_queue.get()
e.data += e2.data
e.raw += e.raw
amount = 10000
raw = self.__read(amount)
data = str(raw, self.encoding, "replace")
e.data += data
e.raw += raw
return e
def clear(self):
"""
Clear the console screen.
"""
self.__write_code(self._clear)
self.__gone_tall = 1
self.__move = self.__move_tall
self.posxy = 0, 0
self.screen = []
@property
def input_hook(self):
try:
import posix
except ImportError:
return None
if posix._is_inputhook_installed():
return posix._inputhook
def __enable_bracketed_paste(self) -> None:
os.write(self.output_fd, b"\x1b[?2004h")
def __disable_bracketed_paste(self) -> None:
os.write(self.output_fd, b"\x1b[?2004l")
def __setup_movement(self):
"""
Set up the movement functions based on the terminal capabilities.
"""
if 0 and self._hpa: # hpa don't work in windows telnet :-(
self.__move_x = self.__move_x_hpa
elif self._cub and self._cuf:
self.__move_x = self.__move_x_cub_cuf
elif self._cub1 and self._cuf1:
self.__move_x = self.__move_x_cub1_cuf1
else:
raise RuntimeError("insufficient terminal (horizontal)")
if self._cuu and self._cud:
self.__move_y = self.__move_y_cuu_cud
elif self._cuu1 and self._cud1:
self.__move_y = self.__move_y_cuu1_cud1
else:
raise RuntimeError("insufficient terminal (vertical)")
if self._dch1:
self.dch1 = self._dch1
elif self._dch:
self.dch1 = curses.tparm(self._dch, 1)
else:
self.dch1 = None
if self._ich1:
self.ich1 = self._ich1
elif self._ich:
self.ich1 = curses.tparm(self._ich, 1)
else:
self.ich1 = None
self.__move = self.__move_short
def __write_changed_line(self, y, oldline, newline, px_coord):
# this is frustrating; there's no reason to test (say)
# self.dch1 inside the loop -- but alternative ways of
# structuring this function are equally painful (I'm trying to
# avoid writing code generators these days...)
minlen = min(wlen(oldline), wlen(newline))
x_pos = 0
x_coord = 0
px_pos = 0
j = 0
for c in oldline:
if j >= px_coord:
break
j += wlen(c)
px_pos += 1
# reuse the oldline as much as possible, but stop as soon as we
# encounter an ESCAPE, because it might be the start of an escape
# sequene
while (
x_coord < minlen
and oldline[x_pos] == newline[x_pos]
and newline[x_pos] != "\x1b"
):
x_coord += wlen(newline[x_pos])
x_pos += 1
# if we need to insert a single character right after the first detected change
if oldline[x_pos:] == newline[x_pos + 1 :] and self.ich1:
if (
y == self.posxy[1]
and x_coord > self.posxy[0]
and oldline[px_pos:x_pos] == newline[px_pos + 1 : x_pos + 1]
):
x_pos = px_pos
x_coord = px_coord
character_width = wlen(newline[x_pos])
self.__move(x_coord, y)
self.__write_code(self.ich1)
self.__write(newline[x_pos])
self.posxy = x_coord + character_width, y
# if it's a single character change in the middle of the line
elif (
x_coord < minlen
and oldline[x_pos + 1 :] == newline[x_pos + 1 :]
and wlen(oldline[x_pos]) == wlen(newline[x_pos])
):
character_width = wlen(newline[x_pos])
self.__move(x_coord, y)
self.__write(newline[x_pos])
self.posxy = x_coord + character_width, y
# if this is the last character to fit in the line and we edit in the middle of the line
elif (
self.dch1
and self.ich1
and wlen(newline) == self.width
and x_coord < wlen(newline) - 2
and newline[x_pos + 1 : -1] == oldline[x_pos:-2]
):
self.__hide_cursor()
self.__move(self.width - 2, y)
self.posxy = self.width - 2, y
self.__write_code(self.dch1)
character_width = wlen(newline[x_pos])
self.__move(x_coord, y)
self.__write_code(self.ich1)
self.__write(newline[x_pos])
self.posxy = character_width + 1, y
else:
self.__hide_cursor()
self.__move(x_coord, y)
if wlen(oldline) > wlen(newline):
self.__write_code(self._el)
self.__write(newline[x_pos:])
self.posxy = wlen(newline), y
if "\x1b" in newline:
# ANSI escape characters are present, so we can't assume
# anything about the position of the cursor. Moving the cursor
# to the left margin should work to get to a known position.
self.move_cursor(0, y)
def __write(self, text):
self.__buffer.append((text, 0))
def __write_code(self, fmt, *args):
self.__buffer.append((curses.tparm(fmt, *args), 1))
def __maybe_write_code(self, fmt, *args):
if fmt:
self.__write_code(fmt, *args)
def __move_y_cuu1_cud1(self, y):
assert self._cud1 is not None
assert self._cuu1 is not None
dy = y - self.posxy[1]
if dy > 0:
self.__write_code(dy * self._cud1)
elif dy < 0:
self.__write_code((-dy) * self._cuu1)
def __move_y_cuu_cud(self, y):
dy = y - self.posxy[1]
if dy > 0:
self.__write_code(self._cud, dy)
elif dy < 0:
self.__write_code(self._cuu, -dy)
def __move_x_hpa(self, x: int) -> None:
if x != self.posxy[0]:
self.__write_code(self._hpa, x)
def __move_x_cub1_cuf1(self, x: int) -> None:
assert self._cuf1 is not None
assert self._cub1 is not None
dx = x - self.posxy[0]
if dx > 0:
self.__write_code(self._cuf1 * dx)
elif dx < 0:
self.__write_code(self._cub1 * (-dx))
def __move_x_cub_cuf(self, x: int) -> None:
dx = x - self.posxy[0]
if dx > 0:
self.__write_code(self._cuf, dx)
elif dx < 0:
self.__write_code(self._cub, -dx)
def __move_short(self, x, y):
self.__move_x(x)
self.__move_y(y)
def __move_tall(self, x, y):
assert 0 <= y - self.__offset < self.height, y - self.__offset
self.__write_code(self._cup, y - self.__offset, x)
def __sigwinch(self, signum, frame):
self.height, self.width = self.getheightwidth()
self.event_queue.insert(Event("resize", None))
def __hide_cursor(self):
if self.cursor_visible:
self.__maybe_write_code(self._civis)
self.cursor_visible = 0
def __show_cursor(self):
if not self.cursor_visible:
self.__maybe_write_code(self._cnorm)
self.cursor_visible = 1
def repaint(self):
if not self.__gone_tall:
self.posxy = 0, self.posxy[1]
self.__write("\r")
ns = len(self.screen) * ["\000" * self.width]
self.screen = ns
else:
self.posxy = 0, self.__offset
self.__move(0, self.__offset)
ns = self.height * ["\000" * self.width]
self.screen = ns
def __tputs(self, fmt, prog=delayprog):
"""A Python implementation of the curses tputs function; the
curses one can't really be wrapped in a sane manner.
I have the strong suspicion that this is complexity that
will never do anyone any good."""
# using .get() means that things will blow up
# only if the bps is actually needed (which I'm
# betting is pretty unlkely)
bps = ratedict.get(self.__svtermstate.ospeed)
while 1:
m = prog.search(fmt)
if not m:
os.write(self.output_fd, fmt)
break
x, y = m.span()
os.write(self.output_fd, fmt[:x])
fmt = fmt[y:]
delay = int(m.group(1))
if b"*" in m.group(2):
delay *= self.height
if self._pad and bps is not None:
nchars = (bps * delay) / 1000
os.write(self.output_fd, self._pad * nchars)
else:
time.sleep(float(delay) / 1000.0)

152
Lib/_pyrepl/unix_eventqueue.py vendored Normal file
View File

@@ -0,0 +1,152 @@
# Copyright 2000-2008 Michael Hudson-Doyle <micahel@gmail.com>
# Armin Rigo
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from collections import deque
from . import keymap
from .console import Event
from . import curses
from .trace import trace
from termios import tcgetattr, VERASE
import os
# Mapping of human-readable key names to their terminal-specific codes
TERMINAL_KEYNAMES = {
"delete": "kdch1",
"down": "kcud1",
"end": "kend",
"enter": "kent",
"home": "khome",
"insert": "kich1",
"left": "kcub1",
"page down": "knp",
"page up": "kpp",
"right": "kcuf1",
"up": "kcuu1",
}
# Function keys F1-F20 mapping
TERMINAL_KEYNAMES.update(("f%d" % i, "kf%d" % i) for i in range(1, 21))
# Known CTRL-arrow keycodes
CTRL_ARROW_KEYCODES= {
# for xterm, gnome-terminal, xfce terminal, etc.
b'\033[1;5D': 'ctrl left',
b'\033[1;5C': 'ctrl right',
# for rxvt
b'\033Od': 'ctrl left',
b'\033Oc': 'ctrl right',
}
def get_terminal_keycodes() -> dict[bytes, str]:
"""
Generates a dictionary mapping terminal keycodes to human-readable names.
"""
keycodes = {}
for key, terminal_code in TERMINAL_KEYNAMES.items():
keycode = curses.tigetstr(terminal_code)
trace('key {key} tiname {terminal_code} keycode {keycode!r}', **locals())
if keycode:
keycodes[keycode] = key
keycodes.update(CTRL_ARROW_KEYCODES)
return keycodes
class EventQueue:
def __init__(self, fd: int, encoding: str) -> None:
self.keycodes = get_terminal_keycodes()
if os.isatty(fd):
backspace = tcgetattr(fd)[6][VERASE]
self.keycodes[backspace] = "backspace"
self.compiled_keymap = keymap.compile_keymap(self.keycodes)
self.keymap = self.compiled_keymap
trace("keymap {k!r}", k=self.keymap)
self.encoding = encoding
self.events: deque[Event] = deque()
self.buf = bytearray()
def get(self) -> Event | None:
"""
Retrieves the next event from the queue.
"""
if self.events:
return self.events.popleft()
else:
return None
def empty(self) -> bool:
"""
Checks if the queue is empty.
"""
return not self.events
def flush_buf(self) -> bytearray:
"""
Flushes the buffer and returns its contents.
"""
old = self.buf
self.buf = bytearray()
return old
def insert(self, event: Event) -> None:
"""
Inserts an event into the queue.
"""
trace('added event {event}', event=event)
self.events.append(event)
def push(self, char: int | bytes) -> None:
"""
Processes a character by updating the buffer and handling special key mappings.
"""
ord_char = char if isinstance(char, int) else ord(char)
char = bytes(bytearray((ord_char,)))
self.buf.append(ord_char)
if char in self.keymap:
if self.keymap is self.compiled_keymap:
#sanity check, buffer is empty when a special key comes
assert len(self.buf) == 1
k = self.keymap[char]
trace('found map {k!r}', k=k)
if isinstance(k, dict):
self.keymap = k
else:
self.insert(Event('key', k, self.flush_buf()))
self.keymap = self.compiled_keymap
elif self.buf and self.buf[0] == 27: # escape
# escape sequence not recognized by our keymap: propagate it
# outside so that i can be recognized as an M-... key (see also
# the docstring in keymap.py
trace('unrecognized escape sequence, propagating...')
self.keymap = self.compiled_keymap
self.insert(Event('key', '\033', bytearray(b'\033')))
for _c in self.flush_buf()[1:]:
self.push(_c)
else:
try:
decoded = bytes(self.buf).decode(self.encoding)
except UnicodeError:
return
else:
self.insert(Event('key', decoded, self.flush_buf()))
self.keymap = self.compiled_keymap

25
Lib/_pyrepl/utils.py vendored Normal file
View File

@@ -0,0 +1,25 @@
import re
import unicodedata
import functools
ANSI_ESCAPE_SEQUENCE = re.compile(r"\x1b\[[ -@]*[A-~]")
@functools.cache
def str_width(c: str) -> int:
if ord(c) < 128:
return 1
w = unicodedata.east_asian_width(c)
if w in ('N', 'Na', 'H', 'A'):
return 1
return 2
def wlen(s: str) -> int:
if len(s) == 1 and s != '\x1a':
return str_width(s)
length = sum(str_width(i) for i in s)
# remove lengths of any escape sequences
sequence = ANSI_ESCAPE_SEQUENCE.findall(s)
ctrl_z_cnt = s.count('\x1a')
return length - sum(len(i) for i in sequence) + ctrl_z_cnt

618
Lib/_pyrepl/windows_console.py vendored Normal file
View File

@@ -0,0 +1,618 @@
# Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from __future__ import annotations
import io
import os
import sys
import time
import msvcrt
from collections import deque
import ctypes
from ctypes.wintypes import (
_COORD,
WORD,
SMALL_RECT,
BOOL,
HANDLE,
CHAR,
DWORD,
WCHAR,
SHORT,
)
from ctypes import Structure, POINTER, Union
from .console import Event, Console
from .trace import trace
from .utils import wlen
try:
from ctypes import GetLastError, WinDLL, windll, WinError # type: ignore[attr-defined]
except:
# Keep MyPy happy off Windows
from ctypes import CDLL as WinDLL, cdll as windll
def GetLastError() -> int:
return 42
class WinError(OSError): # type: ignore[no-redef]
def __init__(self, err: int | None, descr: str | None = None) -> None:
self.err = err
self.descr = descr
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import IO
# Virtual-Key Codes: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
VK_MAP: dict[int, str] = {
0x23: "end", # VK_END
0x24: "home", # VK_HOME
0x25: "left", # VK_LEFT
0x26: "up", # VK_UP
0x27: "right", # VK_RIGHT
0x28: "down", # VK_DOWN
0x2E: "delete", # VK_DELETE
0x70: "f1", # VK_F1
0x71: "f2", # VK_F2
0x72: "f3", # VK_F3
0x73: "f4", # VK_F4
0x74: "f5", # VK_F5
0x75: "f6", # VK_F6
0x76: "f7", # VK_F7
0x77: "f8", # VK_F8
0x78: "f9", # VK_F9
0x79: "f10", # VK_F10
0x7A: "f11", # VK_F11
0x7B: "f12", # VK_F12
0x7C: "f13", # VK_F13
0x7D: "f14", # VK_F14
0x7E: "f15", # VK_F15
0x7F: "f16", # VK_F16
0x80: "f17", # VK_F17
0x81: "f18", # VK_F18
0x82: "f19", # VK_F19
0x83: "f20", # VK_F20
}
# Console escape codes: https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
ERASE_IN_LINE = "\x1b[K"
MOVE_LEFT = "\x1b[{}D"
MOVE_RIGHT = "\x1b[{}C"
MOVE_UP = "\x1b[{}A"
MOVE_DOWN = "\x1b[{}B"
CLEAR = "\x1b[H\x1b[J"
class _error(Exception):
pass
class WindowsConsole(Console):
def __init__(
self,
f_in: IO[bytes] | int = 0,
f_out: IO[bytes] | int = 1,
term: str = "",
encoding: str = "",
):
super().__init__(f_in, f_out, term, encoding)
SetConsoleMode(
OutHandle,
ENABLE_WRAP_AT_EOL_OUTPUT
| ENABLE_PROCESSED_OUTPUT
| ENABLE_VIRTUAL_TERMINAL_PROCESSING,
)
self.screen: list[str] = []
self.width = 80
self.height = 25
self.__offset = 0
self.event_queue: deque[Event] = deque()
try:
self.out = io._WindowsConsoleIO(self.output_fd, "w") # type: ignore[attr-defined]
except ValueError:
# Console I/O is redirected, fallback...
self.out = None
def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None:
"""
Refresh the console screen.
Parameters:
- screen (list): List of strings representing the screen contents.
- c_xy (tuple): Cursor position (x, y) on the screen.
"""
cx, cy = c_xy
while len(self.screen) < min(len(screen), self.height):
self._hide_cursor()
self._move_relative(0, len(self.screen) - 1)
self.__write("\n")
self.posxy = 0, len(self.screen)
self.screen.append("")
px, py = self.posxy
old_offset = offset = self.__offset
height = self.height
# we make sure the cursor is on the screen, and that we're
# using all of the screen if we can
if cy < offset:
offset = cy
elif cy >= offset + height:
offset = cy - height + 1
scroll_lines = offset - old_offset
# Scrolling the buffer as the current input is greater than the visible
# portion of the window. We need to scroll the visible portion and the
# entire history
self._scroll(scroll_lines, self._getscrollbacksize())
self.posxy = self.posxy[0], self.posxy[1] + scroll_lines
self.__offset += scroll_lines
for i in range(scroll_lines):
self.screen.append("")
elif offset > 0 and len(screen) < offset + height:
offset = max(len(screen) - height, 0)
screen.append("")
oldscr = self.screen[old_offset : old_offset + height]
newscr = screen[offset : offset + height]
self.__offset = offset
self._hide_cursor()
for (
y,
oldline,
newline,
) in zip(range(offset, offset + height), oldscr, newscr):
if oldline != newline:
self.__write_changed_line(y, oldline, newline, px)
y = len(newscr)
while y < len(oldscr):
self._move_relative(0, y)
self.posxy = 0, y
self._erase_to_end()
y += 1
self._show_cursor()
self.screen = screen
self.move_cursor(cx, cy)
@property
def input_hook(self):
try:
import nt
except ImportError:
return None
if nt._is_inputhook_installed():
return nt._inputhook
def __write_changed_line(
self, y: int, oldline: str, newline: str, px_coord: int
) -> None:
# this is frustrating; there's no reason to test (say)
# self.dch1 inside the loop -- but alternative ways of
# structuring this function are equally painful (I'm trying to
# avoid writing code generators these days...)
minlen = min(wlen(oldline), wlen(newline))
x_pos = 0
x_coord = 0
px_pos = 0
j = 0
for c in oldline:
if j >= px_coord:
break
j += wlen(c)
px_pos += 1
# reuse the oldline as much as possible, but stop as soon as we
# encounter an ESCAPE, because it might be the start of an escape
# sequene
while (
x_coord < minlen
and oldline[x_pos] == newline[x_pos]
and newline[x_pos] != "\x1b"
):
x_coord += wlen(newline[x_pos])
x_pos += 1
self._hide_cursor()
self._move_relative(x_coord, y)
if wlen(oldline) > wlen(newline):
self._erase_to_end()
self.__write(newline[x_pos:])
if wlen(newline) == self.width:
# If we wrapped we want to start at the next line
self._move_relative(0, y + 1)
self.posxy = 0, y + 1
else:
self.posxy = wlen(newline), y
if "\x1b" in newline or y != self.posxy[1] or '\x1a' in newline:
# ANSI escape characters are present, so we can't assume
# anything about the position of the cursor. Moving the cursor
# to the left margin should work to get to a known position.
self.move_cursor(0, y)
def _scroll(
self, top: int, bottom: int, left: int | None = None, right: int | None = None
) -> None:
scroll_rect = SMALL_RECT()
scroll_rect.Top = SHORT(top)
scroll_rect.Bottom = SHORT(bottom)
scroll_rect.Left = SHORT(0 if left is None else left)
scroll_rect.Right = SHORT(
self.getheightwidth()[1] - 1 if right is None else right
)
destination_origin = _COORD()
fill_info = CHAR_INFO()
fill_info.UnicodeChar = " "
if not ScrollConsoleScreenBuffer(
OutHandle, scroll_rect, None, destination_origin, fill_info
):
raise WinError(GetLastError())
def _hide_cursor(self):
self.__write("\x1b[?25l")
def _show_cursor(self):
self.__write("\x1b[?25h")
def _enable_blinking(self):
self.__write("\x1b[?12h")
def _disable_blinking(self):
self.__write("\x1b[?12l")
def __write(self, text: str) -> None:
if "\x1a" in text:
text = ''.join(["^Z" if x == '\x1a' else x for x in text])
if self.out is not None:
self.out.write(text.encode(self.encoding, "replace"))
self.out.flush()
else:
os.write(self.output_fd, text.encode(self.encoding, "replace"))
@property
def screen_xy(self) -> tuple[int, int]:
info = CONSOLE_SCREEN_BUFFER_INFO()
if not GetConsoleScreenBufferInfo(OutHandle, info):
raise WinError(GetLastError())
return info.dwCursorPosition.X, info.dwCursorPosition.Y
def _erase_to_end(self) -> None:
self.__write(ERASE_IN_LINE)
def prepare(self) -> None:
trace("prepare")
self.screen = []
self.height, self.width = self.getheightwidth()
self.posxy = 0, 0
self.__gone_tall = 0
self.__offset = 0
def restore(self) -> None:
pass
def _move_relative(self, x: int, y: int) -> None:
"""Moves relative to the current posxy"""
dx = x - self.posxy[0]
dy = y - self.posxy[1]
if dx < 0:
self.__write(MOVE_LEFT.format(-dx))
elif dx > 0:
self.__write(MOVE_RIGHT.format(dx))
if dy < 0:
self.__write(MOVE_UP.format(-dy))
elif dy > 0:
self.__write(MOVE_DOWN.format(dy))
def move_cursor(self, x: int, y: int) -> None:
if x < 0 or y < 0:
raise ValueError(f"Bad cursor position {x}, {y}")
if y < self.__offset or y >= self.__offset + self.height:
self.event_queue.insert(0, Event("scroll", ""))
else:
self._move_relative(x, y)
self.posxy = x, y
def set_cursor_vis(self, visible: bool) -> None:
if visible:
self._show_cursor()
else:
self._hide_cursor()
def getheightwidth(self) -> tuple[int, int]:
"""Return (height, width) where height and width are the height
and width of the terminal window in characters."""
info = CONSOLE_SCREEN_BUFFER_INFO()
if not GetConsoleScreenBufferInfo(OutHandle, info):
raise WinError(GetLastError())
return (
info.srWindow.Bottom - info.srWindow.Top + 1,
info.srWindow.Right - info.srWindow.Left + 1,
)
def _getscrollbacksize(self) -> int:
info = CONSOLE_SCREEN_BUFFER_INFO()
if not GetConsoleScreenBufferInfo(OutHandle, info):
raise WinError(GetLastError())
return info.srWindow.Bottom # type: ignore[no-any-return]
def _read_input(self, block: bool = True) -> INPUT_RECORD | None:
if not block:
events = DWORD()
if not GetNumberOfConsoleInputEvents(InHandle, events):
raise WinError(GetLastError())
if not events.value:
return None
rec = INPUT_RECORD()
read = DWORD()
if not ReadConsoleInput(InHandle, rec, 1, read):
raise WinError(GetLastError())
return rec
def get_event(self, block: bool = True) -> Event | None:
"""Return an Event instance. Returns None if |block| is false
and there is no event pending, otherwise waits for the
completion of an event."""
if self.event_queue:
return self.event_queue.pop()
while True:
rec = self._read_input(block)
if rec is None:
return None
if rec.EventType == WINDOW_BUFFER_SIZE_EVENT:
return Event("resize", "")
if rec.EventType != KEY_EVENT or not rec.Event.KeyEvent.bKeyDown:
# Only process keys and keydown events
if block:
continue
return None
key = rec.Event.KeyEvent.uChar.UnicodeChar
if rec.Event.KeyEvent.uChar.UnicodeChar == "\r":
# Make enter make unix-like
return Event(evt="key", data="\n", raw=b"\n")
elif rec.Event.KeyEvent.wVirtualKeyCode == 8:
# Turn backspace directly into the command
return Event(
evt="key",
data="backspace",
raw=rec.Event.KeyEvent.uChar.UnicodeChar,
)
elif rec.Event.KeyEvent.uChar.UnicodeChar == "\x00":
# Handle special keys like arrow keys and translate them into the appropriate command
code = VK_MAP.get(rec.Event.KeyEvent.wVirtualKeyCode)
if code:
return Event(
evt="key", data=code, raw=rec.Event.KeyEvent.uChar.UnicodeChar
)
if block:
continue
return None
return Event(evt="key", data=key, raw=rec.Event.KeyEvent.uChar.UnicodeChar)
def push_char(self, char: int | bytes) -> None:
"""
Push a character to the console event queue.
"""
raise NotImplementedError("push_char not supported on Windows")
def beep(self) -> None:
self.__write("\x07")
def clear(self) -> None:
"""Wipe the screen"""
self.__write(CLEAR)
self.posxy = 0, 0
self.screen = [""]
def finish(self) -> None:
"""Move the cursor to the end of the display and otherwise get
ready for end. XXX could be merged with restore? Hmm."""
y = len(self.screen) - 1
while y >= 0 and not self.screen[y]:
y -= 1
self._move_relative(0, min(y, self.height + self.__offset - 1))
self.__write("\r\n")
def flushoutput(self) -> None:
"""Flush all output to the screen (assuming there's some
buffering going on somewhere).
All output on Windows is unbuffered so this is a nop"""
pass
def forgetinput(self) -> None:
"""Forget all pending, but not yet processed input."""
if not FlushConsoleInputBuffer(InHandle):
raise WinError(GetLastError())
def getpending(self) -> Event:
"""Return the characters that have been typed but not yet
processed."""
return Event("key", "", b"")
def wait(self, timeout: float | None) -> bool:
"""Wait for an event."""
# Poor man's Windows select loop
start_time = time.time()
while True:
if msvcrt.kbhit(): # type: ignore[attr-defined]
return True
if timeout and time.time() - start_time > timeout / 1000:
return False
time.sleep(0.01)
def repaint(self) -> None:
raise NotImplementedError("No repaint support")
# Windows interop
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
_fields_ = [
("dwSize", _COORD),
("dwCursorPosition", _COORD),
("wAttributes", WORD),
("srWindow", SMALL_RECT),
("dwMaximumWindowSize", _COORD),
]
class CONSOLE_CURSOR_INFO(Structure):
_fields_ = [
("dwSize", DWORD),
("bVisible", BOOL),
]
class CHAR_INFO(Structure):
_fields_ = [
("UnicodeChar", WCHAR),
("Attributes", WORD),
]
class Char(Union):
_fields_ = [
("UnicodeChar", WCHAR),
("Char", CHAR),
]
class KeyEvent(ctypes.Structure):
_fields_ = [
("bKeyDown", BOOL),
("wRepeatCount", WORD),
("wVirtualKeyCode", WORD),
("wVirtualScanCode", WORD),
("uChar", Char),
("dwControlKeyState", DWORD),
]
class WindowsBufferSizeEvent(ctypes.Structure):
_fields_ = [("dwSize", _COORD)]
class ConsoleEvent(ctypes.Union):
_fields_ = [
("KeyEvent", KeyEvent),
("WindowsBufferSizeEvent", WindowsBufferSizeEvent),
]
class INPUT_RECORD(Structure):
_fields_ = [("EventType", WORD), ("Event", ConsoleEvent)]
KEY_EVENT = 0x01
FOCUS_EVENT = 0x10
MENU_EVENT = 0x08
MOUSE_EVENT = 0x02
WINDOW_BUFFER_SIZE_EVENT = 0x04
ENABLE_PROCESSED_OUTPUT = 0x01
ENABLE_WRAP_AT_EOL_OUTPUT = 0x02
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x04
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11
if sys.platform == "win32":
_KERNEL32 = WinDLL("kernel32", use_last_error=True)
GetStdHandle = windll.kernel32.GetStdHandle
GetStdHandle.argtypes = [DWORD]
GetStdHandle.restype = HANDLE
GetConsoleScreenBufferInfo = _KERNEL32.GetConsoleScreenBufferInfo
GetConsoleScreenBufferInfo.argtypes = [
HANDLE,
ctypes.POINTER(CONSOLE_SCREEN_BUFFER_INFO),
]
GetConsoleScreenBufferInfo.restype = BOOL
ScrollConsoleScreenBuffer = _KERNEL32.ScrollConsoleScreenBufferW
ScrollConsoleScreenBuffer.argtypes = [
HANDLE,
POINTER(SMALL_RECT),
POINTER(SMALL_RECT),
_COORD,
POINTER(CHAR_INFO),
]
ScrollConsoleScreenBuffer.restype = BOOL
SetConsoleMode = _KERNEL32.SetConsoleMode
SetConsoleMode.argtypes = [HANDLE, DWORD]
SetConsoleMode.restype = BOOL
ReadConsoleInput = _KERNEL32.ReadConsoleInputW
ReadConsoleInput.argtypes = [HANDLE, POINTER(INPUT_RECORD), DWORD, POINTER(DWORD)]
ReadConsoleInput.restype = BOOL
GetNumberOfConsoleInputEvents = _KERNEL32.GetNumberOfConsoleInputEvents
GetNumberOfConsoleInputEvents.argtypes = [HANDLE, POINTER(DWORD)]
GetNumberOfConsoleInputEvents.restype = BOOL
FlushConsoleInputBuffer = _KERNEL32.FlushConsoleInputBuffer
FlushConsoleInputBuffer.argtypes = [HANDLE]
FlushConsoleInputBuffer.restype = BOOL
OutHandle = GetStdHandle(STD_OUTPUT_HANDLE)
InHandle = GetStdHandle(STD_INPUT_HANDLE)
else:
def _win_only(*args, **kwargs):
raise NotImplementedError("Windows only")
GetStdHandle = _win_only
GetConsoleScreenBufferInfo = _win_only
ScrollConsoleScreenBuffer = _win_only
SetConsoleMode = _win_only
ReadConsoleInput = _win_only
GetNumberOfConsoleInputEvents = _win_only
FlushConsoleInputBuffer = _win_only
OutHandle = 0
InHandle = 0

View File

@@ -10,7 +10,6 @@ The objects used by the site module to add custom builtins.
import sys
class Quitter(object):
def __init__(self, name, eof):
self.name = name
@@ -48,7 +47,7 @@ class _Printer(object):
data = None
for filename in self.__filenames:
try:
with open(filename, "r") as fp:
with open(filename, encoding='utf-8') as fp:
data = fp.read()
break
except OSError:

822
Lib/_strptime.py vendored Normal file
View File

@@ -0,0 +1,822 @@
"""Strptime-related classes and functions.
CLASSES:
LocaleTime -- Discovers and stores locale-specific time information
TimeRE -- Creates regexes for pattern matching a string of text containing
time information
FUNCTIONS:
_getlang -- Figure out what language is being used for the locale
strptime -- Calculates the time struct represented by the passed-in string
"""
import os
import time
import locale
import calendar
import re
from re import compile as re_compile
from re import sub as re_sub
from re import IGNORECASE
from re import escape as re_escape
from datetime import (date as datetime_date,
timedelta as datetime_timedelta,
timezone as datetime_timezone)
from _thread import allocate_lock as _thread_allocate_lock
__all__ = []
def _getlang():
# Figure out what the current language is set to.
return locale.getlocale(locale.LC_TIME)
def _findall(haystack, needle):
# Find all positions of needle in haystack.
if not needle:
return
i = 0
while True:
i = haystack.find(needle, i)
if i < 0:
break
yield i
i += len(needle)
def _fixmonths(months):
yield from months
# The lower case of 'İ' ('\u0130') is 'i\u0307'.
# The re module only supports 1-to-1 character matching in
# case-insensitive mode.
for s in months:
if 'i\u0307' in s:
yield s.replace('i\u0307', '\u0130')
lzh_TW_alt_digits = (
# :一:二:三:四:五:六:七:八:九
'\u3007', '\u4e00', '\u4e8c', '\u4e09', '\u56db',
'\u4e94', '\u516d', '\u4e03', '\u516b', '\u4e5d',
# 十:十一:十二:十三:十四:十五:十六:十七:十八:十九
'\u5341', '\u5341\u4e00', '\u5341\u4e8c', '\u5341\u4e09', '\u5341\u56db',
'\u5341\u4e94', '\u5341\u516d', '\u5341\u4e03', '\u5341\u516b', '\u5341\u4e5d',
# 廿:廿一:廿二:廿三:廿四:廿五:廿六:廿七:廿八:廿九
'\u5eff', '\u5eff\u4e00', '\u5eff\u4e8c', '\u5eff\u4e09', '\u5eff\u56db',
'\u5eff\u4e94', '\u5eff\u516d', '\u5eff\u4e03', '\u5eff\u516b', '\u5eff\u4e5d',
# 卅:卅一
'\u5345', '\u5345\u4e00')
class LocaleTime(object):
"""Stores and handles locale-specific information related to time.
ATTRIBUTES:
f_weekday -- full weekday names (7-item list)
a_weekday -- abbreviated weekday names (7-item list)
f_month -- full month names (13-item list; dummy value in [0], which
is added by code)
a_month -- abbreviated month names (13-item list, dummy value in
[0], which is added by code)
am_pm -- AM/PM representation (2-item list)
LC_date_time -- format string for date/time representation (string)
LC_date -- format string for date representation (string)
LC_time -- format string for time representation (string)
timezone -- daylight- and non-daylight-savings timezone representation
(2-item list of sets)
lang -- Language used by instance (2-item tuple)
"""
def __init__(self):
"""Set all attributes.
Order of methods called matters for dependency reasons.
The locale language is set at the offset and then checked again before
exiting. This is to make sure that the attributes were not set with a
mix of information from more than one locale. This would most likely
happen when using threads where one thread calls a locale-dependent
function while another thread changes the locale while the function in
the other thread is still running. Proper coding would call for
locks to prevent changing the locale while locale-dependent code is
running. The check here is done in case someone does not think about
doing this.
Only other possible issue is if someone changed the timezone and did
not call tz.tzset . That is an issue for the programmer, though,
since changing the timezone is worthless without that call.
"""
self.lang = _getlang()
self.__calc_weekday()
self.__calc_month()
self.__calc_am_pm()
self.__calc_alt_digits()
self.__calc_timezone()
self.__calc_date_time()
if _getlang() != self.lang:
raise ValueError("locale changed during initialization")
if time.tzname != self.tzname or time.daylight != self.daylight:
raise ValueError("timezone changed during initialization")
def __calc_weekday(self):
# Set self.a_weekday and self.f_weekday using the calendar
# module.
a_weekday = [calendar.day_abbr[i].lower() for i in range(7)]
f_weekday = [calendar.day_name[i].lower() for i in range(7)]
self.a_weekday = a_weekday
self.f_weekday = f_weekday
def __calc_month(self):
# Set self.f_month and self.a_month using the calendar module.
a_month = [calendar.month_abbr[i].lower() for i in range(13)]
f_month = [calendar.month_name[i].lower() for i in range(13)]
self.a_month = a_month
self.f_month = f_month
def __calc_am_pm(self):
# Set self.am_pm by using time.strftime().
# The magic date (1999,3,17,hour,44,55,2,76,0) is not really that
# magical; just happened to have used it everywhere else where a
# static date was needed.
am_pm = []
for hour in (1, 22):
time_tuple = time.struct_time((1999,3,17,hour,44,55,2,76,0))
# br_FR has AM/PM info (' ',' ').
am_pm.append(time.strftime("%p", time_tuple).lower().strip())
self.am_pm = am_pm
def __calc_alt_digits(self):
# Set self.LC_alt_digits by using time.strftime().
# The magic data should contain all decimal digits.
time_tuple = time.struct_time((1998, 1, 27, 10, 43, 56, 1, 27, 0))
s = time.strftime("%x%X", time_tuple)
if s.isascii():
# Fast path -- all digits are ASCII.
self.LC_alt_digits = ()
return
digits = ''.join(sorted(set(re.findall(r'\d', s))))
if len(digits) == 10 and ord(digits[-1]) == ord(digits[0]) + 9:
# All 10 decimal digits from the same set.
if digits.isascii():
# All digits are ASCII.
self.LC_alt_digits = ()
return
self.LC_alt_digits = [a + b for a in digits for b in digits]
# Test whether the numbers contain leading zero.
time_tuple2 = time.struct_time((2000, 1, 1, 1, 1, 1, 5, 1, 0))
if self.LC_alt_digits[1] not in time.strftime("%x %X", time_tuple2):
self.LC_alt_digits[:10] = digits
return
# Either non-Gregorian calendar or non-decimal numbers.
if {'\u4e00', '\u4e03', '\u4e5d', '\u5341', '\u5eff'}.issubset(s):
# lzh_TW
self.LC_alt_digits = lzh_TW_alt_digits
return
self.LC_alt_digits = None
def __calc_date_time(self):
# Set self.LC_date_time, self.LC_date, self.LC_time and
# self.LC_time_ampm by using time.strftime().
# Use (1999,3,17,22,44,55,2,76,0) for magic date because the amount of
# overloaded numbers is minimized. The order in which searches for
# values within the format string is very important; it eliminates
# possible ambiguity for what something represents.
time_tuple = time.struct_time((1999,3,17,22,44,55,2,76,0))
time_tuple2 = time.struct_time((1999,1,3,1,1,1,6,3,0))
replacement_pairs = []
# Non-ASCII digits
if self.LC_alt_digits or self.LC_alt_digits is None:
for n, d in [(19, '%OC'), (99, '%Oy'), (22, '%OH'),
(44, '%OM'), (55, '%OS'), (17, '%Od'),
(3, '%Om'), (2, '%Ow'), (10, '%OI')]:
if self.LC_alt_digits is None:
s = chr(0x660 + n // 10) + chr(0x660 + n % 10)
replacement_pairs.append((s, d))
if n < 10:
replacement_pairs.append((s[1], d))
elif len(self.LC_alt_digits) > n:
replacement_pairs.append((self.LC_alt_digits[n], d))
else:
replacement_pairs.append((time.strftime(d, time_tuple), d))
replacement_pairs += [
('1999', '%Y'), ('99', '%y'), ('22', '%H'),
('44', '%M'), ('55', '%S'), ('76', '%j'),
('17', '%d'), ('03', '%m'), ('3', '%m'),
# '3' needed for when no leading zero.
('2', '%w'), ('10', '%I'),
]
date_time = []
for directive in ('%c', '%x', '%X', '%r'):
current_format = time.strftime(directive, time_tuple).lower()
current_format = current_format.replace('%', '%%')
# The month and the day of the week formats are treated specially
# because of a possible ambiguity in some locales where the full
# and abbreviated names are equal or names of different types
# are equal. See doc of __find_month_format for more details.
lst, fmt = self.__find_weekday_format(directive)
if lst:
current_format = current_format.replace(lst[2], fmt, 1)
lst, fmt = self.__find_month_format(directive)
if lst:
current_format = current_format.replace(lst[3], fmt, 1)
if self.am_pm[1]:
# Must deal with possible lack of locale info
# manifesting itself as the empty string (e.g., Swedish's
# lack of AM/PM info) or a platform returning a tuple of empty
# strings (e.g., MacOS 9 having timezone as ('','')).
current_format = current_format.replace(self.am_pm[1], '%p')
for tz_values in self.timezone:
for tz in tz_values:
if tz:
current_format = current_format.replace(tz, "%Z")
# Transform all non-ASCII digits to digits in range U+0660 to U+0669.
if not current_format.isascii() and self.LC_alt_digits is None:
current_format = re_sub(r'\d(?<![0-9])',
lambda m: chr(0x0660 + int(m[0])),
current_format)
for old, new in replacement_pairs:
current_format = current_format.replace(old, new)
# If %W is used, then Sunday, 2005-01-03 will fall on week 0 since
# 2005-01-03 occurs before the first Monday of the year. Otherwise
# %U is used.
if '00' in time.strftime(directive, time_tuple2):
U_W = '%W'
else:
U_W = '%U'
current_format = current_format.replace('11', U_W)
date_time.append(current_format)
self.LC_date_time = date_time[0]
self.LC_date = date_time[1]
self.LC_time = date_time[2]
self.LC_time_ampm = date_time[3]
def __find_month_format(self, directive):
"""Find the month format appropriate for the current locale.
In some locales (for example French and Hebrew), the default month
used in __calc_date_time has the same name in full and abbreviated
form. Also, the month name can by accident match other part of the
representation: the day of the week name (for example in Morisyen)
or the month number (for example in Japanese). Thus, cycle months
of the year and find all positions that match the month name for
each month, If no common positions are found, the representation
does not use the month name.
"""
full_indices = abbr_indices = None
for m in range(1, 13):
time_tuple = time.struct_time((1999, m, 17, 22, 44, 55, 2, 76, 0))
datetime = time.strftime(directive, time_tuple).lower()
indices = set(_findall(datetime, self.f_month[m]))
if full_indices is None:
full_indices = indices
else:
full_indices &= indices
indices = set(_findall(datetime, self.a_month[m]))
if abbr_indices is None:
abbr_indices = set(indices)
else:
abbr_indices &= indices
if not full_indices and not abbr_indices:
return None, None
if full_indices:
return self.f_month, '%B'
if abbr_indices:
return self.a_month, '%b'
return None, None
def __find_weekday_format(self, directive):
"""Find the day of the week format appropriate for the current locale.
Similar to __find_month_format().
"""
full_indices = abbr_indices = None
for wd in range(7):
time_tuple = time.struct_time((1999, 3, 17, 22, 44, 55, wd, 76, 0))
datetime = time.strftime(directive, time_tuple).lower()
indices = set(_findall(datetime, self.f_weekday[wd]))
if full_indices is None:
full_indices = indices
else:
full_indices &= indices
if self.f_weekday[wd] != self.a_weekday[wd]:
indices = set(_findall(datetime, self.a_weekday[wd]))
if abbr_indices is None:
abbr_indices = set(indices)
else:
abbr_indices &= indices
if not full_indices and not abbr_indices:
return None, None
if full_indices:
return self.f_weekday, '%A'
if abbr_indices:
return self.a_weekday, '%a'
return None, None
def __calc_timezone(self):
# Set self.timezone by using time.tzname.
# Do not worry about possibility of time.tzname[0] == time.tzname[1]
# and time.daylight; handle that in strptime.
try:
time.tzset()
except AttributeError:
pass
self.tzname = time.tzname
self.daylight = time.daylight
no_saving = frozenset({"utc", "gmt", self.tzname[0].lower()})
if self.daylight:
has_saving = frozenset({self.tzname[1].lower()})
else:
has_saving = frozenset()
self.timezone = (no_saving, has_saving)
class TimeRE(dict):
"""Handle conversion from format directives to regexes."""
def __init__(self, locale_time=None):
"""Create keys/values.
Order of execution is important for dependency reasons.
"""
if locale_time:
self.locale_time = locale_time
else:
self.locale_time = LocaleTime()
base = super()
mapping = {
# The " [1-9]" part of the regex is to make %c from ANSI C work
'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",
'f': r"(?P<f>[0-9]{1,6})",
'H': r"(?P<H>2[0-3]|[0-1]\d|\d| \d)",
'k': r"(?P<H>2[0-3]|[0-1]\d|\d| \d)",
'I': r"(?P<I>1[0-2]|0[1-9]|[1-9]| [1-9])",
'l': r"(?P<I>1[0-2]|0[1-9]|[1-9]| [1-9])",
'G': r"(?P<G>\d\d\d\d)",
'j': r"(?P<j>36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]|[1-9]\d|0[1-9]|[1-9])",
'm': r"(?P<m>1[0-2]|0[1-9]|[1-9])",
'M': r"(?P<M>[0-5]\d|\d)",
'S': r"(?P<S>6[0-1]|[0-5]\d|\d)",
'U': r"(?P<U>5[0-3]|[0-4]\d|\d)",
'w': r"(?P<w>[0-6])",
'u': r"(?P<u>[1-7])",
'V': r"(?P<V>5[0-3]|0[1-9]|[1-4]\d|\d)",
# W is set below by using 'U'
'y': r"(?P<y>\d\d)",
'Y': r"(?P<Y>\d\d\d\d)",
'z': r"(?P<z>[+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?|(?-i:Z))",
'A': self.__seqToRE(self.locale_time.f_weekday, 'A'),
'a': self.__seqToRE(self.locale_time.a_weekday, 'a'),
'B': self.__seqToRE(_fixmonths(self.locale_time.f_month[1:]), 'B'),
'b': self.__seqToRE(_fixmonths(self.locale_time.a_month[1:]), 'b'),
'p': self.__seqToRE(self.locale_time.am_pm, 'p'),
'Z': self.__seqToRE((tz for tz_names in self.locale_time.timezone
for tz in tz_names),
'Z'),
'%': '%'}
if self.locale_time.LC_alt_digits is None:
for d in 'dmyCHIMS':
mapping['O' + d] = r'(?P<%s>\d\d|\d| \d)' % d
mapping['Ow'] = r'(?P<w>\d)'
else:
mapping.update({
'Od': self.__seqToRE(self.locale_time.LC_alt_digits[1:32], 'd',
'3[0-1]|[1-2][0-9]|0[1-9]|[1-9]'),
'Om': self.__seqToRE(self.locale_time.LC_alt_digits[1:13], 'm',
'1[0-2]|0[1-9]|[1-9]'),
'Ow': self.__seqToRE(self.locale_time.LC_alt_digits[:7], 'w',
'[0-6]'),
'Oy': self.__seqToRE(self.locale_time.LC_alt_digits, 'y',
'[0-9][0-9]'),
'OC': self.__seqToRE(self.locale_time.LC_alt_digits, 'C',
'[0-9][0-9]'),
'OH': self.__seqToRE(self.locale_time.LC_alt_digits[:24], 'H',
'2[0-3]|[0-1][0-9]|[0-9]'),
'OI': self.__seqToRE(self.locale_time.LC_alt_digits[1:13], 'I',
'1[0-2]|0[1-9]|[1-9]'),
'OM': self.__seqToRE(self.locale_time.LC_alt_digits[:60], 'M',
'[0-5][0-9]|[0-9]'),
'OS': self.__seqToRE(self.locale_time.LC_alt_digits[:62], 'S',
'6[0-1]|[0-5][0-9]|[0-9]'),
})
mapping.update({
'e': mapping['d'],
'Oe': mapping['Od'],
'P': mapping['p'],
'Op': mapping['p'],
'W': mapping['U'].replace('U', 'W'),
})
mapping['W'] = mapping['U'].replace('U', 'W')
base.__init__(mapping)
base.__setitem__('T', self.pattern('%H:%M:%S'))
base.__setitem__('R', self.pattern('%H:%M'))
base.__setitem__('r', self.pattern(self.locale_time.LC_time_ampm))
base.__setitem__('X', self.pattern(self.locale_time.LC_time))
base.__setitem__('x', self.pattern(self.locale_time.LC_date))
base.__setitem__('c', self.pattern(self.locale_time.LC_date_time))
def __seqToRE(self, to_convert, directive, altregex=None):
"""Convert a list to a regex string for matching a directive.
Want possible matching values to be from longest to shortest. This
prevents the possibility of a match occurring for a value that also
a substring of a larger value that should have matched (e.g., 'abc'
matching when 'abcdef' should have been the match).
"""
to_convert = sorted(to_convert, key=len, reverse=True)
for value in to_convert:
if value != '':
break
else:
return ''
regex = '|'.join(re_escape(stuff) for stuff in to_convert)
if altregex is not None:
regex += '|' + altregex
return '(?P<%s>%s)' % (directive, regex)
def pattern(self, format):
"""Return regex pattern for the format string.
Need to make sure that any characters that might be interpreted as
regex syntax are escaped.
"""
# The sub() call escapes all characters that might be misconstrued
# as regex syntax. Cannot use re.escape since we have to deal with
# format directives (%m, etc.).
format = re_sub(r"([\\.^$*+?\(\){}\[\]|])", r"\\\1", format)
format = re_sub(r'\s+', r'\\s+', format)
format = re_sub(r"'", "['\u02bc]", format) # needed for br_FR
year_in_format = False
day_of_month_in_format = False
def repl(m):
format_char = m[1]
match format_char:
case 'Y' | 'y' | 'G':
nonlocal year_in_format
year_in_format = True
case 'd':
nonlocal day_of_month_in_format
day_of_month_in_format = True
return self[format_char]
format = re_sub(r'%[-_0^#]*[0-9]*([OE]?\\?.?)', repl, format)
if day_of_month_in_format and not year_in_format:
import warnings
warnings.warn("""\
Parsing dates involving a day of month without a year specified is ambiguous
and fails to parse leap day. The default behavior will change in Python 3.15
to either always raise an exception or to use a different default year (TBD).
To avoid trouble, add a specific year to the input & format.
See https://github.com/python/cpython/issues/70647.""",
DeprecationWarning,
skip_file_prefixes=(os.path.dirname(__file__),))
return format
def compile(self, format):
"""Return a compiled re object for the format string."""
return re_compile(self.pattern(format), IGNORECASE)
_cache_lock = _thread_allocate_lock()
# DO NOT modify _TimeRE_cache or _regex_cache without acquiring the cache lock
# first!
_TimeRE_cache = TimeRE()
_CACHE_MAX_SIZE = 5 # Max number of regexes stored in _regex_cache
_regex_cache = {}
def _calc_julian_from_U_or_W(year, week_of_year, day_of_week, week_starts_Mon):
"""Calculate the Julian day based on the year, week of the year, and day of
the week, with week_start_day representing whether the week of the year
assumes the week starts on Sunday or Monday (6 or 0)."""
first_weekday = datetime_date(year, 1, 1).weekday()
# If we are dealing with the %U directive (week starts on Sunday), it's
# easier to just shift the view to Sunday being the first day of the
# week.
if not week_starts_Mon:
first_weekday = (first_weekday + 1) % 7
day_of_week = (day_of_week + 1) % 7
# Need to watch out for a week 0 (when the first day of the year is not
# the same as that specified by %U or %W).
week_0_length = (7 - first_weekday) % 7
if week_of_year == 0:
return 1 + day_of_week - first_weekday
else:
days_to_week = week_0_length + (7 * (week_of_year - 1))
return 1 + days_to_week + day_of_week
def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a 2-tuple consisting of a time struct and an int containing
the number of microseconds based on the input string and the
format string."""
for index, arg in enumerate([data_string, format]):
if not isinstance(arg, str):
msg = "strptime() argument {} must be str, not {}"
raise TypeError(msg.format(index, type(arg)))
global _TimeRE_cache, _regex_cache
with _cache_lock:
locale_time = _TimeRE_cache.locale_time
if (_getlang() != locale_time.lang or
time.tzname != locale_time.tzname or
time.daylight != locale_time.daylight):
_TimeRE_cache = TimeRE()
_regex_cache.clear()
locale_time = _TimeRE_cache.locale_time
if len(_regex_cache) > _CACHE_MAX_SIZE:
_regex_cache.clear()
format_regex = _regex_cache.get(format)
if not format_regex:
try:
format_regex = _TimeRE_cache.compile(format)
# KeyError raised when a bad format is found; can be specified as
# \\, in which case it was a stray % but with a space after it
except KeyError as err:
bad_directive = err.args[0]
del err
bad_directive = bad_directive.replace('\\s', '')
if not bad_directive:
raise ValueError("stray %% in format '%s'" % format) from None
bad_directive = bad_directive.replace('\\', '', 1)
raise ValueError("'%s' is a bad directive in format '%s'" %
(bad_directive, format)) from None
_regex_cache[format] = format_regex
found = format_regex.match(data_string)
if not found:
raise ValueError("time data %r does not match format %r" %
(data_string, format))
if len(data_string) != found.end():
raise ValueError("unconverted data remains: %s" %
data_string[found.end():])
iso_year = year = None
month = day = 1
hour = minute = second = fraction = 0
tz = -1
gmtoff = None
gmtoff_fraction = 0
iso_week = week_of_year = None
week_of_year_start = None
# weekday and julian defaulted to None so as to signal need to calculate
# values
weekday = julian = None
found_dict = found.groupdict()
if locale_time.LC_alt_digits:
def parse_int(s):
try:
return locale_time.LC_alt_digits.index(s)
except ValueError:
return int(s)
else:
parse_int = int
for group_key in found_dict.keys():
# Directives not explicitly handled below:
# c, x, X
# handled by making out of other directives
# U, W
# worthless without day of the week
if group_key == 'y':
year = parse_int(found_dict['y'])
if 'C' in found_dict:
century = parse_int(found_dict['C'])
year += century * 100
else:
# Open Group specification for strptime() states that a %y
#value in the range of [00, 68] is in the century 2000, while
#[69,99] is in the century 1900
if year <= 68:
year += 2000
else:
year += 1900
elif group_key == 'Y':
year = int(found_dict['Y'])
elif group_key == 'G':
iso_year = int(found_dict['G'])
elif group_key == 'm':
month = parse_int(found_dict['m'])
elif group_key == 'B':
month = locale_time.f_month.index(found_dict['B'].lower())
elif group_key == 'b':
month = locale_time.a_month.index(found_dict['b'].lower())
elif group_key == 'd':
day = parse_int(found_dict['d'])
elif group_key == 'H':
hour = parse_int(found_dict['H'])
elif group_key == 'I':
hour = parse_int(found_dict['I'])
ampm = found_dict.get('p', '').lower()
# If there was no AM/PM indicator, we'll treat this like AM
if ampm in ('', locale_time.am_pm[0]):
# We're in AM so the hour is correct unless we're
# looking at 12 midnight.
# 12 midnight == 12 AM == hour 0
if hour == 12:
hour = 0
elif ampm == locale_time.am_pm[1]:
# We're in PM so we need to add 12 to the hour unless
# we're looking at 12 noon.
# 12 noon == 12 PM == hour 12
if hour != 12:
hour += 12
elif group_key == 'M':
minute = parse_int(found_dict['M'])
elif group_key == 'S':
second = parse_int(found_dict['S'])
elif group_key == 'f':
s = found_dict['f']
# Pad to always return microseconds.
s += "0" * (6 - len(s))
fraction = int(s)
elif group_key == 'A':
weekday = locale_time.f_weekday.index(found_dict['A'].lower())
elif group_key == 'a':
weekday = locale_time.a_weekday.index(found_dict['a'].lower())
elif group_key == 'w':
weekday = int(found_dict['w'])
if weekday == 0:
weekday = 6
else:
weekday -= 1
elif group_key == 'u':
weekday = int(found_dict['u'])
weekday -= 1
elif group_key == 'j':
julian = int(found_dict['j'])
elif group_key in ('U', 'W'):
week_of_year = int(found_dict[group_key])
if group_key == 'U':
# U starts week on Sunday.
week_of_year_start = 6
else:
# W starts week on Monday.
week_of_year_start = 0
elif group_key == 'V':
iso_week = int(found_dict['V'])
elif group_key == 'z':
z = found_dict['z']
if z == 'Z':
gmtoff = 0
else:
if z[3] == ':':
z = z[:3] + z[4:]
if len(z) > 5:
if z[5] != ':':
msg = f"Inconsistent use of : in {found_dict['z']}"
raise ValueError(msg)
z = z[:5] + z[6:]
hours = int(z[1:3])
minutes = int(z[3:5])
seconds = int(z[5:7] or 0)
gmtoff = (hours * 60 * 60) + (minutes * 60) + seconds
gmtoff_remainder = z[8:]
# Pad to always return microseconds.
gmtoff_remainder_padding = "0" * (6 - len(gmtoff_remainder))
gmtoff_fraction = int(gmtoff_remainder + gmtoff_remainder_padding)
if z.startswith("-"):
gmtoff = -gmtoff
gmtoff_fraction = -gmtoff_fraction
elif group_key == 'Z':
# Since -1 is default value only need to worry about setting tz if
# it can be something other than -1.
found_zone = found_dict['Z'].lower()
for value, tz_values in enumerate(locale_time.timezone):
if found_zone in tz_values:
# Deal with bad locale setup where timezone names are the
# same and yet time.daylight is true; too ambiguous to
# be able to tell what timezone has daylight savings
if (time.tzname[0] == time.tzname[1] and
time.daylight and found_zone not in ("utc", "gmt")):
break
else:
tz = value
break
# Deal with the cases where ambiguities arise
# don't assume default values for ISO week/year
if iso_year is not None:
if julian is not None:
raise ValueError("Day of the year directive '%j' is not "
"compatible with ISO year directive '%G'. "
"Use '%Y' instead.")
elif iso_week is None or weekday is None:
raise ValueError("ISO year directive '%G' must be used with "
"the ISO week directive '%V' and a weekday "
"directive ('%A', '%a', '%w', or '%u').")
elif iso_week is not None:
if year is None or weekday is None:
raise ValueError("ISO week directive '%V' must be used with "
"the ISO year directive '%G' and a weekday "
"directive ('%A', '%a', '%w', or '%u').")
else:
raise ValueError("ISO week directive '%V' is incompatible with "
"the year directive '%Y'. Use the ISO year '%G' "
"instead.")
leap_year_fix = False
if year is None:
if month == 2 and day == 29:
year = 1904 # 1904 is first leap year of 20th century
leap_year_fix = True
else:
year = 1900
# If we know the week of the year and what day of that week, we can figure
# out the Julian day of the year.
if julian is None and weekday is not None:
if week_of_year is not None:
week_starts_Mon = True if week_of_year_start == 0 else False
julian = _calc_julian_from_U_or_W(year, week_of_year, weekday,
week_starts_Mon)
elif iso_year is not None and iso_week is not None:
datetime_result = datetime_date.fromisocalendar(iso_year, iso_week, weekday + 1)
year = datetime_result.year
month = datetime_result.month
day = datetime_result.day
if julian is not None and julian <= 0:
year -= 1
yday = 366 if calendar.isleap(year) else 365
julian += yday
if julian is None:
# Cannot pre-calculate datetime_date() since can change in Julian
# calculation and thus could have different value for the day of
# the week calculation.
# Need to add 1 to result since first day of the year is 1, not 0.
julian = datetime_date(year, month, day).toordinal() - \
datetime_date(year, 1, 1).toordinal() + 1
else: # Assume that if they bothered to include Julian day (or if it was
# calculated above with year/week/weekday) it will be accurate.
datetime_result = datetime_date.fromordinal(
(julian - 1) +
datetime_date(year, 1, 1).toordinal())
year = datetime_result.year
month = datetime_result.month
day = datetime_result.day
if weekday is None:
weekday = datetime_date(year, month, day).weekday()
# Add timezone info
tzname = found_dict.get("Z")
if leap_year_fix:
# the caller didn't supply a year but asked for Feb 29th. We couldn't
# use the default of 1900 for computations. We set it back to ensure
# that February 29th is smaller than March 1st.
year = 1900
return (year, month, day,
hour, minute, second,
weekday, julian, tz, tzname, gmtoff), fraction, gmtoff_fraction
def _strptime_time(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a time struct based on the input string and the
format string."""
tt = _strptime(data_string, format)[0]
return time.struct_time(tt[:time._STRUCT_TM_ITEMS])
def _strptime_datetime_date(cls, data_string, format="%a %b %d %Y"):
"""Return a date instance based on the input string and the
format string."""
tt, _, _ = _strptime(data_string, format)
args = tt[:3]
return cls(*args)
def _parse_tz(tzname, gmtoff, gmtoff_fraction):
tzdelta = datetime_timedelta(seconds=gmtoff, microseconds=gmtoff_fraction)
if tzname:
return datetime_timezone(tzdelta, tzname)
else:
return datetime_timezone(tzdelta)
def _strptime_datetime_time(cls, data_string, format="%H:%M:%S"):
"""Return a time instance based on the input string and the
format string."""
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
tzname, gmtoff = tt[-2:]
args = tt[3:6] + (fraction,)
if gmtoff is None:
return cls(*args)
else:
tz = _parse_tz(tzname, gmtoff, gmtoff_fraction)
return cls(*args, tz)
def _strptime_datetime_datetime(cls, data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a datetime instance based on the input string and the
format string."""
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
tzname, gmtoff = tt[-2:]
args = tt[:6] + (fraction,)
if gmtoff is None:
return cls(*args)
else:
tz = _parse_tz(tzname, gmtoff, gmtoff_fraction)
return cls(*args, tz)

View File

@@ -4,133 +4,6 @@
class. Depending on the version of Python you're using, there may be a
faster one available. You should always import the `local` class from
`threading`.)
Thread-local objects support the management of thread-local data.
If you have data that you want to be local to a thread, simply create
a thread-local object and use its attributes:
>>> mydata = local()
>>> mydata.number = 42
>>> mydata.number
42
You can also access the local-object's dictionary:
>>> mydata.__dict__
{'number': 42}
>>> mydata.__dict__.setdefault('widgets', [])
[]
>>> mydata.widgets
[]
What's important about thread-local objects is that their data are
local to a thread. If we access the data in a different thread:
>>> log = []
>>> def f():
... items = sorted(mydata.__dict__.items())
... log.append(items)
... mydata.number = 11
... log.append(mydata.number)
>>> import threading
>>> thread = threading.Thread(target=f)
>>> thread.start()
>>> thread.join()
>>> log
[[], 11]
we get different data. Furthermore, changes made in the other thread
don't affect data seen in this thread:
>>> mydata.number
42
Of course, values you get from a local object, including a __dict__
attribute, are for whatever thread was current at the time the
attribute was read. For that reason, you generally don't want to save
these values across threads, as they apply only to the thread they
came from.
You can create custom local objects by subclassing the local class:
>>> class MyLocal(local):
... number = 2
... initialized = False
... def __init__(self, **kw):
... if self.initialized:
... raise SystemError('__init__ called too many times')
... self.initialized = True
... self.__dict__.update(kw)
... def squared(self):
... return self.number ** 2
This can be useful to support default values, methods and
initialization. Note that if you define an __init__ method, it will be
called each time the local object is used in a separate thread. This
is necessary to initialize each thread's dictionary.
Now if we create a local object:
>>> mydata = MyLocal(color='red')
Now we have a default number:
>>> mydata.number
2
an initial color:
>>> mydata.color
'red'
>>> del mydata.color
And a method that operates on the data:
>>> mydata.squared()
4
As before, we can access the data in a separate thread:
>>> log = []
>>> thread = threading.Thread(target=f)
>>> thread.start()
>>> thread.join()
>>> log
[[('color', 'red'), ('initialized', True)], 11]
without affecting this thread's data:
>>> mydata.number
2
>>> mydata.color
Traceback (most recent call last):
...
AttributeError: 'MyLocal' object has no attribute 'color'
Note that subclasses can define slots, but they are not thread
local. They are shared across threads:
>>> class MyLocal(local):
... __slots__ = 'number'
>>> mydata = MyLocal()
>>> mydata.number = 42
>>> mydata.color = 'red'
So, the separate thread:
>>> thread = threading.Thread(target=f)
>>> thread.start()
>>> thread.join()
affects what we see:
>>> # TODO: RUSTPYTHON, __slots__
>>> mydata.number #doctest: +SKIP
11
>>> del mydata
"""
from weakref import ref
@@ -194,7 +67,6 @@ class _localimpl:
@contextmanager
def _patch(self):
old = object.__getattribute__(self, '__dict__')
impl = object.__getattribute__(self, '_local__impl')
try:
dct = impl.get_dict()
@@ -205,13 +77,12 @@ def _patch(self):
with impl.locallock:
object.__setattr__(self, '__dict__', dct)
yield
object.__setattr__(self, '__dict__', old)
class local:
__slots__ = '_local__impl', '__dict__'
def __new__(cls, *args, **kw):
def __new__(cls, /, *args, **kw):
if (args or kw) and (cls.__init__ is object.__init__):
raise TypeError("Initialization arguments are not supported")
self = object.__new__(cls)

81
Lib/_weakrefset.py vendored
View File

@@ -8,69 +8,29 @@ from types import GenericAlias
__all__ = ['WeakSet']
class _IterationGuard:
# This context manager registers itself in the current iterators of the
# weak container, such as to delay all removals until the context manager
# exits.
# This technique should be relatively thread-safe (since sets are).
def __init__(self, weakcontainer):
# Don't create cycles
self.weakcontainer = ref(weakcontainer)
def __enter__(self):
w = self.weakcontainer()
if w is not None:
w._iterating.add(self)
return self
def __exit__(self, e, t, b):
w = self.weakcontainer()
if w is not None:
s = w._iterating
s.remove(self)
if not s:
w._commit_removals()
class WeakSet:
def __init__(self, data=None):
self.data = set()
def _remove(item, selfref=ref(self)):
self = selfref()
if self is not None:
if self._iterating:
self._pending_removals.append(item)
else:
self.data.discard(item)
self.data.discard(item)
self._remove = _remove
# A list of keys to be removed
self._pending_removals = []
self._iterating = set()
if data is not None:
self.update(data)
def _commit_removals(self):
pop = self._pending_removals.pop
discard = self.data.discard
while True:
try:
item = pop()
except IndexError:
return
discard(item)
def __iter__(self):
with _IterationGuard(self):
for itemref in self.data:
item = itemref()
if item is not None:
# Caveat: the iterator will keep a strong reference to
# `item` until it is resumed or closed.
yield item
for itemref in self.data.copy():
item = itemref()
if item is not None:
# Caveat: the iterator will keep a strong reference to
# `item` until it is resumed or closed.
yield item
def __len__(self):
return len(self.data) - len(self._pending_removals)
return len(self.data)
def __contains__(self, item):
try:
@@ -80,25 +40,18 @@ class WeakSet:
return wr in self.data
def __reduce__(self):
return (self.__class__, (list(self),),
getattr(self, '__dict__', None))
return self.__class__, (list(self),), self.__getstate__()
def add(self, item):
if self._pending_removals:
self._commit_removals()
self.data.add(ref(item, self._remove))
def clear(self):
if self._pending_removals:
self._commit_removals()
self.data.clear()
def copy(self):
return self.__class__(self)
def pop(self):
if self._pending_removals:
self._commit_removals()
while True:
try:
itemref = self.data.pop()
@@ -109,18 +62,12 @@ class WeakSet:
return item
def remove(self, item):
if self._pending_removals:
self._commit_removals()
self.data.remove(ref(item))
def discard(self, item):
if self._pending_removals:
self._commit_removals()
self.data.discard(ref(item))
def update(self, other):
if self._pending_removals:
self._commit_removals()
for element in other:
self.add(element)
@@ -137,8 +84,6 @@ class WeakSet:
def difference_update(self, other):
self.__isub__(other)
def __isub__(self, other):
if self._pending_removals:
self._commit_removals()
if self is other:
self.data.clear()
else:
@@ -152,8 +97,6 @@ class WeakSet:
def intersection_update(self, other):
self.__iand__(other)
def __iand__(self, other):
if self._pending_removals:
self._commit_removals()
self.data.intersection_update(ref(item) for item in other)
return self
@@ -185,8 +128,6 @@ class WeakSet:
def symmetric_difference_update(self, other):
self.__ixor__(other)
def __ixor__(self, other):
if self._pending_removals:
self._commit_removals()
if self is other:
self.data.clear()
else:

4
Lib/abc.py vendored
View File

@@ -85,10 +85,6 @@ try:
from _abc import (get_cache_token, _abc_init, _abc_register,
_abc_instancecheck, _abc_subclasscheck, _get_dump,
_reset_registry, _reset_caches)
# TODO: RUSTPYTHON missing _abc module implementation.
except ModuleNotFoundError:
from _py_abc import ABCMeta, get_cache_token
ABCMeta.__module__ = 'abc'
except ImportError:
from _py_abc import ABCMeta, get_cache_token
ABCMeta.__module__ = 'abc'

984
Lib/aifc.py vendored
View File

@@ -1,984 +0,0 @@
"""Stuff to parse AIFF-C and AIFF files.
Unless explicitly stated otherwise, the description below is true
both for AIFF-C files and AIFF files.
An AIFF-C file has the following structure.
+-----------------+
| FORM |
+-----------------+
| <size> |
+----+------------+
| | AIFC |
| +------------+
| | <chunks> |
| | . |
| | . |
| | . |
+----+------------+
An AIFF file has the string "AIFF" instead of "AIFC".
A chunk consists of an identifier (4 bytes) followed by a size (4 bytes,
big endian order), followed by the data. The size field does not include
the size of the 8 byte header.
The following chunk types are recognized.
FVER
<version number of AIFF-C defining document> (AIFF-C only).
MARK
<# of markers> (2 bytes)
list of markers:
<marker ID> (2 bytes, must be > 0)
<position> (4 bytes)
<marker name> ("pstring")
COMM
<# of channels> (2 bytes)
<# of sound frames> (4 bytes)
<size of the samples> (2 bytes)
<sampling frequency> (10 bytes, IEEE 80-bit extended
floating point)
in AIFF-C files only:
<compression type> (4 bytes)
<human-readable version of compression type> ("pstring")
SSND
<offset> (4 bytes, not used by this program)
<blocksize> (4 bytes, not used by this program)
<sound data>
A pstring consists of 1 byte length, a string of characters, and 0 or 1
byte pad to make the total length even.
Usage.
Reading AIFF files:
f = aifc.open(file, 'r')
where file is either the name of a file or an open file pointer.
The open file pointer must have methods read(), seek(), and close().
In some types of audio files, if the setpos() method is not used,
the seek() method is not necessary.
This returns an instance of a class with the following public methods:
getnchannels() -- returns number of audio channels (1 for
mono, 2 for stereo)
getsampwidth() -- returns sample width in bytes
getframerate() -- returns sampling frequency
getnframes() -- returns number of audio frames
getcomptype() -- returns compression type ('NONE' for AIFF files)
getcompname() -- returns human-readable version of
compression type ('not compressed' for AIFF files)
getparams() -- returns a namedtuple consisting of all of the
above in the above order
getmarkers() -- get the list of marks in the audio file or None
if there are no marks
getmark(id) -- get mark with the specified id (raises an error
if the mark does not exist)
readframes(n) -- returns at most n frames of audio
rewind() -- rewind to the beginning of the audio stream
setpos(pos) -- seek to the specified position
tell() -- return the current position
close() -- close the instance (make it unusable)
The position returned by tell(), the position given to setpos() and
the position of marks are all compatible and have nothing to do with
the actual position in the file.
The close() method is called automatically when the class instance
is destroyed.
Writing AIFF files:
f = aifc.open(file, 'w')
where file is either the name of a file or an open file pointer.
The open file pointer must have methods write(), tell(), seek(), and
close().
This returns an instance of a class with the following public methods:
aiff() -- create an AIFF file (AIFF-C default)
aifc() -- create an AIFF-C file
setnchannels(n) -- set the number of channels
setsampwidth(n) -- set the sample width
setframerate(n) -- set the frame rate
setnframes(n) -- set the number of frames
setcomptype(type, name)
-- set the compression type and the
human-readable compression type
setparams(tuple)
-- set all parameters at once
setmark(id, pos, name)
-- add specified mark to the list of marks
tell() -- return current position in output file (useful
in combination with setmark())
writeframesraw(data)
-- write audio frames without pathing up the
file header
writeframes(data)
-- write audio frames and patch up the file header
close() -- patch up the file header and close the
output file
You should set the parameters before the first writeframesraw or
writeframes. The total number of frames does not need to be set,
but when it is set to the correct value, the header does not have to
be patched up.
It is best to first set all parameters, perhaps possibly the
compression type, and then write audio frames using writeframesraw.
When all frames have been written, either call writeframes(b'') or
close() to patch up the sizes in the header.
Marks can be added anytime. If there are any marks, you must call
close() after all frames have been written.
The close() method is called automatically when the class instance
is destroyed.
When a file is opened with the extension '.aiff', an AIFF file is
written, otherwise an AIFF-C file is written. This default can be
changed by calling aiff() or aifc() before the first writeframes or
writeframesraw.
"""
import struct
import builtins
import warnings
__all__ = ["Error", "open"]
warnings._deprecated(__name__, remove=(3, 13))
class Error(Exception):
pass
_AIFC_version = 0xA2805140 # Version 1 of AIFF-C
def _read_long(file):
try:
return struct.unpack('>l', file.read(4))[0]
except struct.error:
raise EOFError from None
def _read_ulong(file):
try:
return struct.unpack('>L', file.read(4))[0]
except struct.error:
raise EOFError from None
def _read_short(file):
try:
return struct.unpack('>h', file.read(2))[0]
except struct.error:
raise EOFError from None
def _read_ushort(file):
try:
return struct.unpack('>H', file.read(2))[0]
except struct.error:
raise EOFError from None
def _read_string(file):
length = ord(file.read(1))
if length == 0:
data = b''
else:
data = file.read(length)
if length & 1 == 0:
dummy = file.read(1)
return data
_HUGE_VAL = 1.79769313486231e+308 # See <limits.h>
def _read_float(f): # 10 bytes
expon = _read_short(f) # 2 bytes
sign = 1
if expon < 0:
sign = -1
expon = expon + 0x8000
himant = _read_ulong(f) # 4 bytes
lomant = _read_ulong(f) # 4 bytes
if expon == himant == lomant == 0:
f = 0.0
elif expon == 0x7FFF:
f = _HUGE_VAL
else:
expon = expon - 16383
f = (himant * 0x100000000 + lomant) * pow(2.0, expon - 63)
return sign * f
def _write_short(f, x):
f.write(struct.pack('>h', x))
def _write_ushort(f, x):
f.write(struct.pack('>H', x))
def _write_long(f, x):
f.write(struct.pack('>l', x))
def _write_ulong(f, x):
f.write(struct.pack('>L', x))
def _write_string(f, s):
if len(s) > 255:
raise ValueError("string exceeds maximum pstring length")
f.write(struct.pack('B', len(s)))
f.write(s)
if len(s) & 1 == 0:
f.write(b'\x00')
def _write_float(f, x):
import math
if x < 0:
sign = 0x8000
x = x * -1
else:
sign = 0
if x == 0:
expon = 0
himant = 0
lomant = 0
else:
fmant, expon = math.frexp(x)
if expon > 16384 or fmant >= 1 or fmant != fmant: # Infinity or NaN
expon = sign|0x7FFF
himant = 0
lomant = 0
else: # Finite
expon = expon + 16382
if expon < 0: # denormalized
fmant = math.ldexp(fmant, expon)
expon = 0
expon = expon | sign
fmant = math.ldexp(fmant, 32)
fsmant = math.floor(fmant)
himant = int(fsmant)
fmant = math.ldexp(fmant - fsmant, 32)
fsmant = math.floor(fmant)
lomant = int(fsmant)
_write_ushort(f, expon)
_write_ulong(f, himant)
_write_ulong(f, lomant)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
from chunk import Chunk
from collections import namedtuple
_aifc_params = namedtuple('_aifc_params',
'nchannels sampwidth framerate nframes comptype compname')
_aifc_params.nchannels.__doc__ = 'Number of audio channels (1 for mono, 2 for stereo)'
_aifc_params.sampwidth.__doc__ = 'Sample width in bytes'
_aifc_params.framerate.__doc__ = 'Sampling frequency'
_aifc_params.nframes.__doc__ = 'Number of audio frames'
_aifc_params.comptype.__doc__ = 'Compression type ("NONE" for AIFF files)'
_aifc_params.compname.__doc__ = ("""\
A human-readable version of the compression type
('not compressed' for AIFF files)""")
class Aifc_read:
# Variables used in this class:
#
# These variables are available to the user though appropriate
# methods of this class:
# _file -- the open file with methods read(), close(), and seek()
# set through the __init__() method
# _nchannels -- the number of audio channels
# available through the getnchannels() method
# _nframes -- the number of audio frames
# available through the getnframes() method
# _sampwidth -- the number of bytes per audio sample
# available through the getsampwidth() method
# _framerate -- the sampling frequency
# available through the getframerate() method
# _comptype -- the AIFF-C compression type ('NONE' if AIFF)
# available through the getcomptype() method
# _compname -- the human-readable AIFF-C compression type
# available through the getcomptype() method
# _markers -- the marks in the audio file
# available through the getmarkers() and getmark()
# methods
# _soundpos -- the position in the audio stream
# available through the tell() method, set through the
# setpos() method
#
# These variables are used internally only:
# _version -- the AIFF-C version number
# _decomp -- the decompressor from builtin module cl
# _comm_chunk_read -- 1 iff the COMM chunk has been read
# _aifc -- 1 iff reading an AIFF-C file
# _ssnd_seek_needed -- 1 iff positioned correctly in audio
# file for readframes()
# _ssnd_chunk -- instantiation of a chunk class for the SSND chunk
# _framesize -- size of one frame in the file
_file = None # Set here since __del__ checks it
def initfp(self, file):
self._version = 0
self._convert = None
self._markers = []
self._soundpos = 0
self._file = file
chunk = Chunk(file)
if chunk.getname() != b'FORM':
raise Error('file does not start with FORM id')
formdata = chunk.read(4)
if formdata == b'AIFF':
self._aifc = 0
elif formdata == b'AIFC':
self._aifc = 1
else:
raise Error('not an AIFF or AIFF-C file')
self._comm_chunk_read = 0
self._ssnd_chunk = None
while 1:
self._ssnd_seek_needed = 1
try:
chunk = Chunk(self._file)
except EOFError:
break
chunkname = chunk.getname()
if chunkname == b'COMM':
self._read_comm_chunk(chunk)
self._comm_chunk_read = 1
elif chunkname == b'SSND':
self._ssnd_chunk = chunk
dummy = chunk.read(8)
self._ssnd_seek_needed = 0
elif chunkname == b'FVER':
self._version = _read_ulong(chunk)
elif chunkname == b'MARK':
self._readmark(chunk)
chunk.skip()
if not self._comm_chunk_read or not self._ssnd_chunk:
raise Error('COMM chunk and/or SSND chunk missing')
def __init__(self, f):
if isinstance(f, str):
file_object = builtins.open(f, 'rb')
try:
self.initfp(file_object)
except:
file_object.close()
raise
else:
# assume it is an open file object already
self.initfp(f)
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
#
# User visible methods.
#
def getfp(self):
return self._file
def rewind(self):
self._ssnd_seek_needed = 1
self._soundpos = 0
def close(self):
file = self._file
if file is not None:
self._file = None
file.close()
def tell(self):
return self._soundpos
def getnchannels(self):
return self._nchannels
def getnframes(self):
return self._nframes
def getsampwidth(self):
return self._sampwidth
def getframerate(self):
return self._framerate
def getcomptype(self):
return self._comptype
def getcompname(self):
return self._compname
## def getversion(self):
## return self._version
def getparams(self):
return _aifc_params(self.getnchannels(), self.getsampwidth(),
self.getframerate(), self.getnframes(),
self.getcomptype(), self.getcompname())
def getmarkers(self):
if len(self._markers) == 0:
return None
return self._markers
def getmark(self, id):
for marker in self._markers:
if id == marker[0]:
return marker
raise Error('marker {0!r} does not exist'.format(id))
def setpos(self, pos):
if pos < 0 or pos > self._nframes:
raise Error('position not in range')
self._soundpos = pos
self._ssnd_seek_needed = 1
def readframes(self, nframes):
if self._ssnd_seek_needed:
self._ssnd_chunk.seek(0)
dummy = self._ssnd_chunk.read(8)
pos = self._soundpos * self._framesize
if pos:
self._ssnd_chunk.seek(pos + 8)
self._ssnd_seek_needed = 0
if nframes == 0:
return b''
data = self._ssnd_chunk.read(nframes * self._framesize)
if self._convert and data:
data = self._convert(data)
self._soundpos = self._soundpos + len(data) // (self._nchannels
* self._sampwidth)
return data
#
# Internal methods.
#
def _alaw2lin(self, data):
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=DeprecationWarning)
import audioop
return audioop.alaw2lin(data, 2)
def _ulaw2lin(self, data):
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=DeprecationWarning)
import audioop
return audioop.ulaw2lin(data, 2)
def _adpcm2lin(self, data):
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=DeprecationWarning)
import audioop
if not hasattr(self, '_adpcmstate'):
# first time
self._adpcmstate = None
data, self._adpcmstate = audioop.adpcm2lin(data, 2, self._adpcmstate)
return data
def _sowt2lin(self, data):
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=DeprecationWarning)
import audioop
return audioop.byteswap(data, 2)
def _read_comm_chunk(self, chunk):
self._nchannels = _read_short(chunk)
self._nframes = _read_long(chunk)
self._sampwidth = (_read_short(chunk) + 7) // 8
self._framerate = int(_read_float(chunk))
if self._sampwidth <= 0:
raise Error('bad sample width')
if self._nchannels <= 0:
raise Error('bad # of channels')
self._framesize = self._nchannels * self._sampwidth
if self._aifc:
#DEBUG: SGI's soundeditor produces a bad size :-(
kludge = 0
if chunk.chunksize == 18:
kludge = 1
warnings.warn('Warning: bad COMM chunk size')
chunk.chunksize = 23
#DEBUG end
self._comptype = chunk.read(4)
#DEBUG start
if kludge:
length = ord(chunk.file.read(1))
if length & 1 == 0:
length = length + 1
chunk.chunksize = chunk.chunksize + length
chunk.file.seek(-1, 1)
#DEBUG end
self._compname = _read_string(chunk)
if self._comptype != b'NONE':
if self._comptype == b'G722':
self._convert = self._adpcm2lin
elif self._comptype in (b'ulaw', b'ULAW'):
self._convert = self._ulaw2lin
elif self._comptype in (b'alaw', b'ALAW'):
self._convert = self._alaw2lin
elif self._comptype in (b'sowt', b'SOWT'):
self._convert = self._sowt2lin
else:
raise Error('unsupported compression type')
self._sampwidth = 2
else:
self._comptype = b'NONE'
self._compname = b'not compressed'
def _readmark(self, chunk):
nmarkers = _read_short(chunk)
# Some files appear to contain invalid counts.
# Cope with this by testing for EOF.
try:
for i in range(nmarkers):
id = _read_short(chunk)
pos = _read_long(chunk)
name = _read_string(chunk)
if pos or name:
# some files appear to have
# dummy markers consisting of
# a position 0 and name ''
self._markers.append((id, pos, name))
except EOFError:
w = ('Warning: MARK chunk contains only %s marker%s instead of %s' %
(len(self._markers), '' if len(self._markers) == 1 else 's',
nmarkers))
warnings.warn(w)
class Aifc_write:
# Variables used in this class:
#
# These variables are user settable through appropriate methods
# of this class:
# _file -- the open file with methods write(), close(), tell(), seek()
# set through the __init__() method
# _comptype -- the AIFF-C compression type ('NONE' in AIFF)
# set through the setcomptype() or setparams() method
# _compname -- the human-readable AIFF-C compression type
# set through the setcomptype() or setparams() method
# _nchannels -- the number of audio channels
# set through the setnchannels() or setparams() method
# _sampwidth -- the number of bytes per audio sample
# set through the setsampwidth() or setparams() method
# _framerate -- the sampling frequency
# set through the setframerate() or setparams() method
# _nframes -- the number of audio frames written to the header
# set through the setnframes() or setparams() method
# _aifc -- whether we're writing an AIFF-C file or an AIFF file
# set through the aifc() method, reset through the
# aiff() method
#
# These variables are used internally only:
# _version -- the AIFF-C version number
# _comp -- the compressor from builtin module cl
# _nframeswritten -- the number of audio frames actually written
# _datalength -- the size of the audio samples written to the header
# _datawritten -- the size of the audio samples actually written
_file = None # Set here since __del__ checks it
def __init__(self, f):
if isinstance(f, str):
file_object = builtins.open(f, 'wb')
try:
self.initfp(file_object)
except:
file_object.close()
raise
# treat .aiff file extensions as non-compressed audio
if f.endswith('.aiff'):
self._aifc = 0
else:
# assume it is an open file object already
self.initfp(f)
def initfp(self, file):
self._file = file
self._version = _AIFC_version
self._comptype = b'NONE'
self._compname = b'not compressed'
self._convert = None
self._nchannels = 0
self._sampwidth = 0
self._framerate = 0
self._nframes = 0
self._nframeswritten = 0
self._datawritten = 0
self._datalength = 0
self._markers = []
self._marklength = 0
self._aifc = 1 # AIFF-C is default
def __del__(self):
self.close()
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
#
# User visible methods.
#
def aiff(self):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
self._aifc = 0
def aifc(self):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
self._aifc = 1
def setnchannels(self, nchannels):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
if nchannels < 1:
raise Error('bad # of channels')
self._nchannels = nchannels
def getnchannels(self):
if not self._nchannels:
raise Error('number of channels not set')
return self._nchannels
def setsampwidth(self, sampwidth):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
if sampwidth < 1 or sampwidth > 4:
raise Error('bad sample width')
self._sampwidth = sampwidth
def getsampwidth(self):
if not self._sampwidth:
raise Error('sample width not set')
return self._sampwidth
def setframerate(self, framerate):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
if framerate <= 0:
raise Error('bad frame rate')
self._framerate = framerate
def getframerate(self):
if not self._framerate:
raise Error('frame rate not set')
return self._framerate
def setnframes(self, nframes):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
self._nframes = nframes
def getnframes(self):
return self._nframeswritten
def setcomptype(self, comptype, compname):
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
if comptype not in (b'NONE', b'ulaw', b'ULAW',
b'alaw', b'ALAW', b'G722', b'sowt', b'SOWT'):
raise Error('unsupported compression type')
self._comptype = comptype
self._compname = compname
def getcomptype(self):
return self._comptype
def getcompname(self):
return self._compname
## def setversion(self, version):
## if self._nframeswritten:
## raise Error, 'cannot change parameters after starting to write'
## self._version = version
def setparams(self, params):
nchannels, sampwidth, framerate, nframes, comptype, compname = params
if self._nframeswritten:
raise Error('cannot change parameters after starting to write')
if comptype not in (b'NONE', b'ulaw', b'ULAW',
b'alaw', b'ALAW', b'G722', b'sowt', b'SOWT'):
raise Error('unsupported compression type')
self.setnchannels(nchannels)
self.setsampwidth(sampwidth)
self.setframerate(framerate)
self.setnframes(nframes)
self.setcomptype(comptype, compname)
def getparams(self):
if not self._nchannels or not self._sampwidth or not self._framerate:
raise Error('not all parameters set')
return _aifc_params(self._nchannels, self._sampwidth, self._framerate,
self._nframes, self._comptype, self._compname)
def setmark(self, id, pos, name):
if id <= 0:
raise Error('marker ID must be > 0')
if pos < 0:
raise Error('marker position must be >= 0')
if not isinstance(name, bytes):
raise Error('marker name must be bytes')
for i in range(len(self._markers)):
if id == self._markers[i][0]:
self._markers[i] = id, pos, name
return
self._markers.append((id, pos, name))
def getmark(self, id):
for marker in self._markers:
if id == marker[0]:
return marker
raise Error('marker {0!r} does not exist'.format(id))
def getmarkers(self):
if len(self._markers) == 0:
return None
return self._markers
def tell(self):
return self._nframeswritten
def writeframesraw(self, data):
if not isinstance(data, (bytes, bytearray)):
data = memoryview(data).cast('B')
self._ensure_header_written(len(data))
nframes = len(data) // (self._sampwidth * self._nchannels)
if self._convert:
data = self._convert(data)
self._file.write(data)
self._nframeswritten = self._nframeswritten + nframes
self._datawritten = self._datawritten + len(data)
def writeframes(self, data):
self.writeframesraw(data)
if self._nframeswritten != self._nframes or \
self._datalength != self._datawritten:
self._patchheader()
def close(self):
if self._file is None:
return
try:
self._ensure_header_written(0)
if self._datawritten & 1:
# quick pad to even size
self._file.write(b'\x00')
self._datawritten = self._datawritten + 1
self._writemarkers()
if self._nframeswritten != self._nframes or \
self._datalength != self._datawritten or \
self._marklength:
self._patchheader()
finally:
# Prevent ref cycles
self._convert = None
f = self._file
self._file = None
f.close()
#
# Internal methods.
#
def _lin2alaw(self, data):
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=DeprecationWarning)
import audioop
return audioop.lin2alaw(data, 2)
def _lin2ulaw(self, data):
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=DeprecationWarning)
import audioop
return audioop.lin2ulaw(data, 2)
def _lin2adpcm(self, data):
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=DeprecationWarning)
import audioop
if not hasattr(self, '_adpcmstate'):
self._adpcmstate = None
data, self._adpcmstate = audioop.lin2adpcm(data, 2, self._adpcmstate)
return data
def _lin2sowt(self, data):
with warnings.catch_warnings():
warnings.simplefilter('ignore', category=DeprecationWarning)
import audioop
return audioop.byteswap(data, 2)
def _ensure_header_written(self, datasize):
if not self._nframeswritten:
if self._comptype in (b'ULAW', b'ulaw',
b'ALAW', b'alaw', b'G722',
b'sowt', b'SOWT'):
if not self._sampwidth:
self._sampwidth = 2
if self._sampwidth != 2:
raise Error('sample width must be 2 when compressing '
'with ulaw/ULAW, alaw/ALAW, sowt/SOWT '
'or G7.22 (ADPCM)')
if not self._nchannels:
raise Error('# channels not specified')
if not self._sampwidth:
raise Error('sample width not specified')
if not self._framerate:
raise Error('sampling rate not specified')
self._write_header(datasize)
def _init_compression(self):
if self._comptype == b'G722':
self._convert = self._lin2adpcm
elif self._comptype in (b'ulaw', b'ULAW'):
self._convert = self._lin2ulaw
elif self._comptype in (b'alaw', b'ALAW'):
self._convert = self._lin2alaw
elif self._comptype in (b'sowt', b'SOWT'):
self._convert = self._lin2sowt
def _write_header(self, initlength):
if self._aifc and self._comptype != b'NONE':
self._init_compression()
self._file.write(b'FORM')
if not self._nframes:
self._nframes = initlength // (self._nchannels * self._sampwidth)
self._datalength = self._nframes * self._nchannels * self._sampwidth
if self._datalength & 1:
self._datalength = self._datalength + 1
if self._aifc:
if self._comptype in (b'ulaw', b'ULAW', b'alaw', b'ALAW'):
self._datalength = self._datalength // 2
if self._datalength & 1:
self._datalength = self._datalength + 1
elif self._comptype == b'G722':
self._datalength = (self._datalength + 3) // 4
if self._datalength & 1:
self._datalength = self._datalength + 1
try:
self._form_length_pos = self._file.tell()
except (AttributeError, OSError):
self._form_length_pos = None
commlength = self._write_form_length(self._datalength)
if self._aifc:
self._file.write(b'AIFC')
self._file.write(b'FVER')
_write_ulong(self._file, 4)
_write_ulong(self._file, self._version)
else:
self._file.write(b'AIFF')
self._file.write(b'COMM')
_write_ulong(self._file, commlength)
_write_short(self._file, self._nchannels)
if self._form_length_pos is not None:
self._nframes_pos = self._file.tell()
_write_ulong(self._file, self._nframes)
if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
_write_short(self._file, 8)
else:
_write_short(self._file, self._sampwidth * 8)
_write_float(self._file, self._framerate)
if self._aifc:
self._file.write(self._comptype)
_write_string(self._file, self._compname)
self._file.write(b'SSND')
if self._form_length_pos is not None:
self._ssnd_length_pos = self._file.tell()
_write_ulong(self._file, self._datalength + 8)
_write_ulong(self._file, 0)
_write_ulong(self._file, 0)
def _write_form_length(self, datalength):
if self._aifc:
commlength = 18 + 5 + len(self._compname)
if commlength & 1:
commlength = commlength + 1
verslength = 12
else:
commlength = 18
verslength = 0
_write_ulong(self._file, 4 + verslength + self._marklength + \
8 + commlength + 16 + datalength)
return commlength
def _patchheader(self):
curpos = self._file.tell()
if self._datawritten & 1:
datalength = self._datawritten + 1
self._file.write(b'\x00')
else:
datalength = self._datawritten
if datalength == self._datalength and \
self._nframes == self._nframeswritten and \
self._marklength == 0:
self._file.seek(curpos, 0)
return
self._file.seek(self._form_length_pos, 0)
dummy = self._write_form_length(datalength)
self._file.seek(self._nframes_pos, 0)
_write_ulong(self._file, self._nframeswritten)
self._file.seek(self._ssnd_length_pos, 0)
_write_ulong(self._file, datalength + 8)
self._file.seek(curpos, 0)
self._nframes = self._nframeswritten
self._datalength = datalength
def _writemarkers(self):
if len(self._markers) == 0:
return
self._file.write(b'MARK')
length = 2
for marker in self._markers:
id, pos, name = marker
length = length + len(name) + 1 + 6
if len(name) & 1 == 0:
length = length + 1
_write_ulong(self._file, length)
self._marklength = length + 8
_write_short(self._file, len(self._markers))
for marker in self._markers:
id, pos, name = marker
_write_short(self._file, id)
_write_ulong(self._file, pos)
_write_string(self._file, name)
def open(f, mode=None):
if mode is None:
if hasattr(f, 'mode'):
mode = f.mode
else:
mode = 'rb'
if mode in ('r', 'rb'):
return Aifc_read(f)
elif mode in ('w', 'wb'):
return Aifc_write(f)
else:
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
if __name__ == '__main__':
import sys
if not sys.argv[1:]:
sys.argv.append('/usr/demos/data/audio/bach.aiff')
fn = sys.argv[1]
with open(fn, 'r') as f:
print("Reading", fn)
print("nchannels =", f.getnchannels())
print("nframes =", f.getnframes())
print("sampwidth =", f.getsampwidth())
print("framerate =", f.getframerate())
print("comptype =", f.getcomptype())
print("compname =", f.getcompname())
if sys.argv[2:]:
gn = sys.argv[2]
print("Writing", gn)
with open(gn, 'w') as g:
g.setparams(f.getparams())
while 1:
data = f.readframes(1024)
if not data:
break
g.writeframes(data)
print("Done.")

1197
Lib/annotationlib.py vendored Normal file

File diff suppressed because it is too large Load Diff

1051
Lib/argparse.py vendored

File diff suppressed because it is too large Load Diff

1489
Lib/ast.py vendored

File diff suppressed because it is too large Load Diff

307
Lib/asynchat.py vendored
View File

@@ -1,307 +0,0 @@
# -*- Mode: Python; tab-width: 4 -*-
# Id: asynchat.py,v 2.26 2000/09/07 22:29:26 rushing Exp
# Author: Sam Rushing <rushing@nightmare.com>
# ======================================================================
# Copyright 1996 by Sam Rushing
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Sam
# Rushing not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# ======================================================================
r"""A class supporting chat-style (command/response) protocols.
This class adds support for 'chat' style protocols - where one side
sends a 'command', and the other sends a response (examples would be
the common internet protocols - smtp, nntp, ftp, etc..).
The handle_read() method looks at the input stream for the current
'terminator' (usually '\r\n' for single-line responses, '\r\n.\r\n'
for multi-line output), calling self.found_terminator() on its
receipt.
for example:
Say you build an async nntp client using this class. At the start
of the connection, you'll have self.terminator set to '\r\n', in
order to process the single-line greeting. Just before issuing a
'LIST' command you'll set it to '\r\n.\r\n'. The output of the LIST
command will be accumulated (using your own 'collect_incoming_data'
method) up to the terminator, and then control will be returned to
you - by calling your self.found_terminator() method.
"""
import asyncore
from collections import deque
class async_chat(asyncore.dispatcher):
"""This is an abstract class. You must derive from this class, and add
the two methods collect_incoming_data() and found_terminator()"""
# these are overridable defaults
ac_in_buffer_size = 65536
ac_out_buffer_size = 65536
# we don't want to enable the use of encoding by default, because that is a
# sign of an application bug that we don't want to pass silently
use_encoding = 0
encoding = 'latin-1'
def __init__(self, sock=None, map=None):
# for string terminator matching
self.ac_in_buffer = b''
# we use a list here rather than io.BytesIO for a few reasons...
# del lst[:] is faster than bio.truncate(0)
# lst = [] is faster than bio.truncate(0)
self.incoming = []
# we toss the use of the "simple producer" and replace it with
# a pure deque, which the original fifo was a wrapping of
self.producer_fifo = deque()
asyncore.dispatcher.__init__(self, sock, map)
def collect_incoming_data(self, data):
raise NotImplementedError("must be implemented in subclass")
def _collect_incoming_data(self, data):
self.incoming.append(data)
def _get_data(self):
d = b''.join(self.incoming)
del self.incoming[:]
return d
def found_terminator(self):
raise NotImplementedError("must be implemented in subclass")
def set_terminator(self, term):
"""Set the input delimiter.
Can be a fixed string of any length, an integer, or None.
"""
if isinstance(term, str) and self.use_encoding:
term = bytes(term, self.encoding)
elif isinstance(term, int) and term < 0:
raise ValueError('the number of received bytes must be positive')
self.terminator = term
def get_terminator(self):
return self.terminator
# grab some more data from the socket,
# throw it to the collector method,
# check for the terminator,
# if found, transition to the next state.
def handle_read(self):
try:
data = self.recv(self.ac_in_buffer_size)
except BlockingIOError:
return
except OSError as why:
self.handle_error()
return
if isinstance(data, str) and self.use_encoding:
data = bytes(str, self.encoding)
self.ac_in_buffer = self.ac_in_buffer + data
# Continue to search for self.terminator in self.ac_in_buffer,
# while calling self.collect_incoming_data. The while loop
# is necessary because we might read several data+terminator
# combos with a single recv(4096).
while self.ac_in_buffer:
lb = len(self.ac_in_buffer)
terminator = self.get_terminator()
if not terminator:
# no terminator, collect it all
self.collect_incoming_data(self.ac_in_buffer)
self.ac_in_buffer = b''
elif isinstance(terminator, int):
# numeric terminator
n = terminator
if lb < n:
self.collect_incoming_data(self.ac_in_buffer)
self.ac_in_buffer = b''
self.terminator = self.terminator - lb
else:
self.collect_incoming_data(self.ac_in_buffer[:n])
self.ac_in_buffer = self.ac_in_buffer[n:]
self.terminator = 0
self.found_terminator()
else:
# 3 cases:
# 1) end of buffer matches terminator exactly:
# collect data, transition
# 2) end of buffer matches some prefix:
# collect data to the prefix
# 3) end of buffer does not match any prefix:
# collect data
terminator_len = len(terminator)
index = self.ac_in_buffer.find(terminator)
if index != -1:
# we found the terminator
if index > 0:
# don't bother reporting the empty string
# (source of subtle bugs)
self.collect_incoming_data(self.ac_in_buffer[:index])
self.ac_in_buffer = self.ac_in_buffer[index+terminator_len:]
# This does the Right Thing if the terminator
# is changed here.
self.found_terminator()
else:
# check for a prefix of the terminator
index = find_prefix_at_end(self.ac_in_buffer, terminator)
if index:
if index != lb:
# we found a prefix, collect up to the prefix
self.collect_incoming_data(self.ac_in_buffer[:-index])
self.ac_in_buffer = self.ac_in_buffer[-index:]
break
else:
# no prefix, collect it all
self.collect_incoming_data(self.ac_in_buffer)
self.ac_in_buffer = b''
def handle_write(self):
self.initiate_send()
def handle_close(self):
self.close()
def push(self, data):
if not isinstance(data, (bytes, bytearray, memoryview)):
raise TypeError('data argument must be byte-ish (%r)',
type(data))
sabs = self.ac_out_buffer_size
if len(data) > sabs:
for i in range(0, len(data), sabs):
self.producer_fifo.append(data[i:i+sabs])
else:
self.producer_fifo.append(data)
self.initiate_send()
def push_with_producer(self, producer):
self.producer_fifo.append(producer)
self.initiate_send()
def readable(self):
"predicate for inclusion in the readable for select()"
# cannot use the old predicate, it violates the claim of the
# set_terminator method.
# return (len(self.ac_in_buffer) <= self.ac_in_buffer_size)
return 1
def writable(self):
"predicate for inclusion in the writable for select()"
return self.producer_fifo or (not self.connected)
def close_when_done(self):
"automatically close this channel once the outgoing queue is empty"
self.producer_fifo.append(None)
def initiate_send(self):
while self.producer_fifo and self.connected:
first = self.producer_fifo[0]
# handle empty string/buffer or None entry
if not first:
del self.producer_fifo[0]
if first is None:
self.handle_close()
return
# handle classic producer behavior
obs = self.ac_out_buffer_size
try:
data = first[:obs]
except TypeError:
data = first.more()
if data:
self.producer_fifo.appendleft(data)
else:
del self.producer_fifo[0]
continue
if isinstance(data, str) and self.use_encoding:
data = bytes(data, self.encoding)
# send the data
try:
num_sent = self.send(data)
except OSError:
self.handle_error()
return
if num_sent:
if num_sent < len(data) or obs < len(first):
self.producer_fifo[0] = first[num_sent:]
else:
del self.producer_fifo[0]
# we tried to send some actual data
return
def discard_buffers(self):
# Emergencies only!
self.ac_in_buffer = b''
del self.incoming[:]
self.producer_fifo.clear()
class simple_producer:
def __init__(self, data, buffer_size=512):
self.data = data
self.buffer_size = buffer_size
def more(self):
if len(self.data) > self.buffer_size:
result = self.data[:self.buffer_size]
self.data = self.data[self.buffer_size:]
return result
else:
result = self.data
self.data = b''
return result
# Given 'haystack', see if any prefix of 'needle' is at its end. This
# assumes an exact match has already been checked. Return the number of
# characters matched.
# for example:
# f_p_a_e("qwerty\r", "\r\n") => 1
# f_p_a_e("qwertydkjf", "\r\n") => 0
# f_p_a_e("qwerty\r\n", "\r\n") => <undefined>
# this could maybe be made faster with a computed regex?
# [answer: no; circa Python-2.0, Jan 2001]
# new python: 28961/s
# old python: 18307/s
# re: 12820/s
# regex: 14035/s
def find_prefix_at_end(haystack, needle):
l = len(needle) - 1
while l and not haystack.endswith(needle[:l]):
l -= 1
return l

View File

@@ -1,23 +1,16 @@
"""The asyncio package, tracking PEP 3156."""
# flake8: noqa
import sys
import selectors
# XXX RustPython TODO: _overlapped
if sys.platform == 'win32' and False:
# Similar thing for _overlapped.
try:
from . import _overlapped
except ImportError:
import _overlapped # Will also be exported.
# This relies on each of the submodules having an __all__ variable.
from .base_events import *
from .coroutines import *
from .events import *
from .exceptions import *
from .futures import *
from .graph import *
from .locks import *
from .protocols import *
from .runners import *
@@ -25,12 +18,17 @@ from .queues import *
from .streams import *
from .subprocess import *
from .tasks import *
from .taskgroups import *
from .timeouts import *
from .threads import *
from .transports import *
__all__ = (base_events.__all__ +
coroutines.__all__ +
events.__all__ +
exceptions.__all__ +
futures.__all__ +
graph.__all__ +
locks.__all__ +
protocols.__all__ +
runners.__all__ +
@@ -38,6 +36,9 @@ __all__ = (base_events.__all__ +
streams.__all__ +
subprocess.__all__ +
tasks.__all__ +
taskgroups.__all__ +
threads.__all__ +
timeouts.__all__ +
transports.__all__)
if sys.platform == 'win32': # pragma: no cover
@@ -46,3 +47,28 @@ if sys.platform == 'win32': # pragma: no cover
else:
from .unix_events import * # pragma: no cover
__all__ += unix_events.__all__
def __getattr__(name: str):
import warnings
match name:
case "AbstractEventLoopPolicy":
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
return events._AbstractEventLoopPolicy
case "DefaultEventLoopPolicy":
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
if sys.platform == 'win32':
return windows_events._DefaultEventLoopPolicy
return unix_events._DefaultEventLoopPolicy
case "WindowsSelectorEventLoopPolicy":
if sys.platform == 'win32':
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
return windows_events._WindowsSelectorEventLoopPolicy
# Else fall through to the AttributeError below.
case "WindowsProactorEventLoopPolicy":
if sys.platform == 'win32':
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
return windows_events._WindowsProactorEventLoopPolicy
# Else fall through to the AttributeError below.
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

239
Lib/asyncio/__main__.py vendored Normal file
View File

@@ -0,0 +1,239 @@
import argparse
import ast
import asyncio
import asyncio.tools
import concurrent.futures
import contextvars
import inspect
import os
import site
import sys
import threading
import types
import warnings
from _colorize import get_theme
from _pyrepl.console import InteractiveColoredConsole
from . import futures
class AsyncIOInteractiveConsole(InteractiveColoredConsole):
def __init__(self, locals, loop):
super().__init__(locals, filename="<stdin>")
self.compile.compiler.flags |= ast.PyCF_ALLOW_TOP_LEVEL_AWAIT
self.loop = loop
self.context = contextvars.copy_context()
def runcode(self, code):
global return_code
future = concurrent.futures.Future()
def callback():
global return_code
global repl_future
global keyboard_interrupted
repl_future = None
keyboard_interrupted = False
func = types.FunctionType(code, self.locals)
try:
coro = func()
except SystemExit as se:
return_code = se.code
self.loop.stop()
return
except KeyboardInterrupt as ex:
keyboard_interrupted = True
future.set_exception(ex)
return
except BaseException as ex:
future.set_exception(ex)
return
if not inspect.iscoroutine(coro):
future.set_result(coro)
return
try:
repl_future = self.loop.create_task(coro, context=self.context)
futures._chain_future(repl_future, future)
except BaseException as exc:
future.set_exception(exc)
self.loop.call_soon_threadsafe(callback, context=self.context)
try:
return future.result()
except SystemExit as se:
return_code = se.code
self.loop.stop()
return
except BaseException:
if keyboard_interrupted:
if not CAN_USE_PYREPL:
self.write("\nKeyboardInterrupt\n")
else:
self.showtraceback()
return self.STATEMENT_FAILED
class REPLThread(threading.Thread):
def run(self):
global return_code
try:
banner = (
f'asyncio REPL {sys.version} on {sys.platform}\n'
f'Use "await" directly instead of "asyncio.run()".\n'
f'Type "help", "copyright", "credits" or "license" '
f'for more information.\n'
)
console.write(banner)
if startup_path := os.getenv("PYTHONSTARTUP"):
sys.audit("cpython.run_startup", startup_path)
import tokenize
with tokenize.open(startup_path) as f:
startup_code = compile(f.read(), startup_path, "exec")
exec(startup_code, console.locals)
ps1 = getattr(sys, "ps1", ">>> ")
if CAN_USE_PYREPL:
theme = get_theme().syntax
ps1 = f"{theme.prompt}{ps1}{theme.reset}"
console.write(f"{ps1}import asyncio\n")
if CAN_USE_PYREPL:
from _pyrepl.simple_interact import (
run_multiline_interactive_console,
)
try:
run_multiline_interactive_console(console)
except SystemExit:
# expected via the `exit` and `quit` commands
pass
except BaseException:
# unexpected issue
console.showtraceback()
console.write("Internal error, ")
return_code = 1
else:
console.interact(banner="", exitmsg="")
finally:
warnings.filterwarnings(
'ignore',
message=r'^coroutine .* was never awaited$',
category=RuntimeWarning)
loop.call_soon_threadsafe(loop.stop)
def interrupt(self) -> None:
if not CAN_USE_PYREPL:
return
from _pyrepl.simple_interact import _get_reader
r = _get_reader()
if r.threading_hook is not None:
r.threading_hook.add("") # type: ignore
if __name__ == '__main__':
parser = argparse.ArgumentParser(
prog="python3 -m asyncio",
description="Interactive asyncio shell and CLI tools",
color=True,
)
subparsers = parser.add_subparsers(help="sub-commands", dest="command")
ps = subparsers.add_parser(
"ps", help="Display a table of all pending tasks in a process"
)
ps.add_argument("pid", type=int, help="Process ID to inspect")
pstree = subparsers.add_parser(
"pstree", help="Display a tree of all pending tasks in a process"
)
pstree.add_argument("pid", type=int, help="Process ID to inspect")
args = parser.parse_args()
match args.command:
case "ps":
asyncio.tools.display_awaited_by_tasks_table(args.pid)
sys.exit(0)
case "pstree":
asyncio.tools.display_awaited_by_tasks_tree(args.pid)
sys.exit(0)
case None:
pass # continue to the interactive shell
case _:
# shouldn't happen as an invalid command-line wouldn't parse
# but let's keep it for the next person adding a command
print(f"error: unhandled command {args.command}", file=sys.stderr)
parser.print_usage(file=sys.stderr)
sys.exit(1)
sys.audit("cpython.run_stdin")
if os.getenv('PYTHON_BASIC_REPL'):
CAN_USE_PYREPL = False
else:
from _pyrepl.main import CAN_USE_PYREPL
return_code = 0
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
repl_locals = {'asyncio': asyncio}
for key in {'__name__', '__package__',
'__loader__', '__spec__',
'__builtins__', '__file__'}:
repl_locals[key] = locals()[key]
console = AsyncIOInteractiveConsole(repl_locals, loop)
repl_future = None
keyboard_interrupted = False
try:
import readline # NoQA
except ImportError:
readline = None
interactive_hook = getattr(sys, "__interactivehook__", None)
if interactive_hook is not None:
sys.audit("cpython.run_interactivehook", interactive_hook)
interactive_hook()
if interactive_hook is site.register_readline:
# Fix the completer function to use the interactive console locals
try:
import rlcompleter
except:
pass
else:
if readline is not None:
completer = rlcompleter.Completer(console.locals)
readline.set_completer(completer.complete)
repl_thread = REPLThread(name="Interactive thread")
repl_thread.daemon = True
repl_thread.start()
while True:
try:
loop.run_forever()
except KeyboardInterrupt:
keyboard_interrupted = True
if repl_future and not repl_future.done():
repl_future.cancel()
repl_thread.interrupt()
continue
else:
break
console.write('exiting asyncio REPL...\n')
sys.exit(return_code)

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,8 @@
__all__ = []
__all__ = ()
import concurrent.futures._base
import reprlib
from . import events
Error = concurrent.futures._base.Error
CancelledError = concurrent.futures.CancelledError
TimeoutError = concurrent.futures.TimeoutError
class InvalidStateError(Error):
"""The operation is not allowed in this state."""
from . import format_helpers
# States for Future.
_PENDING = 'PENDING'
@@ -38,17 +28,17 @@ def _format_callbacks(cb):
cb = ''
def format_cb(callback):
return events._format_callback_source(callback, ())
return format_helpers._format_callback_source(callback, ())
if size == 1:
cb = format_cb(cb[0])
cb = format_cb(cb[0][0])
elif size == 2:
cb = '{}, {}'.format(format_cb(cb[0]), format_cb(cb[1]))
cb = '{}, {}'.format(format_cb(cb[0][0]), format_cb(cb[1][0]))
elif size > 2:
cb = '{}, <{} more>, {}'.format(format_cb(cb[0]),
cb = '{}, <{} more>, {}'.format(format_cb(cb[0][0]),
size - 2,
format_cb(cb[-1]))
return 'cb=[%s]' % cb
format_cb(cb[-1][0]))
return f'cb=[{cb}]'
def _future_repr_info(future):
@@ -57,15 +47,21 @@ def _future_repr_info(future):
info = [future._state.lower()]
if future._state == _FINISHED:
if future._exception is not None:
info.append('exception={!r}'.format(future._exception))
info.append(f'exception={future._exception!r}')
else:
# use reprlib to limit the length of the output, especially
# for very long strings
result = reprlib.repr(future._result)
info.append('result={}'.format(result))
info.append(f'result={result}')
if future._callbacks:
info.append(_format_callbacks(future._callbacks))
if future._source_traceback:
frame = future._source_traceback[-1]
info.append('created at %s:%s' % (frame[0], frame[1]))
info.append(f'created at {frame[0]}:{frame[1]}')
return info
@reprlib.recursive_repr()
def _future_repr(future):
info = ' '.join(_future_repr_info(future))
return f'<{future.__class__.__name__} {info}>'

Some files were not shown because too many files have changed in this diff Show More