You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stubgen: preserve type alias definitions when TypeAlias is imported from another module #22294
stubgen does not recognize TypeAlias annotations when TypeAlias is re-exported from another module.
Instead of preserving the type alias definition, it replaces the right-hand side with ....
This is particularly problematic when using a compatibility module to support TypeAlias across different Python versions.
To Reproduce
types_compat.py
importsysfromtypingimportTYPE_CHECKINGifsys.version_info>= (3, 10): # workaround for mypy, which cannot distinguish between real imports in except clausefromtypingimportTypeAliaselifTYPE_CHECKING: # don't add a real dependency on typing_extensions!fromtyping_extensionsimportTypeAliaselse:
TypeAlias=object
When TypeAlias is imported directly from typing or defined using the compatibility logic in the same module, stubgen correctly preserves the type alias definition.
The problem only occurs when the TypeAlias annotation is imported through another module.
It would be useful if stubgen could recognize re-exported TypeAlias annotations and preserve their definitions, without requiring the compatibility logic to be duplicated across modules or post-processing of the generated stubs.
Additionally, my module is actually named _types - and I don't want to use --include-private to be able to use them type aliases.
Activity