Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 9 additions & 36 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/asottile/reorder-python-imports
rev: v3.13.0
hooks:
- id: reorder-python-imports
args:
- --py39-plus
- --add-import
- from __future__ import annotations

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args:
- --py39-plus

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
args:
- --py36-plus

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.19
rev: v0.25
hooks:
- id: validate-pyproject

- repo: https://github.com/psf/black
rev: "24.8.0"
hooks:
- id: black

- repo: https://github.com/pycqa/autoflake
rev: v2.3.1
hooks:
- id: autoflake

- repo: https://github.com/fsouza/mirrors-pyright
rev: v1.1.381
rev: v1.1.275
hooks:
- id: pyright

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
hooks:
- id: ruff-check
- id: ruff-format
28 changes: 14 additions & 14 deletions autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""Removes unused imports and unused variables as reported by pyflakes."""

from __future__ import annotations

import ast
Expand All @@ -36,20 +37,19 @@
import sys
import sysconfig
import tokenize
from collections.abc import Callable
from collections.abc import Iterable
from collections.abc import Mapping
from collections.abc import MutableMapping
from collections.abc import Sequence
from typing import Any
from typing import Callable
from typing import cast
from typing import IO

import pyflakes.api
import pyflakes.messages
import pyflakes.reporter


__version__ = "2.3.1"


Expand Down Expand Up @@ -496,7 +496,7 @@ def filter_from_import(line: str, unused_module: Iterable[str]) -> str:
Return line without unused import modules, or `pass` if all of the
module in import is unused.
"""
(indentation, imports) = re.split(
indentation, imports = re.split(
pattern=r"\bimport\b",
string=line,
maxsplit=1,
Expand Down Expand Up @@ -533,7 +533,7 @@ def break_up_import(line: str) -> str:
if not newline:
return line

(indentation, imports) = re.split(
indentation, imports = re.split(
pattern=r"\bimport\b",
string=line,
maxsplit=1,
Expand Down Expand Up @@ -578,8 +578,7 @@ def filter_code(
undefined_names: list[str] = []
if expand_star_imports and not (
# See explanations in #18.
re.search(r"\b__all__\b", source)
or re.search(r"\bdel\b", source)
re.search(r"\b__all__\b", source) or re.search(r"\bdel\b", source)
):
marked_star_import_line_numbers = frozenset(
star_import_used_line_numbers(messages),
Expand Down Expand Up @@ -1386,7 +1385,7 @@ def _main(
imports_group.add_argument(
"--remove-all-unused-imports",
action="store_true",
help="remove all unused imports (not just those from " "the standard library)",
help="remove all unused imports (not just those from the standard library)",
)

parser.add_argument(
Expand All @@ -1401,12 +1400,12 @@ def _main(
type=int,
metavar="n",
default=0,
help="number of parallel jobs; " "match CPU count if value is 0 (default: 0)",
help="number of parallel jobs; match CPU count if value is 0 (default: 0)",
)
parser.add_argument(
"--exclude",
metavar="globs",
help="exclude file/directory names that match these " "comma-separated globs",
help="exclude file/directory names that match these comma-separated globs",
)
parser.add_argument(
"--expand-star-imports",
Expand All @@ -1420,7 +1419,7 @@ def _main(
parser.add_argument(
"--ignore-init-module-imports",
action="store_true",
help="exclude __init__.py when removing unused " "imports",
help="exclude __init__.py when removing unused imports",
)
parser.add_argument(
"--remove-duplicate-keys",
Expand All @@ -1435,7 +1434,7 @@ def _main(
parser.add_argument(
"--remove-rhs-for-unused-variables",
action="store_true",
help="remove RHS of statements when removing unused " "variables (unsafe)",
help="remove RHS of statements when removing unused variables (unsafe)",
)
parser.add_argument(
"--ignore-pass-statements",
Expand Down Expand Up @@ -1463,7 +1462,7 @@ def _main(
action="count",
dest="verbosity",
default=0,
help="print more verbose logs (you can " "repeat `-v` to make it more verbose)",
help="print more verbose logs (you can repeat `-v` to make it more verbose)",
)
parser.add_argument(
"--stdin-display-name",
Expand Down Expand Up @@ -1518,8 +1517,9 @@ def _main(
if not success:
return 1

if args["remove_rhs_for_unused_variables"] and not (
args["remove_unused_variables"]
if (
args["remove_rhs_for_unused_variables"]
and not (args["remove_unused_variables"])
):
_LOGGER.error(
"Using --remove-rhs-for-unused-variables only makes sense when "
Expand Down
Loading