Skip to content
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

Support type aliases in metaclasses #13335

Merged
merged 3 commits into from
Aug 5, 2022
Merged

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Aug 5, 2022

This is the simplest solution I found: I just expand type alias before isinstance(type_info, Instance).

I've added several tests to make sure wrong aliases are not allowed.
Should I add anything else to the test?

Closes #13334
Refs #13331

@github-actions

This comment has been minimized.

@sobolevn sobolevn requested a review from ilevkivskyi August 5, 2022 13:32
@sobolevn
Copy link
Member Author

sobolevn commented Aug 5, 2022

@ilevkivskyi you've done a lot of type-aliases related work recently, do you have some time to take a look? 🙂

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Looks good.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Maybe add a test for a type alias that is a an alias to another type alias?

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@sobolevn
Copy link
Member Author

sobolevn commented Aug 5, 2022

Two levels of type aliases also work! I've added a test case.
Thanks everyone!

@sobolevn sobolevn merged commit 5d3eeea into python:master Aug 5, 2022
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.

TypeAlias cannot be used as a metaclass
3 participants