Skip to content

Commit

Permalink
Merge pull request #280 from asottile/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
asottile authored Jul 28, 2024
2 parents f8af4ed + a07ae32 commit a0f3964
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ repos:
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.11.0
hooks:
- id: mypy
10 changes: 9 additions & 1 deletion add_trailing_comma/_ast_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ast
import warnings
from typing import Protocol

from tokenize_rt import Offset

Expand All @@ -12,5 +13,12 @@ def ast_parse(contents_text: str) -> ast.Module:
return ast.parse(contents_text.encode())


def ast_to_offset(node: ast.AST) -> Offset:
class _HasOffsetInfo(Protocol):
@property
def lineno(self) -> int: ...
@property
def col_offset(self) -> int: ...


def ast_to_offset(node: _HasOffsetInfo) -> Offset:
return Offset(node.lineno, node.col_offset)
3 changes: 2 additions & 1 deletion add_trailing_comma/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class State(NamedTuple):
TokenFunc = Callable[[int, list[Token]], None]
ASTFunc = Callable[[State, AST_T], Iterable[tuple[Offset, TokenFunc]]]

FUNCS = collections.defaultdict(list)
FUNCS: ASTCallbackMapping # python/mypy#17566
FUNCS = collections.defaultdict(list) # type: ignore[assignment]


def register(tp: type[AST_T]) -> Callable[[ASTFunc[AST_T]], ASTFunc[AST_T]]:
Expand Down
2 changes: 1 addition & 1 deletion add_trailing_comma/_plugins/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def visit_Call(
state: State,
node: ast.Call,
) -> Iterable[tuple[Offset, TokenFunc]]:
argnodes = [*node.args, *node.keywords]
argnodes: list[ast.expr | ast.keyword] = [*node.args, *node.keywords]
arg_offsets = set()
for argnode in argnodes:
offset = ast_to_offset(argnode)
Expand Down
2 changes: 1 addition & 1 deletion add_trailing_comma/_plugins/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def visit_ClassDef(
# starargs are allowed in py3 class definitions, py35+ allows trailing
# commas. py34 does not, but adding an option for this very obscure
# case seems not worth it.
args = [*node.bases, *node.keywords]
args: list[ast.expr | ast.keyword] = [*node.bases, *node.keywords]
arg_offsets = {ast_to_offset(arg) for arg in args}

if arg_offsets:
Expand Down

0 comments on commit a0f3964

Please sign in to comment.