Skip to content

stubgen does not handle TypeAlias #18905

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

Closed
jpl-dhemberg opened this issue Apr 10, 2025 · 2 comments · Fixed by #18960
Closed

stubgen does not handle TypeAlias #18905

jpl-dhemberg opened this issue Apr 10, 2025 · 2 comments · Fixed by #18960
Labels
bug mypy got something wrong topic-stubgen

Comments

@jpl-dhemberg
Copy link

Bug Report

When running stubgen on a file that uses TypeAlias, the stubbed type of the type alias is TypeAlias. This prevents the actual aliased type from being recorded in the stub file, and causes mypy to emit a [valid-type] error.

To Reproduce

Create a file tmp.py:

from typing import TypeAlias

Foo: TypeAlias = tuple[int, str]

Then run stubgen tmp.py.

Expected Behavior

I'm not exactly sure what the expected behavior is. I guess maybe it should behave similarly to Foo = tuple[int, str] (i.e. without the TypeAlias typehint), which stubgen includes verbatim in the stub file.

Actual Behavior

The stubbed type was only TypeAlias

$ cat out/tmp.pyi 
from typing import TypeAlias

Foo: TypeAlias

Then if this stub is used, mypy emits the following error:

Invalid type alias: expression is not a valid type  [valid-type]
Foo: TypeAlias
^

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.10
@jpl-dhemberg jpl-dhemberg added the bug mypy got something wrong label Apr 10, 2025
@makridenko
Copy link
Contributor

Hi! Can I work on this?

@sobolevn
Copy link
Member

@makridenko sure, please go ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubgen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants