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

Removes quotes from annotations removes quotes from literal values #2613

Closed
Czaki opened this issue Feb 6, 2023 · 11 comments · Fixed by #2615
Closed

Removes quotes from annotations removes quotes from literal values #2613

Czaki opened this issue Feb 6, 2023 · 11 comments · Fixed by #2615
Assignees
Labels
bug Something isn't working

Comments

@Czaki
Copy link
Contributor

Czaki commented Feb 6, 2023

It looks like #2431 also removes quotes from literal values in type annotation

In general, when bump ruff from 0.0.237 to 0.0.242 the following change is generated by ruff:

Literal["x86_64", "arm64"]

to

Literal[x86_64, arm64]

cibuilwheel PR with visible problem

pypa/cibuildwheel#1412

The change, when force revert changes

pypa/cibuildwheel@923fd3c (#1412)

And log from ruff:

https://results.pre-commit.ci/run/github/85508223/1675723555.oUgkXTipRmOlnOPISWV1OA

ruff configuration https://github.com/pypa/cibuildwheel/blob/e42277a69204ccfae9a1f4ae3b574eaa54109925/pyproject.toml#L120

@charliermarsh
Copy link
Member

Thank you, I'll fix this tonight and cut a new release.

@henryiii
Copy link
Contributor

henryiii commented Feb 6, 2023

Breaking pypa/build too: https://github.com/pypa/build/pull/576/files

- PathType = Union[str, 'os.PathLike[str]']
+ PathType = Union[str, os.PathLike[str]]

- _TProjectBuilder = TypeVar('_TProjectBuilder', bound='ProjectBuilder')
+ _TProjectBuilder = TypeVar('_TProjectBuilder', bound=ProjectBuilder)

These are both broken. os.PathLike[str] is not valid on Python 3.7 (and it's not an annotation). TypeVar can't have the quotes removed, the thing it's bound to doesn't exist yet. And it's also not an annotation.

@henryiii
Copy link
Contributor

henryiii commented Feb 6, 2023

Also, I'd really love for a way to see see fixed operaitons too. I have no idea what rules were applied when things are "fixed". Maybe there's a flag I missed?

@charliermarsh
Copy link
Member

In the Literal case, the issue is that you're accessing Literal from a module that isn't typing or typing_extensions.

For example, this doesn't raise an error:

from __future__ import annotations

from typing import Literal

x: Literal["x86_64", "arm64"]

But this does:

from __future__ import annotations

from .typing import Literal

x: Literal["x86_64", "arm64"]

We use typing-modules to fix this, but it doesn't support relative imports right now.

@charliermarsh
Copy link
Member

Also, I'd really love for a way to see see fixed operaitons too. I have no idea what rules were applied when things are "fixed". Maybe there's a flag I missed?

There's a --diff flag -- is that along the lines of what you're describing?

@charliermarsh charliermarsh self-assigned this Feb 6, 2023
@charliermarsh charliermarsh added the bug Something isn't working label Feb 6, 2023
@charliermarsh
Copy link
Member

The issues that @henryiii raised are fixed in #2614.

@charliermarsh
Copy link
Member

I can add support for relative import paths with typing-modules to fix the issue @Czaki raised. (I'm actually surprised that hasn't bitten you already prior to this lint rule!)

@henryiii
Copy link
Contributor

henryiii commented Feb 6, 2023

I can see a diff of what changed via git, I just can't see the list of rules that were applied to make those changes. For example, if I make a fixable change to a Ruby file and run rubocop:

Inspecting 16 files
....C...........

Offenses:

_plugins/checkproj.rb:36:7: C: [Corrected] Style/RedundantReturn: Redundant return detected.
      return @people ||= people_gen
      ^^^^^^

16 files inspected, 1 offense detected, 1 offense corrected

I can see exactly what rules were applied in the fixes.

Something like Fixed:\n followed by the rules that were fixed, for example.

@henryiii
Copy link
Contributor

henryiii commented Feb 6, 2023

The typing modules issue has bit before, it's #2005.

@charliermarsh
Copy link
Member

Gonna try and fix that tonight.

@Czaki
Copy link
Contributor Author

Czaki commented Feb 7, 2023

Thanks for the really fast action :) ❤️

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