GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use PyStrRef for TypeAliasType name by walker84837 · Pull Request #6203 · RustPython/RustPython

Conversation

@walker84837

@walker84837 walker84837 commented Oct 20, 2025 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@walker84837
fix(PyStrRef): fix TODO in typing.rs where PyObjectRef was used
78601f3
@coderabbitai

coderabbitai Bot commented Oct 20, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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 docstrings
🧪 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)
  • vm/src/stdlib/typing.rs

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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@walker84837
chore(fmt): apply rustfmt to code
1e6dbc6
youknowone
youknowone approved these changes Oct 21, 2025
View reviewed changes

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

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.

All reactions
@youknowone
youknowone merged commit b15e537 into RustPython:main Oct 21, 2025
1 check passed

Uh oh!

There was an error while loading. Please reload this page.

@walker84837
walker84837 deleted the fix/todo-use-pystrref branch October 21, 2025 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@youknowone youknowone youknowone approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@walker84837 @youknowone
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.