Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 19, 2026

The last commit is generated by #6796
python3 scripts/update_lib quick typing

Summary by CodeRabbit

  • New Features

    • PyMappingProxy objects are now hashable for use in sets and dictionaries
    • Added Abstract Base Classes support with caching and subclass registry management
    • Union type now includes attributes: __name__, __qualname__, __origin__, __parameters__, __args__
  • Improvements

    • Enhanced error message formatting for unhashable types

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Warning

Rate limit exceeded

@youknowone has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e8077f2 and 7c8d52d.

⛔ Files ignored due to path filters (5)
  • Lib/copyreg.py is excluded by !Lib/**
  • Lib/test/test_dataclasses/__init__.py is excluded by !Lib/**
  • Lib/test/test_types.py is excluded by !Lib/**
  • Lib/test/test_typing.py is excluded by !Lib/**
  • Lib/typing.py is excluded by !Lib/**
📒 Files selected for processing (11)
  • crates/vm/src/builtins/genericalias.rs
  • crates/vm/src/builtins/mappingproxy.rs
  • crates/vm/src/builtins/mod.rs
  • crates/vm/src/builtins/namespace.rs
  • crates/vm/src/builtins/type.rs
  • crates/vm/src/builtins/union.rs
  • crates/vm/src/stdlib/_abc.rs
  • crates/vm/src/stdlib/mod.rs
  • crates/vm/src/stdlib/typevar.rs
  • crates/vm/src/stdlib/typing.rs
  • crates/vm/src/types/slot.rs
📝 Walkthrough

Walkthrough

This PR updates binary operator return types from PyObjectRef to PyResult across multiple builtin modules, comprehensively reworks PyUnion to track hashable/unhashable arguments separately, implements Python ABC (Abstract Base Classes) mechanics, and updates related type system exports and error handling.

Changes

Cohort / File(s) Summary
Binary Operator Return Type Standardization
crates/vm/src/builtins/genericalias.rs, crates/vm/src/builtins/type.rs
Updated __or__ and __ror__ return types from PyObjectRef to PyResult to propagate errors; removed ToPyResult wrapping and adjusted PyNumberMethods wiring accordingly
PyUnion Implementation Rework
crates/vm/src/builtins/union.rs
Restructured PyUnion to internally track hashable_args and unhashable_args separately; added deduplication logic via dedup_and_flatten_args; introduced DedupResult struct; reworked __class_getitem__, equality, and hashing to support set-like membership semantics; added __mro_entries__ to prevent subclassing
Hashing Support for MappingProxy
crates/vm/src/builtins/mappingproxy.rs
Added Hashable trait implementation for PyMappingProxy by delegating to the underlying object's hash method
Module Exports and Public API
crates/vm/src/builtins/mod.rs, crates/vm/src/stdlib/typevar.rs, crates/vm/src/stdlib/typing.rs
Exported make_union alongside PyUnion; replaced internal typing function calls with direct make_union invocations; exposed Union as public typing module attribute
ABC Mechanics Implementation
crates/vm/src/stdlib/_abc.rs
New module implementing Python's Abstract Base Classes with cache/registry management, subclass tracking, instance/subclass checking with negative caching and invalidation signaling
ABC Module Registration
crates/vm/src/stdlib/mod.rs
Registered new _abc stdlib module in global module initialization map
Error Message Formatting
crates/vm/src/types/slot.rs
Updated unhashable type error message to wrap type name in single quotes

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: args: PyTuple
    make_union->>dedup: args: PyTuple
    dedup->>dedup: Iterate args, track hashable vs unhashable
    dedup->>dedup: Deduplicate using hashable set + equality checks
    dedup-->>make_union: DedupResult {args, hashable_args, unhashable_args}
    alt Single argument
        make_union-->>Caller: Return single arg unwrapped
    else Multiple arguments
        make_union->>PyUnion: from_dedup_result(DedupResult)
        PyUnion->>PyUnion: Store hashable/unhashable tracking
        PyUnion-->>make_union: PyUnion instance
        make_union-->>Caller: PyResult<PyUnion>
    end
Loading
sequenceDiagram
    participant Code as Client Code
    participant ABCMethods as ABC Methods
    participant Cache as Cache/Registry
    participant Counter as Invalidation Counter

    Code->>ABCMethods: _abc_subclasscheck(cls, subclass)
    ABCMethods->>Cache: Check positive cache
    alt Found in cache
        Cache-->>ABCMethods: Cached result
    else Cache miss
        ABCMethods->>Cache: Check negative cache version
        alt Version mismatch
            ABCMethods->>Counter: Increment invalidation counter
            ABCMethods->>Cache: Clear negative cache
        end
        ABCMethods->>ABCMethods: Check direct subclass/__subclasscheck__
        ABCMethods->>Cache: Check registry (recursive)
        Cache-->>ABCMethods: Result
        ABCMethods->>Cache: Update appropriate cache
    end
    ABCMethods-->>Code: bool result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • arihant2math
  • ShaharNaveh

Poem

🐰 Union types now split their ways,
Hashable and not, through dedup's maze,
ABCs cache and invalidate right,
Operators return PyResult bright,
Type systems dancing in the night! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.62% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title is partially related to the changeset but lacks specificity. It mentions _abc, _typing, and typing updates from 3.14.2, which reflect some of the changes, but omits several important modifications like PyMappingProxy hashing support, PyGenericAlias return type changes, and type operator refactoring that constitute significant portions of the changeset. Consider a more descriptive title that captures the main refactoring efforts, such as 'Refactor type operators to return PyResult and add ABC support' or provide more specific scope information about the multiple subsystems being modified.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@youknowone youknowone changed the title _abc _abc, _typing and update typing from 3.14.2 Jan 19, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 19, 2026

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
    Please pull the latest changes before pushing again:
git pull origin abc

@youknowone youknowone force-pushed the abc branch 3 times, most recently from 6df2b89 to e8077f2 Compare January 19, 2026 15:39
@youknowone youknowone changed the title _abc, _typing and update typing from 3.14.2 _abc, _typing and update typing,test_types from 3.14.2 Jan 19, 2026
@youknowone youknowone marked this pull request as ready for review January 19, 2026 15:52
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/vm/src/builtins/union.rs`:
- Around line 248-332: The dedup_and_flatten_args function currently treats any
error from arg.hash(vm) as "unhashable", masking real exceptions; change the
Err(_) arm to capture the exception (Err(e)) and propagate it unless it's a
TypeError, in which case proceed with unhashable handling. Concretely, in
dedup_and_flatten_args replace the match on arg.hash(vm) so that if Err(e) you
check the exception type (compare against vm.ctx.exceptions.type_error or use
vm.is_instance) and return Err(e) for non-TypeError, otherwise handle as now by
doing equality comparisons and adding to unhashable_list.
🧹 Nitpick comments (2)
crates/vm/src/stdlib/_abc.rs (1)

341-350: Avoid calling into the VM while holding AbcData locks.

Drop the lock guard before invoking set.clear() to reduce reentrancy/deadlock risk; apply the same pattern in _reset_registry and _reset_caches.

♻️ Suggested refactor pattern (apply similarly in reset helpers)
-        let negative_cache = impl_data.negative_cache.read();
-        if let Some(ref set) = *negative_cache {
-            vm.call_method(set.as_ref(), "clear", ())?;
-        }
-        drop(negative_cache);
+        let negative_cache = impl_data.negative_cache.read();
+        let set = negative_cache.as_ref().cloned();
+        drop(negative_cache);
+        if let Some(set) = set {
+            vm.call_method(set.as_ref(), "clear", ())?;
+        }
         impl_data.set_cache_version(invalidation_counter);

Also applies to: 453-477

crates/vm/src/builtins/union.rs (1)

389-441: Optional: fast equality path when all args are hashable.

If both unions have unhashable_args == None, consider comparing hashable_args (frozensets) directly to avoid the O(n²) nested loops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant