Skip to content

Commit f1230fc

Browse files
Fix new type error (#489)
python/typeshed#11880 correctly points out that not all AST nodes have a line and column number.
1 parent 9c4a5d8 commit f1230fc

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

pyi.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from functools import cached_property, partial
1515
from itertools import chain, groupby, zip_longest
1616
from keyword import iskeyword
17-
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, Union
17+
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple, Protocol, Union
1818

1919
from flake8 import checker
2020
from flake8.options.manager import OptionManager
@@ -62,6 +62,11 @@ class TypeVarInfo(NamedTuple):
6262
name: str
6363

6464

65+
class NodeWithLocation(Protocol):
66+
lineno: int
67+
col_offset: int
68+
69+
6570
def all_equal(iterable: Iterable[object]) -> bool:
6671
"""Returns True if all the elements are equal to each other.
6772
@@ -2245,7 +2250,7 @@ def check_arg_default(self, arg: ast.arg, default: ast.expr | None) -> None:
22452250
if default is not None and not _is_valid_default_value_with_annotation(default):
22462251
self.error(default, (Y014 if arg.annotation is None else Y011))
22472252

2248-
def error(self, node: ast.AST, message: str) -> None:
2253+
def error(self, node: NodeWithLocation, message: str) -> None:
22492254
self.errors.append(Error(node.lineno, node.col_offset, message, PyiTreeChecker))
22502255

22512256
def _check_for_unused_things(self) -> None:

0 commit comments

Comments
 (0)