File tree 3 files changed +11
-3
lines changed
3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import ast
4
4
import warnings
5
+ from typing import Protocol
5
6
6
7
from tokenize_rt import Offset
7
8
@@ -12,5 +13,12 @@ def ast_parse(contents_text: str) -> ast.Module:
12
13
return ast .parse (contents_text .encode ())
13
14
14
15
15
- def ast_to_offset (node : ast .AST ) -> Offset :
16
+ class _HasOffsetInfo (Protocol ):
17
+ @property
18
+ def lineno (self ) -> int : ...
19
+ @property
20
+ def col_offset (self ) -> int : ...
21
+
22
+
23
+ def ast_to_offset (node : _HasOffsetInfo ) -> Offset :
16
24
return Offset (node .lineno , node .col_offset )
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ def visit_Call(
34
34
state : State ,
35
35
node : ast .Call ,
36
36
) -> Iterable [tuple [Offset , TokenFunc ]]:
37
- argnodes = [* node .args , * node .keywords ]
37
+ argnodes : list [ ast . expr | ast . keyword ] = [* node .args , * node .keywords ]
38
38
arg_offsets = set ()
39
39
for argnode in argnodes :
40
40
offset = ast_to_offset (argnode )
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ def visit_ClassDef(
37
37
# starargs are allowed in py3 class definitions, py35+ allows trailing
38
38
# commas. py34 does not, but adding an option for this very obscure
39
39
# case seems not worth it.
40
- args = [* node .bases , * node .keywords ]
40
+ args : list [ ast . expr | ast . keyword ] = [* node .bases , * node .keywords ]
41
41
arg_offsets = {ast_to_offset (arg ) for arg in args }
42
42
43
43
if arg_offsets :
You can’t perform that action at this time.
0 commit comments