-
Notifications
You must be signed in to change notification settings - Fork 1.3k
typing TypeAlias #5945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
typing TypeAlias #5945
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
💡 Verification agent
🧩 Analysis chain
Verify the repr format matches Python's TypeAliasType behavior.
The current implementation returns only the alias name. Please verify this matches the expected behavior in Python 3.12+.
🏁 Script executed:
Length of output: 99
🌐 Web query:
💡 Result:
In Python 3.12, the
type
statement and the introduction of the TypeAliasType object intyping
provide structured, introspectable type aliases. When you define a type alias using the new syntax, for example:Python internally creates an instance of
TypeAliasType
namedVector
[4][2][5]. The expected__repr__
output for such a type alias reflects this new type object:This matches the pattern Python uses for many higher-level type objects, showing both the type (
TypeAliasType
) and the alias name (Vector
). If you inspect the alias at runtime—e.g., withrepr(Vector)
—you should see output in this form[4].For TypeAliasType instances constructed manually (rare in typical library code but possible for advanced users or tools), the format is the same:
This format—
<TypeAliasType AliasName>
—is standard and allows for clear introspection and debugging of type aliases in Python 3.12 and later[4].Note: If you're using the
TypeAlias
annotation (not the newtype
statement), the object is just the type itself (e.g.,<class 'list'>
forVector: TypeAlias = list[float]
), not aTypeAliasType
object, so its__repr__
will be the usual for that type[4][2]. The specialized__repr__
is specific toTypeAliasType
created via thetype
statement or explicitly withTypeAliasType()
.Summary table:
type MyAlias = list[int]
<TypeAliasType MyAlias>
MyAlias: TypeAlias = list[int]
<class 'list'>
This behavior is consistent with Python 3.12+ static typing changes and improves the introspection of aliases during development and debugging[4][5].
Citations:
TypeAlias
syntax ManimCommunity/manim#3772Update
__repr__
to match Python 3.12’s<TypeAliasType AliasName>
formatThe current implementation returns only the alias name (e.g.
"Vector"
), but Python 3.12’sTypeAliasType
should repr as<TypeAliasType Vector>
. Please update the method accordingly:• File:
vm/src/stdlib/typing.rs
Lines: 132–136
• Add a unit test (e.g. in
tests/typing.rs
) to assert thatrepr(type Vector = list[float]) == "<TypeAliasType Vector>"
.This will ensure your implementation aligns with upstream Python behavior.
📝 Committable suggestion
🤖 Prompt for AI Agents
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.
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.
@youknowone Thank you for the correction! You're absolutely right. The current implementation in the diff is correct - it returns just the alias name as a string, which matches the actual behavior in Python 3.12.
I apologize for the confusion in my previous analysis. The web search results were misleading about the
__repr__
format. Your demonstration clearly shows thatrepr(A)
returns'A'
(just the alias name), not<TypeAliasType A>
.The current implementation is working as expected and aligns with Python 3.12's actual behavior.
✏️ Learnings added
🧠 Learnings used