_abc, _typing and update typing,test_types from 3.14.2 by youknowone · Pull Request #6797 · RustPython/RustPython
📝 Walkthrough
Walkthrough
This PR standardizes binary operator hooks to return PyResult, reworks PyUnion to track hashable vs unhashable components with dedup/flatten logic, adds a new stdlib _abc module implementing ABC mechanics and caching, and makes related module/export and small API adjustments.
Changes
| Cohort / File(s) | Summary |
|---|---|
Binary operator return types crates/vm/src/builtins/genericalias.rs, crates/vm/src/builtins/type.rs, crates/vm/src/stdlib/typing.rs |
Change __or__/__ror__ and number-slot or wiring to return PyResult directly; remove ToPyResult wrapping in caller sites. |
PyUnion / typing surface crates/vm/src/builtins/union.rs, crates/vm/src/builtins/mod.rs, crates/vm/src/stdlib/typevar.rs, crates/vm/src/stdlib/typing.rs |
Major PyUnion refactor: add hashable_args/unhashable_args, dedup/flatten args, new constructors/helpers (make_union, dedup_and_flatten_args, string_to_forwardref), new getters, __mro_entries__, move union type into typing surface and export make_union/Union. |
ABC implementation crates/vm/src/stdlib/_abc.rs, crates/vm/src/stdlib/mod.rs |
Add new _abc module providing ABC data, registry/cache/negative_cache with invalidation counter, subclass/instance check functions, registration and reset APIs; register module in stdlib init map. |
MappingProxy hashing crates/vm/src/builtins/mappingproxy.rs |
Add Hashable impl delegating to underlying mapped object's hash. |
Namespace changes crates/vm/src/builtins/namespace.rs |
Add __replace__ and allow optional mapping positional arg for initialization (keys must be strings). |
Misc small changes crates/vm/src/types/slot.rs, .cspell.dict/python-more.txt |
Tweak unhashable type error formatting ('name') and add frozensets to spell dictionary. |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant make_union as make_union()
participant dedup as dedup_and_flatten_args()
participant PyUnion as PyUnion
Caller->>make_union: call with args (PyTuple)
make_union->>dedup: dedup_and_flatten_args(args)
dedup->>dedup: flatten strings -> ForwardRef, separate hashable/unhashable, dedupe
dedup-->>make_union: UnionComponents {args, hashable_args?, unhashable_args?}
alt single arg
make_union-->>Caller: return underlying arg (unwrapped)
else multiple args
make_union->>PyUnion: from_components(UnionComponents)
PyUnion-->>make_union: PyUnion instance (PyResult)
make_union-->>Caller: PyUnion (PyResult)
end
sequenceDiagram
participant Code
participant ABCMethods as _abc methods
participant Cache as Registry/Cache
participant Counter as InvalidationCounter
Code->>ABCMethods: _abc_subclasscheck(cls, subclass)
ABCMethods->>Cache: check positive cache
alt cached hit
Cache-->>ABCMethods: result
else cache miss
ABCMethods->>Cache: check negative_cache version
alt negative cache stale
ABCMethods->>Counter: increment token
ABCMethods->>Cache: clear negative cache
end
ABCMethods->>ABCMethods: run subclass hooks / direct checks / recursive registry traversal
ABCMethods->>Cache: update positive or negative cache
end
ABCMethods-->>Code: boolean result
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- RustPython version to 3.14 #6718 — overlaps on PyUnion,
make_unionexport, and operator signature changes. - Implement copyslot #6505 — related changes to numeric/operator slot wiring and
__or__/__ror__semantics. - Deprecate ::new_ref #6046 — touches
PyNamespacechanges and related builtin adjustments.
Suggested reviewers
- arihant2math
Poem
🐇 I hopped through unions, hashed and not,
I flattened strings and trimmed a lot,
ABCs now count and cache the way,
Operators return results today,
A tiny rabbit cheers the new array!
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 59.02% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The PR title references specific changes (_abc, _typing updates from 3.14.2) that align with the actual changeset, which includes new _abc module implementation, Union type updates, typing modifications, and supporting changes to type operators. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- 📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.