diff --git a/scripts/_utils.py b/scripts/_utils.py index 23ac16d57d..7871be6cd9 100644 --- a/scripts/_utils.py +++ b/scripts/_utils.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import re from pathlib import Path diff --git a/scripts/add_plugin.py b/scripts/add_plugin.py index 7cc83974b7..9e171faf5c 100755 --- a/scripts/add_plugin.py +++ b/scripts/add_plugin.py @@ -8,6 +8,7 @@ Example usage: --url https://pypi.org/project/flake8-pie/ --prefix PIE """ +from __future__ import annotations import argparse diff --git a/scripts/add_rule.py b/scripts/add_rule.py index 43bfddfade..1fb271aa85 100755 --- a/scripts/add_rule.py +++ b/scripts/add_rule.py @@ -9,6 +9,7 @@ Example usage: --code 807 \ --linter flake8-pie """ +from __future__ import annotations import argparse import subprocess diff --git a/scripts/check_docs_formatted.py b/scripts/check_docs_formatted.py index 336ce040eb..7256f28c7c 100755 --- a/scripts/check_docs_formatted.py +++ b/scripts/check_docs_formatted.py @@ -1,17 +1,22 @@ #!/usr/bin/env python3 """Check code snippets in docs are formatted by black.""" +from __future__ import annotations + import argparse import os import re import textwrap -from collections.abc import Sequence from pathlib import Path from re import Match +from typing import TYPE_CHECKING import black from black.mode import Mode, TargetVersion from black.parsing import InvalidInput +if TYPE_CHECKING: + from collections.abc import Sequence + TARGET_VERSIONS = ["py37", "py38", "py39", "py310", "py311"] SNIPPED_RE = re.compile( r"(?P^(?P *)```\s*python\n)" diff --git a/scripts/ecosystem_all_check.py b/scripts/ecosystem_all_check.py index 9f509c57ac..96107c7365 100644 --- a/scripts/ecosystem_all_check.py +++ b/scripts/ecosystem_all_check.py @@ -3,13 +3,14 @@ panics, autofix errors and similar problems. It's a less elaborate, more hacky version of check_ecosystem.py """ +from __future__ import annotations import json import subprocess import sys from pathlib import Path from subprocess import CalledProcessError -from typing import NamedTuple, Optional +from typing import NamedTuple from tqdm import tqdm @@ -19,7 +20,7 @@ class Repository(NamedTuple): org: str repo: str - ref: Optional[str] + ref: str | None def main() -> None: diff --git a/scripts/generate_known_standard_library.py b/scripts/generate_known_standard_library.py index 7fd7ae7222..5d9c66c58b 100644 --- a/scripts/generate_known_standard_library.py +++ b/scripts/generate_known_standard_library.py @@ -5,6 +5,7 @@ Source: Only the generation of the file has been modified for use in this project. """ +from __future__ import annotations from pathlib import Path diff --git a/scripts/generate_mkdocs.py b/scripts/generate_mkdocs.py index 5793858e91..8d0b92b882 100644 --- a/scripts/generate_mkdocs.py +++ b/scripts/generate_mkdocs.py @@ -1,4 +1,6 @@ """Generate an MkDocs-compatible `docs` and `mkdocs.yml` from the README.md.""" +from __future__ import annotations + import argparse import re import shutil diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index ca7d45e508..7f4282c4c3 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -2,7 +2,7 @@ name = "scripts" version = "0.0.1" dependencies = ["sphinx"] -requires-python = ">=3.9" +requires-python = ">=3.8" [tool.black] line-length = 88 @@ -21,5 +21,8 @@ ignore = [ "FBT", # flake8-boolean-trap ] +[tool.ruff.isort] +required-imports = ["from __future__ import annotations"] + [tool.ruff.pydocstyle] convention = "pep257" diff --git a/scripts/transform_readme.py b/scripts/transform_readme.py index 963f55ca3f..7170eef20f 100644 --- a/scripts/transform_readme.py +++ b/scripts/transform_readme.py @@ -4,6 +4,8 @@ By default, we assume that our README.md will be rendered on GitHub. However, di targets have different strategies for rendering light- and dark-mode images. This script adjusts the images in the README.md to support the given target. """ +from __future__ import annotations + import argparse from pathlib import Path diff --git a/scripts/update_ambiguous_characters.py b/scripts/update_ambiguous_characters.py index 4243313e6e..27a06fd039 100644 --- a/scripts/update_ambiguous_characters.py +++ b/scripts/update_ambiguous_characters.py @@ -1,4 +1,6 @@ """Generate the confusables.rs file from the VS Code ambiguous.json file.""" +from __future__ import annotations + import json import subprocess from pathlib import Path diff --git a/scripts/update_schemastore.py b/scripts/update_schemastore.py index 9c79d7dc42..685fa7bbff 100644 --- a/scripts/update_schemastore.py +++ b/scripts/update_schemastore.py @@ -4,6 +4,7 @@ This script will clone astral-sh/schemastore, update the schema and push the cha to a new branch tagged with the ruff git hash. You should see a URL to create the PR to schemastore in the CLI. """ +from __future__ import annotations import json from pathlib import Path