Skip to content

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

Merged
merged 10 commits into from
May 1, 2025
Merged

Conversation

makridenko
Copy link
Contributor

@makridenko makridenko commented Apr 24, 2025

fixes #18905

TypeAlias is an unanalyzed type, but is also an alias. So I changed a little bit of checking in the visit_assignment_stmt method.

alias: TypeAlias = tuple[int, str]

[out]
alias = tuple[int, str]
Copy link
Member

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:

Suggested change
alias = tuple[int, str]
from typing import TypeAlias
alias: TypeAlias = tuple[int, str]

alias: TypeAlias = tuple[int, str]

[out]
alias: TypeAlias = tuple[int, str]
Copy link
Member

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 👍

Copy link
Contributor Author

@makridenko makridenko May 1, 2025

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

Copy link
Member

@sobolevn sobolevn May 1, 2025

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 :)

@sobolevn sobolevn marked this pull request as draft May 1, 2025 12:49
@makridenko makridenko marked this pull request as ready for review May 1, 2025 13:14
@makridenko makridenko requested a review from sobolevn May 1, 2025 13:14
Copy link
Member

@sobolevn sobolevn left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# here's required = False

Copy link
Contributor Author

@makridenko makridenko May 1, 2025

Choose a reason for hiding this comment

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

fixed this, thank you

[case testExplicitTypeAlias]
from typing import TypeAlias

alias: TypeAlias = tuple[int, str]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
alias: TypeAlias = tuple[int, str]
explicit_alias: TypeAlias = tuple[int, str]
implicit_alias = list[int]

Copy link
Contributor Author

@makridenko makridenko May 1, 2025

Choose a reason for hiding this comment

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

fixed this, thank you

[out]
from typing import TypeAlias

alias: TypeAlias = tuple[int, str]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
alias: TypeAlias = tuple[int, str]
explicit_alias: TypeAlias = tuple[int, str]
implicit_alias = list[int]

Copy link
Contributor Author

@makridenko makridenko May 1, 2025

Choose a reason for hiding this comment

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

fixed this, thank you

@makridenko makridenko requested a review from sobolevn May 1, 2025 14:45
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thank you!

@sobolevn sobolevn merged commit 4b46d09 into python:master May 1, 2025
12 checks passed
@makridenko makridenko deleted the type-alias-stubgen-fix branch May 2, 2025 08:17
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.

stubgen does not handle TypeAlias
2 participants