Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#9399)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and Pierre-Sassoulas authored Jan 30, 2024
1 parent a87cb4c commit fa2cffb
Show file tree
Hide file tree
Showing 38 changed files with 358 additions and 389 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
doc/data/messages/m/missing-final-newline/bad/crlf.py
)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.9"
rev: "v0.1.14"
hooks:
- id: ruff
args: ["--fix"]
Expand All @@ -39,7 +39,7 @@ repos:
- id: isort
exclude: doc/data/messages/
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
args: [--safe, --quiet]
Expand Down Expand Up @@ -158,7 +158,7 @@ repos:
setup.cfg
)$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.6
rev: 1.7.7
hooks:
- id: bandit
args: ["-r", "-lll"]
Expand Down
3 changes: 1 addition & 2 deletions doc/data/messages/a/arguments-renamed/bad.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ def brew(self, ingredient_name: str):
print(f"Brewing a {type(self)} with {ingredient_name}")


class Apple(Fruit):
...
class Apple(Fruit): ...


class Orange(Fruit):
Expand Down
3 changes: 1 addition & 2 deletions doc/data/messages/a/arguments-renamed/good.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ def brew(self, ingredient_name: str):
print(f"Brewing a {type(self)} with {ingredient_name}")


class Apple(Fruit):
...
class Apple(Fruit): ...


class Orange(Fruit):
Expand Down
3 changes: 1 addition & 2 deletions doc/data/messages/b/broken-collections-callable/good.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Callable, Optional


def func() -> Optional[Callable[[int], None]]:
...
def func() -> Optional[Callable[[int], None]]: ...
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cats: (int | str)
cats: int | str
3 changes: 1 addition & 2 deletions doc/data/messages/d/duplicate-code/good/apple.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fruit import Fruit


class Apple(Fruit):
...
class Apple(Fruit): ...
1 change: 1 addition & 0 deletions doc/data/messages/m/missing-module-docstring/good.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module providing a function printing python version."""

import sys


Expand Down
3 changes: 1 addition & 2 deletions doc/data/messages/u/unused-wildcard-import/bad.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abc import * # [unused-wildcard-import]


class Animal(ABC):
...
class Animal(ABC): ...
3 changes: 1 addition & 2 deletions doc/data/messages/u/unused-wildcard-import/good.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abc import ABC


class Animal(ABC):
...
class Animal(ABC): ...
3 changes: 1 addition & 2 deletions doc/data/messages/u/use-symbolic-message-instead/good.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@


# pylint: disable-next=redefined-outer-name
def eat(fruit_name: str):
...
def eat(fruit_name: str): ...
3 changes: 1 addition & 2 deletions doc/data/messages/u/useless-object-inheritance/good.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
class Banana:
...
class Banana: ...
3 changes: 1 addition & 2 deletions doc/data/messages/u/useless-suppression/good.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fruit_counter = 0


def eat(fruit_name: str):
...
def eat(fruit_name: str): ...
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
@final # [using-final-decorator-in-unsupported-version]
class Playtypus(Animal):
@final # [using-final-decorator-in-unsupported-version]
def lay_egg(self):
...
def lay_egg(self): ...
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
class Playtypus(Animal):
def lay_egg(self):
...
def lay_egg(self): ...
6 changes: 3 additions & 3 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ def leave_module(self, _: nodes.Module) -> None:
for all_groups in self._bad_names.values():
if len(all_groups) < 2:
continue
groups: collections.defaultdict[
int, list[list[_BadNamesTuple]]
] = collections.defaultdict(list)
groups: collections.defaultdict[int, list[list[_BadNamesTuple]]] = (
collections.defaultdict(list)
)
min_warnings = sys.maxsize
prevalent_group, _ = max(all_groups.items(), key=lambda item: len(item[1]))
for group in all_groups.values():
Expand Down
136 changes: 68 additions & 68 deletions pylint/checkers/design_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,74 +21,74 @@
if TYPE_CHECKING:
from pylint.lint import PyLinter

MSGS: dict[
str, MessageDefinitionTuple
] = { # pylint: disable=consider-using-namedtuple-or-dataclass
"R0901": (
"Too many ancestors (%s/%s)",
"too-many-ancestors",
"Used when class has too many parent classes, try to reduce "
"this to get a simpler (and so easier to use) class.",
),
"R0902": (
"Too many instance attributes (%s/%s)",
"too-many-instance-attributes",
"Used when class has too many instance attributes, try to reduce "
"this to get a simpler (and so easier to use) class.",
),
"R0903": (
"Too few public methods (%s/%s)",
"too-few-public-methods",
"Used when class has too few public methods, so be sure it's "
"really worth it.",
),
"R0904": (
"Too many public methods (%s/%s)",
"too-many-public-methods",
"Used when class has too many public methods, try to reduce "
"this to get a simpler (and so easier to use) class.",
),
"R0911": (
"Too many return statements (%s/%s)",
"too-many-return-statements",
"Used when a function or method has too many return statement, "
"making it hard to follow.",
),
"R0912": (
"Too many branches (%s/%s)",
"too-many-branches",
"Used when a function or method has too many branches, "
"making it hard to follow.",
),
"R0913": (
"Too many arguments (%s/%s)",
"too-many-arguments",
"Used when a function or method takes too many arguments.",
),
"R0914": (
"Too many local variables (%s/%s)",
"too-many-locals",
"Used when a function or method has too many local variables.",
),
"R0915": (
"Too many statements (%s/%s)",
"too-many-statements",
"Used when a function or method has too many statements. You "
"should then split it in smaller functions / methods.",
),
"R0916": (
"Too many boolean expressions in if statement (%s/%s)",
"too-many-boolean-expressions",
"Used when an if statement contains too many boolean expressions.",
),
"R0917": (
"Too many positional arguments in a function call.",
"too-many-positional",
"Will be implemented in https://github.com/pylint-dev/pylint/issues/9099,"
"msgid/symbol pair reserved for compatibility with ruff, "
"see https://github.com/astral-sh/ruff/issues/8946.",
),
}
MSGS: dict[str, MessageDefinitionTuple] = (
{ # pylint: disable=consider-using-namedtuple-or-dataclass
"R0901": (
"Too many ancestors (%s/%s)",
"too-many-ancestors",
"Used when class has too many parent classes, try to reduce "
"this to get a simpler (and so easier to use) class.",
),
"R0902": (
"Too many instance attributes (%s/%s)",
"too-many-instance-attributes",
"Used when class has too many instance attributes, try to reduce "
"this to get a simpler (and so easier to use) class.",
),
"R0903": (
"Too few public methods (%s/%s)",
"too-few-public-methods",
"Used when class has too few public methods, so be sure it's "
"really worth it.",
),
"R0904": (
"Too many public methods (%s/%s)",
"too-many-public-methods",
"Used when class has too many public methods, try to reduce "
"this to get a simpler (and so easier to use) class.",
),
"R0911": (
"Too many return statements (%s/%s)",
"too-many-return-statements",
"Used when a function or method has too many return statement, "
"making it hard to follow.",
),
"R0912": (
"Too many branches (%s/%s)",
"too-many-branches",
"Used when a function or method has too many branches, "
"making it hard to follow.",
),
"R0913": (
"Too many arguments (%s/%s)",
"too-many-arguments",
"Used when a function or method takes too many arguments.",
),
"R0914": (
"Too many local variables (%s/%s)",
"too-many-locals",
"Used when a function or method has too many local variables.",
),
"R0915": (
"Too many statements (%s/%s)",
"too-many-statements",
"Used when a function or method has too many statements. You "
"should then split it in smaller functions / methods.",
),
"R0916": (
"Too many boolean expressions in if statement (%s/%s)",
"too-many-boolean-expressions",
"Used when an if statement contains too many boolean expressions.",
),
"R0917": (
"Too many positional arguments in a function call.",
"too-many-positional",
"Will be implemented in https://github.com/pylint-dev/pylint/issues/9099,"
"msgid/symbol pair reserved for compatibility with ruff, "
"see https://github.com/astral-sh/ruff/issues/8946.",
),
}
)
SPECIAL_OBJ = re.compile("^_{2}[a-z]+_{2}$")
DATACLASSES_DECORATORS = frozenset({"dataclass", "attrs"})
DATACLASS_IMPORT = "dataclasses"
Expand Down
44 changes: 21 additions & 23 deletions pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ def __init__(self, linter: PyLinter) -> None:
self.import_graph: defaultdict[str, set[str]] = defaultdict(set)
self._imports_stack: list[tuple[ImportNode, str]] = []
self._first_non_import_node = None
self._module_pkg: dict[
Any, Any
] = {} # mapping of modules to the pkg they belong in
self._module_pkg: dict[Any, Any] = (
{}
) # mapping of modules to the pkg they belong in
self._allow_any_import_level: set[Any] = set()
self.reports = (
("RP0401", "External dependencies", self._report_external_dependencies),
Expand Down Expand Up @@ -612,13 +612,15 @@ def leave_module(self, node: nodes.Module) -> None:

def compute_first_non_import_node(
self,
node: nodes.If
| nodes.Expr
| nodes.Comprehension
| nodes.IfExp
| nodes.Assign
| nodes.AssignAttr
| nodes.Try,
node: (
nodes.If
| nodes.Expr
| nodes.Comprehension
| nodes.IfExp
| nodes.Assign
| nodes.AssignAttr
| nodes.Try
),
) -> None:
# if the node does not contain an import instruction, and if it is the
# first node of the module, keep a track of it (all the import positions
Expand All @@ -645,13 +647,9 @@ def compute_first_non_import_node(
return
self._first_non_import_node = node

visit_try = (
visit_assignattr
) = (
visit_assign
) = (
visit_ifexp
) = visit_comprehension = visit_expr = visit_if = compute_first_non_import_node
visit_try = visit_assignattr = visit_assign = visit_ifexp = visit_comprehension = (
visit_expr
) = visit_if = compute_first_non_import_node

def visit_functiondef(
self, node: nodes.FunctionDef | nodes.While | nodes.For | nodes.ClassDef
Expand Down Expand Up @@ -750,9 +748,7 @@ def _is_fallback_import(
return any(astroid.are_exclusive(import_node, node) for import_node in imports)

# pylint: disable = too-many-statements
def _check_imports_order(
self, _module_node: nodes.Module
) -> tuple[
def _check_imports_order(self, _module_node: nodes.Module) -> tuple[
list[tuple[ImportNode, str]],
list[tuple[ImportNode, str]],
list[tuple[ImportNode, str]],
Expand Down Expand Up @@ -1242,9 +1238,11 @@ def _check_toplevel(self, node: ImportNode) -> None:
return

module_names = [
f"{node.modname}.{name[0]}"
if isinstance(node, nodes.ImportFrom)
else name[0]
(
f"{node.modname}.{name[0]}"
if isinstance(node, nodes.ImportFrom)
else name[0]
)
for name in node.names
]

Expand Down
Loading

0 comments on commit fa2cffb

Please sign in to comment.