File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change 29
29
30
30
31
31
class ArgumentConcreteTypeHintChecker (ast .NodeVisitor ):
32
+ _concrete_type_hint_error_codes : dict [str , ErrorMessage ] = {
33
+ "list" : KTH101 ,
34
+ "tuple" : KTH102 ,
35
+ "set" : KTH103 ,
36
+ "dict" : KTH104 ,
37
+ }
38
+
32
39
def __init__ (self ) -> None :
33
40
self .errors : list [tuple [LineNumber , ColumnOffset , ErrorMessage ]] = []
34
41
35
42
def visit_arg (self , node : ast .arg ) -> None :
36
43
if node .annotation is not None :
37
44
annotation : ast .expr = node .annotation
38
- if hasattr (annotation , "value" ):
39
- if annotation .value .id == "list" :
40
- self .errors .append ((node .lineno , node .col_offset , KTH101 ))
41
- elif annotation .value .id == "tuple" :
42
- self .errors .append ((node .lineno , node .col_offset , KTH102 ))
43
- elif annotation .value .id == "set" :
44
- self .errors .append ((node .lineno , node .col_offset , KTH103 ))
45
- elif annotation .value .id == "dict" :
46
- self .errors .append ((node .lineno , node .col_offset , KTH104 ))
45
+ if (
46
+ hasattr (annotation , "value" )
47
+ and annotation .value .id in self ._concrete_type_hint_error_codes
48
+ ):
49
+ self .errors .append (
50
+ (
51
+ node .lineno ,
52
+ node .col_offset ,
53
+ self ._concrete_type_hint_error_codes [
54
+ annotation .value .id
55
+ ],
56
+ )
57
+ )
47
58
self .generic_visit (node )
48
59
49
60
You can’t perform that action at this time.
0 commit comments