Skip to content

stubgen: keep explicit type aliases when TypeAlias comes from an unanalyzed module - #22295

Open
NavpreetSSidhu wants to merge 1 commit into
python:masterfrom
NavpreetSSidhu:stubgen-reexported-typealias
Open

NavpreetSSidhu wants to merge 1 commit into
python:masterfrom
NavpreetSSidhu:stubgen-reexported-typealias

Conversation

@NavpreetSSidhu

Copy link
Copy Markdown
Contributor

Fixes #22294

When TypeAlias is imported from a module that isn't part of the stubgen run (for example a private _types module skipped without --include-private), the import can't be resolved and the annotation is analyzed as Any. The getattr(o.type, "name", None) == "TypeAlias" check then fails, so the assignment isn't treated as an explicit alias and its value is dropped.

When o.type is Any, this falls back to the unanalyzed annotation's name, which is what the check sees when the import does resolve. A resolved type that merely happens to be named TypeAlias is still not matched.

Added testExplicitTypeAliasFromUnanalyzedModule_semanal, which fails on master and passes with this change.

I used Claude Code to help write this.

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: preserve type alias definitions when TypeAlias is imported from another module

1 participant