GeezerVison is showing github.com — Use PyStrRef for TypeAliasType name by walker84837 · Pull Request #6203 · RustPython/RustPython
Conversation
walker84837
commented
Oct 20, 2025
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
This MR changes TypeAliasType so that it uses a PyStrRef object for its name field instead of a PyObjectRef.
Previously, the name field was a PyObjectRef. Although PyObjectRef is flexible, using a more specific type, like PyStrRef, improves transparency and type safety.
Changes include:
- As mentioned, updating
TypeAliasType.name from PyObjectRef to PyStrRef.
- Changing
TypeAliasType::new() and __name__ getter to handle PyStrRef.
- Adding small type checks in:
vm/src/frame.rs
vm/src/stdlib/typing.rs
to enforce that the TypeAliasType name is a string.
- Since the type of
name is now a PyStrRef, the repr_str implementation for TypeAliasType was simplified by using PyStrRef::as_str() directly.
Summary by CodeRabbit
- Bug Fixes
- Strengthened validation for TypeAliasType names so non-string names now produce a clear "TypeAliasType name must be a string" error.
- Improved consistency of TypeAliasType construction and string representation, reducing confusion when inspecting or creating type aliases.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Oct 20, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Walkthrough
Adds runtime validation ensuring TypeAliasType names are Python strings and changes the internal TypeAliasType.name field from PyObjectRef to PyStrRef, updating constructors, repr, and name handling accordingly.
Changes
| Cohort / File(s) |
Summary |
TypeAlias intrinsic validation vm/src/frame.rs |
Downcasts the provided name to PyStr; returns TypeError("TypeAliasType name must be a string") on failure before creating the TypeAliasType. |
TypeAliasType type safety & API vm/src/stdlib/typing.rs |
Changes TypeAliasType.name: PyObjectRef → PyStrRef; new/py_new accept/validate PyStrRef; __name__ now returns self.name.clone().into(); repr_str returns name.as_str() and ignores VM; type_params downcast handling tightened. |
Sequence Diagram(s)
sequenceDiagram
participant Caller as Intrinsic Handler (frame.rs)
participant Typing as TypeAliasType (typing.rs)
participant VM as VirtualMachine
Caller->>Typing: provide name (PyObjectRef) and type_params, value
Typing->>Typing: downcast name -> PyStr
alt downcast succeeds
Typing->>Typing: construct TypeAliasType{name: PyStrRef, type_params, value}
Typing-->>Caller: return TypeAliasType instance
else downcast fails
Typing-->>Caller: raise TypeError("TypeAliasType name must be a string")
end
Loading
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
- Type alias type #6011 — Modifies
TypeAliasType construction/representation in vm/src/stdlib/typing.rs, overlapping constructor/validation changes.
- typing TypeAlias #5945 — Changes
frame.rs intrinsic handling and typing.rs TypeAlias representation; closely related to combined edits here.
- Fix TypeParams, TypeAlias compile #5862 — Adjusts
TypeAlias handling in frame.rs, including name/type_params validation patterns.
Poem
🐰 I hopped through code with nimble paws,
I checked each name for stringly laws.
PyStrRef snug where objects once lay,
Errors caught before they stray.
A tiny twitch, a safer day ✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
⚠️ Warning |
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. |
You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check |
✅ Passed |
The title "Use PyStrRef for TypeAliasType name" directly and accurately captures the primary change in the pull request. The changeset centers on replacing the PyObjectRef type with PyStrRef for the TypeAliasType.name field, updating the constructor and related methods to reflect this change, and adding type validation. The title is concise, specific, and clearly communicates the main objective without vague language or unnecessary details. A reader reviewing the commit history would immediately understand that this PR refines type safety by using a more specific string reference type for the TypeAliasType name. |
✨ Finishing touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 78601f3 and 1e6dbc6.
📒 Files selected for processing (1)
vm/src/stdlib/typing.rs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing!
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|