-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adding flake8-future-annotations #3072
Comments
Cool, thanks for writing this up! My only hesitation is around how this overlaps / interacts with some of the functionality that we already support -- e.g., right now, you can enforce |
Yes, the lint rule was designed such that it only raises an error if the file benefits from |
Hey sorry -- lost track of this one. I try not to inject too much opinion into what gets included and excluded, but what do you see as the benefit of omitting future annotations from files that don't need it? To me it feels easier to either use them in all files for a given package (for consistency of semantics) or none at all. |
I'm currently type-checking a large monorepo, and to avoid making changes to all files at once, adding future annotations only to changed files is easier for incremental rollout and safety on legacy code. I'm not sure if you can achieve the same effect using isort's require_imports. Honestly fine either way you decide here, I recognize that adding redundant plugins can add to the future maintainability of a project. But I am interested to hear what the broader criteria for including/excluding lint rules is; the flake8-future-annotations plugin has ~600k downloads now, so it is getting some use, but it is unclear to me if ruff just eats all tools to become the mega-tool or is more selective at redirecting functionality. |
If you're still interested, I'd be happy to support you in implementing this. It does seem complementary to what we already have with A couple questions...
What's the workflow typically look like here? As in, how do the rules help with incremental migrations?
Does FA100 not go beyond 3.10? |
One example is I want to upgrade types in certain parts of a project to modern PEP 585 syntax (e.g. In ruff, the existing mechanism to do so would be to add the future annotations line to
Fixed above to clarify the lint rule is currently applied for Python 3.7+, but the rules are not strictly necessary past Python 3.10 because |
Yeah this makes sense. I was mostly wondering if
Oh right right. (I was mistakenly wondering if the 3.10 limit was based on the original timeline for stabilizing future annotations.) |
Yes, because flake8-future-annotations only raises the lint error if a file uses an import like |
I skimmed through the conversation here, I wanted to suggest a standalone [tool.ruff.isort]
required-imports = ["from __future__ import annotations"]
[tool.ruff.per-file-ignores]
"*.pyi" = [
"I002", # from __future__ import annotations
] Even more so in the context of eventually having extendible configuration, I would prefer leaving "required-imports" empty in my base config and let per-project configuration override it. As for TylerYep's request to only adding the line when needed. I'd consider it dead code. It's a good standard to always add it when devs have to manually track it. But if tooling is aware of when it's needed of not, then devs don't have to think about it or see it when it's not needed. In other words: it's an unused import and imo should be treated as such. |
https://beta.ruff.rs/docs/ https://github.com/charliermarsh/ruff Massively simplify configurations and speedup linting thanks to Ruff. Adds more autofixes too. Using `pathlib` instead of `os.path` is the modern way to go. However fixing this could introduce a bug if not careful. So I'm leaving it for later. Existing related Ruff requests (nothing here is a blocker, just future improvements): - astral-sh/ruff#1256 - astral-sh/ruff#3011 - astral-sh/ruff#3072 - astral-sh/ruff#3910 - astral-sh/ruff#2419 - astral-sh/ruff#3115 - astral-sh/ruff#1904
https://beta.ruff.rs/docs/ https://github.com/charliermarsh/ruff Massively simplify configurations and speedup linting thanks to Ruff. Adds more autofixes too. Using `pathlib` instead of `os.path` is the modern way to go. However fixing this could introduce a bug if not careful. So I'm leaving it for later. Existing related Ruff requests (nothing here is a blocker, just future improvements): - astral-sh/ruff#1256 - astral-sh/ruff#3011 - astral-sh/ruff#3072 - astral-sh/ruff#3910 - astral-sh/ruff#2419 - astral-sh/ruff#3115 - astral-sh/ruff#1904
https://beta.ruff.rs/docs/ https://github.com/charliermarsh/ruff Massively simplify configurations and speedup linting thanks to Ruff. Adds more autofixes too. Using `pathlib` instead of `os.path` is the modern way to go. However fixing this could introduce a bug if not careful. So I'm leaving it for later. Existing related Ruff requests (nothing here is a blocker, just future improvements): - astral-sh/ruff#1256 - astral-sh/ruff#3011 - astral-sh/ruff#3072 - astral-sh/ruff#3910 - astral-sh/ruff#2419 - astral-sh/ruff#3115 - astral-sh/ruff#1904
I think this is good to go after #4702, apart from the autofix. |
Is the autofix work being tracked somewhere? |
Hi, I authored the flake8-future-annotations plugin: https://github.com/TylerYep/flake8-future-annotations and I think it would be a good addition to ruff.
The goal of the lint rule is to verifies python 3.7+ files use from future import annotations if a type is used in the module that can be rewritten using PEP 563 e.g.
typing.List, Dict, Optional, Union, etc
.It pairs especially well with pyupgrade with the --py37-plus flag or higher, since pyupgrade only replaces type annotations with the PEP 563 rules if from future import annotations is present, which I also see is included in ruff.
I plan to take a stab at implementing it (I see many of the necessary components are already tracked in ast.rs) in the following order:
list
ordict
but missing future annotations import in Python 3.7 to 3.10)All feedback is welcome, thanks!
The text was updated successfully, but these errors were encountered: