-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Type alias stubgen fix #18960
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
Type alias stubgen fix #18960
Conversation
test-data/unit/stubgen.test
Outdated
alias: TypeAlias = tuple[int, str] | ||
|
||
[out] | ||
alias = tuple[int, str] |
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.
I don't think that we should skip TypeAlias
here. It should be like this, in my opinion:
alias = tuple[int, str] | |
from typing import TypeAlias | |
alias: TypeAlias = tuple[int, str] |
test-data/unit/stubgen.test
Outdated
alias: TypeAlias = tuple[int, str] | ||
|
||
[out] | ||
alias: TypeAlias = tuple[int, str] |
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.
Don't forget to add an import 👍
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.
@sobolevn sorry, this PR still WIP, I didn't mean to ask for a review
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.
No worries, marked as a draft for now :)
…xplicit TypeAlias assignments
…name in import tracker
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.
Thanks! Some nitpicks.
mypy/stubgen.py
Outdated
@@ -1194,6 +1207,7 @@ def visit_import_from(self, o: ImportFrom) -> None: | |||
self.import_tracker.reexport(name) | |||
as_name = name | |||
import_names.append((name, as_name)) | |||
# here's required = False |
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.
# here's required = False |
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.
fixed this, thank you
test-data/unit/stubgen.test
Outdated
[case testExplicitTypeAlias] | ||
from typing import TypeAlias | ||
|
||
alias: TypeAlias = tuple[int, str] |
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.
alias: TypeAlias = tuple[int, str] | |
explicit_alias: TypeAlias = tuple[int, str] | |
implicit_alias = list[int] |
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.
fixed this, thank you
test-data/unit/stubgen.test
Outdated
[out] | ||
from typing import TypeAlias | ||
|
||
alias: TypeAlias = tuple[int, str] |
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.
alias: TypeAlias = tuple[int, str] | |
explicit_alias: TypeAlias = tuple[int, str] | |
implicit_alias = list[int] |
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.
fixed this, thank you
…implicit_alias for clarity
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!
fixes #18905
TypeAlias
is an unanalyzed type, but is also an alias. So I changed a little bit of checking in thevisit_assignment_stmt
method.