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

PYI055's "safe" fix breaks type annotation semantics #9156

Closed
tooruu opened this issue Dec 16, 2023 · 2 comments · Fixed by #9161
Closed

PYI055's "safe" fix breaks type annotation semantics #9156

tooruu opened this issue Dec 16, 2023 · 2 comments · Fixed by #9161
Labels
bug Something isn't working

Comments

@tooruu
Copy link

tooruu commented Dec 16, 2023

Ruff 0.1.8
ruff check --isolated --select PYI055 --fix
turns

def convert_union(union: UnionType) -> _T | None:
    converters: tuple[
        type[_T] | type[Converter[_T]] | Converter[_T] | Callable[[str], _T], ...
    ] = union.__args__
    ...

into

def convert_union(union: UnionType) -> _T | None:
    converters: tuple[
        type[_T | Converter[_T]], ...
    ] = union.__args__
    ...

completely disregarding Converter[_T] | Callable[[str], _T]

@zanieb zanieb added the bug Something isn't working label Dec 16, 2023
@zanieb
Copy link
Member

zanieb commented Dec 16, 2023

Thanks for the report! This just looks like a bug cc @diceroll123

ref #7886 #7934

@diceroll123
Copy link
Contributor

Sorry about that silly oversight! Opened a PR to fix.

charliermarsh pushed a commit that referenced this issue Dec 16, 2023
…#9161)

## Summary

Fix dropped union expressions for piped non-types in `PYI055` autofix

If you had `type[int] | type[str] | str`, it would have dropped the
`str`, which breaks the type!

Closes #9156 

## Test Plan

`cargo test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants