Skip to content
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

Add import Union to stub file (#12929) #13428

Closed

Conversation

SilvestrLanik
Copy link

Fixes #12929

Stubs generated from files with new format of Union typing will include importing Union from typing.

Test Plan

I've added 3 new tests while making sure they pass locally.

@SilvestrLanik
Copy link
Author

I've fixed the formatting and failing test :-)

def foo(a: str | None):
pass
[out]
from typing import Union
Copy link
Member

Choose a reason for hiding this comment

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

Can you please also add Optional to the test? It is highly related to Union as well.

hamdanal added a commit to hamdanal/mypy that referenced this pull request Feb 3, 2023
When a PEP 604 Union exists in the runtime, stubgen was generating a
`Union[...]` syntax without importing `Union` from `typing`. With this
change, stubgen preserves the ` | `-unions in the output.

Fixes python#12929
Closes python#13428
Ref python#12920
hauntsaninja pushed a commit that referenced this pull request Feb 7, 2023
When a PEP 604 Union exists in the runtime, stubgen was generating a
`Union[...]` syntax without importing `Union` from `typing`. With this
change, stubgen preserves the ` | `-unions in the output.

Fixes #12929
Closes #13428
Ref #12920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stubgen: import Union if generated stub code includes
3 participants