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

"Union" is not replaced with "|" in user-defined type hints #645

Closed
simon-liebehenschel opened this issue May 23, 2022 · 3 comments
Closed

Comments

@simon-liebehenschel
Copy link

simon-liebehenschel commented May 23, 2022

Sample code:

from typing import Union

FooBar = Union[str, int]

Current result:

No changes

Expected result

FooBar = int | str

pre-commit config:

  - repo: https://github.com/asottile/pyupgrade
    rev: v2.32.1
    hooks:
      - id: pyupgrade
        args: [--py310-plus]

I've tried to search over open and closed issues, but I found nothing. If it is an expected behavior, then it will be nice to document this.

@simon-liebehenschel simon-liebehenschel changed the title pep 604 typing rewrites" "pep 604 typing rewrites" does not support annotated variables May 23, 2022
@simon-liebehenschel simon-liebehenschel changed the title "pep 604 typing rewrites" does not support annotated variables "Union" is not replaced with "|" in user-defined type hints May 23, 2022
@asottile
Copy link
Owner

this was intentionally omitted because type checkers did not support it

@sjdemartini
Copy link

Should the behavior in pyupgrade be changed now that mypy supports the PEP604 syntax python/mypy#9880, so that user-defined type-hints with Union aren't ignored?

@asottile
Copy link
Owner

perhaps! feel free to send a tested patch

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

No branches or pull requests

3 participants