Skip to content

Type alias stubgen fix - #18960

Merged
sobolevn merged 10 commits into
python:masterfrom
makridenko:type-alias-stubgen-fix
May 1, 2025
Merged

sobolevn merged 10 commits into
python:masterfrom
makridenko:type-alias-stubgen-fix

Conversation

@makridenko

@makridenko makridenko commented Apr 24, 2025 •

Copy link
Copy Markdown
Contributor

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.

Comment thread test-data/unit/stubgen.test Outdated
alias: TypeAlias = tuple[int, str]

[out]
alias = tuple[int, str]

Copy link
Copy Markdown
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]

Comment thread test-data/unit/stubgen.test Outdated
alias: TypeAlias = tuple[int, str]

[out]
alias: TypeAlias = tuple[int, str]

Copy link
Copy Markdown
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 👍

@makridenko makridenko May 1, 2025 •

Copy link
Copy Markdown
Contributor Author

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

@sobolevn sobolevn May 1, 2025 •

Copy link
Copy Markdown
Member

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

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Some nitpicks.

Comment thread mypy/stubgen.py Outdated
self.import_tracker.reexport(name)
as_name = name
import_names.append((name, as_name))
# here's required = False

Copy link
Copy Markdown
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

@makridenko makridenko May 1, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed this, thank you

Comment thread test-data/unit/stubgen.test Outdated
[case testExplicitTypeAlias]
from typing import TypeAlias

alias: TypeAlias = tuple[int, str]

Copy link
Copy Markdown
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]

@makridenko makridenko May 1, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed this, thank you

Comment thread test-data/unit/stubgen.test Outdated
[out]
from typing import TypeAlias

alias: TypeAlias = tuple[int, str]

Copy link
Copy Markdown
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]

@makridenko makridenko May 1, 2025 •

Copy link
Copy Markdown
Contributor Author

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

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

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
@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