46 Commits

Author SHA1 Message Date
Shahar Naveh
d7d936575c General code nitpicks (#7955) 2026-05-24 19:55:22 +09:00
Shahar Naveh
f3b83efcee Update test_structseq.py to 3.14.5 (#7951) 2026-05-22 20:11:57 +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
ddfcb25957 Clippy nursery lints (#7875) 2026-05-15 10:38:36 +00:00
Shahar Naveh
460b1d39ed Clippy warn uninlined_format_args & redundant_else (#7873) 2026-05-15 16:52:06 +09:00
Shahar Naveh
e8711edd2d Clippy warn on unnecessary wraps (#7869) 2026-05-13 23:14:33 +09:00
Shahar Naveh
4a46e84eb9 Add map_unwrap_or clippy rule (#7829) 2026-05-12 00:51:23 +09:00
Shahar Naveh
ee5e9d0001 Enable some pedantic clippy lints (#7764) 2026-05-04 10:25:37 +09:00
Shahar Naveh
eb99a8ecf1 Warn on unreachable_pub (#7762) 2026-05-04 10:18:24 +09:00
Shahar Naveh
926d69b50a Add some clippy lints (#7755) 2026-05-02 11:14:23 +09: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
Roman
7bb2fb0755 Fix pyclass memory layout to prevent silent UB in inherited getter dispatch (#7663) 2026-04-24 23:30:23 +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
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
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
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
1f6e47ce9c extend types and exceptions only for genesis (#7316) 2026-03-03 11:24:58 +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
563abea251 Require exact n_sequence_fields length in TryFromObject (#7150)
Unmark test_asctime expectedFailure for Windows.
2026-02-15 14:37:48 +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
Jeong, YunWon
5dabad6702 reason inside #[allow] (#7049) 2026-02-08 13:11:50 +00:00
Jeong, YunWon
477e20a7a9 Support #[cfg] in with (#6975) 2026-02-03 18:55:59 +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
Noa
276a4bdc80 Make paths in macro arguments relative to the source file, not MANIFEST_DIR (#6873) 2026-01-30 22:37:18 +09:00
Noa
617cdc9724 Make validate_downcastable_from unsafe (#6851) 2026-01-26 10:39:08 +09:00
Jeong YunWon
20376451eb Implement Py_mod_create slot support in multi-phase init 2026-01-22 11:21:42 +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
2da102fab8 FromArgs with error_msg (#6804) 2026-01-20 02:10:19 +09:00
Jeong, YunWon
9301ae2746 traverse and clear (#6780) 2026-01-18 23:23:11 +09:00
Jeong, YunWon
f5b44f505a Fix Exception.__init__ 2026-01-17 19:21:11 +09:00
Noa
09bde28281 Move typeid into vtable (#6231)
* Move typeid into vtable

* Bump rust-version
2026-01-07 12:33:29 +09:00
Jeong, YunWon
346519bb6b Warn user not to override special magic methods (#6625) 2026-01-02 17:49:55 +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
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
f8199d7099 impl basicsize (#6557)
* shape_differs

* may_add_dict

* basicsize
2025-12-28 14:25:10 +09:00
Jeong, YunWon
7edc3bba5d tp_itemsize (#6544) 2025-12-28 10:27:58 +09:00
Jeong, YunWon
c9bf8df19c copyslot for init (#6515) 2025-12-26 09:46:33 +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
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
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
c826f9d809 PyStructSequence Compatibility (#6327)
* Fix local time

* PyStructSequence
2025-12-05 22:44:00 +09:00
Shahar Naveh
6479a2063c move derive-impl -> crates/derive-impl (#6263) 2025-11-15 19:49:00 +09:00