1
1
import argparse
2
2
import ast
3
+ import enum
3
4
import optparse
4
5
from collections import deque
5
- from collections .abc import Callable , Generator , Iterable , Sequence
6
- from typing import Final , Literal
6
+ from collections .abc import Callable , Generator , Iterable , Iterator , Sequence
7
+ from typing import Any , Final , Literal
7
8
from typing_extensions import Self
8
9
9
10
__version__ : Final [str ]
@@ -13,22 +14,30 @@ METACLASS_BASES: Final[frozenset[Literal["type", "ABCMeta"]]]
13
14
METHOD_CONTAINER_NODES : Final [set [ast .AST ]]
14
15
FUNC_NODES : Final [tuple [type [ast .FunctionDef ], type [ast .AsyncFunctionDef ]]]
15
16
16
- class _ASTCheckMeta (type ):
17
- codes : tuple [str , ...]
17
+ class BaseASTCheck :
18
18
all : list [BaseASTCheck ]
19
- def __init__ (cls , class_name : str , bases : tuple [object , ...], namespace : Iterable [str ]) -> None : ...
20
-
21
- class BaseASTCheck (metaclass = _ASTCheckMeta ):
22
19
codes : tuple [str , ...]
23
- all : list [BaseASTCheck ]
20
+ # Per convention, unknown kwargs are passed to the super-class. See there for the types.
21
+ def __init_subclass__ (cls , ** kwargs : Any ) -> None : ...
24
22
def err (self , node : ast .AST , code : str , ** kwargs : str ) -> tuple [int , int , str , Self ]: ...
25
23
24
+ class NameSet (frozenset [str ]):
25
+ def __new__ (cls , iterable : Iterable [str ]) -> Self : ...
26
+ def __contains__ (self , item : object , / ) -> bool : ...
27
+
28
+ @enum .unique
29
+ class FunctionType (enum .Enum ):
30
+ CLASSMETHOD = "classmethod"
31
+ STATICMETHOD = "staticmethod"
32
+ FUNCTION = "function"
33
+ METHOD = "method"
34
+
26
35
class NamingChecker :
27
36
name : str
28
37
version : str
29
38
visitors : Sequence [BaseASTCheck ]
30
- decorator_to_type : dict [str , Literal [ "classmethod" , "staticmethod" ] ]
31
- ignore_names : frozenset [ str ]
39
+ decorator_to_type : dict [str , FunctionType ]
40
+ ignored : NameSet
32
41
def __init__ (self , tree : ast .AST , filename : str ) -> None : ...
33
42
@classmethod
34
43
def add_options (cls , parser : optparse .OptionParser ) -> None : ...
@@ -38,105 +47,105 @@ class NamingChecker:
38
47
def visit_tree (self , node : ast .AST , parents : deque [ast .AST ]) -> Generator [tuple [int , int , str , Self ]]: ...
39
48
def visit_node (self , node : ast .AST , parents : Sequence [ast .AST ]) -> Generator [tuple [int , int , str , Self ]]: ...
40
49
def tag_class_functions (self , cls_node : ast .ClassDef ) -> None : ...
41
- def set_function_nodes_types (self , nodes : Iterable [ast .AST ], ismetaclass : bool , late_decoration : dict [str , str ]) -> None : ...
50
+ def set_function_nodes_types (
51
+ self , nodes : Iterator [ast .AST ], ismetaclass : bool , late_decoration : dict [str , FunctionType ]
52
+ ) -> None : ...
42
53
@classmethod
43
54
def find_decorator_name (cls , d : ast .Expr ) -> str : ...
44
55
@staticmethod
45
56
def find_global_defs (func_def_node : ast .AST ) -> None : ...
46
57
47
58
class ClassNameCheck (BaseASTCheck ):
48
59
codes : tuple [Literal ["N801" ], Literal ["N818" ]]
49
- N801 : str
50
- N818 : str
60
+ N801 : Final [ str ]
61
+ N818 : Final [ str ]
51
62
@classmethod
52
63
def get_classdef (cls , name : str , parents : Sequence [ast .AST ]) -> ast .ClassDef | None : ...
53
64
@classmethod
54
65
def superclass_names (cls , name : str , parents : Sequence [ast .AST ], _names : set [str ] | None = None ) -> set [str ]: ...
55
66
def visit_classdef (
56
- self , node : ast .ClassDef , parents : Sequence [ast .AST ], ignore : Iterable [ str ] | None = None
67
+ self , node : ast .ClassDef , parents : Sequence [ast .AST ], ignored : NameSet
57
68
) -> Generator [tuple [int , int , str , Self ]]: ...
58
69
59
70
class FunctionNameCheck (BaseASTCheck ):
60
71
codes : tuple [Literal ["N802" ], Literal ["N807" ]]
61
- N802 : str
62
- N807 : str
72
+ N802 : Final [ str ]
73
+ N807 : Final [ str ]
63
74
@staticmethod
64
75
def has_override_decorator (node : ast .FunctionDef | ast .AsyncFunctionDef ) -> bool : ...
65
76
def visit_functiondef (
66
- self , node : ast .FunctionDef , parents : Sequence [ast .AST ], ignore : Iterable [ str ] | None = None
77
+ self , node : ast .FunctionDef , parents : Sequence [ast .AST ], ignored : NameSet
67
78
) -> Generator [tuple [int , int , str , Self ]]: ...
68
79
def visit_asyncfunctiondef (
69
- self , node : ast .AsyncFunctionDef , parents : Sequence [ast .AST ], ignore : Iterable [ str ] | None = None
80
+ self , node : ast .AsyncFunctionDef , parents : Sequence [ast .AST ], ignored : NameSet
70
81
) -> Generator [tuple [int , int , str , Self ]]: ...
71
82
72
83
class FunctionArgNamesCheck (BaseASTCheck ):
73
84
codes : tuple [Literal ["N803" ], Literal ["N804" ], Literal ["N805" ]]
74
- N803 : str
75
- N804 : str
76
- N805 : str
85
+ N803 : Final [ str ]
86
+ N804 : Final [ str ]
87
+ N805 : Final [ str ]
77
88
def visit_functiondef (
78
- self , node : ast .FunctionDef , parents : Sequence [ast .AST ], ignore : Iterable [ str ] | None = None
89
+ self , node : ast .FunctionDef , parents : Sequence [ast .AST ], ignored : NameSet
79
90
) -> Generator [tuple [int , int , str , Self ]]: ...
80
91
def visit_asyncfunctiondef (
81
- self , node : ast .AsyncFunctionDef , parents : Sequence [ast .AST ], ignore : Iterable [ str ] | None = None
92
+ self , node : ast .AsyncFunctionDef , parents : Sequence [ast .AST ], ignored : NameSet
82
93
) -> Generator [tuple [int , int , str , Self ]]: ...
83
94
84
95
class ImportAsCheck (BaseASTCheck ):
85
96
codes : tuple [Literal ["N811" ], Literal ["N812" ], Literal ["N813" ], Literal ["N814" ], Literal ["N817" ]]
86
- N811 : str
87
- N812 : str
88
- N813 : str
89
- N814 : str
90
- N817 : str
97
+ N811 : Final [ str ]
98
+ N812 : Final [ str ]
99
+ N813 : Final [ str ]
100
+ N814 : Final [ str ]
101
+ N817 : Final [ str ]
91
102
def visit_importfrom (
92
- self , node : ast .ImportFrom , parents : Sequence [ast .AST ], ignore : Iterable [ str ] | None = None
103
+ self , node : ast .ImportFrom , parents : Sequence [ast .AST ], ignored : NameSet
93
104
) -> Generator [tuple [int , int , str , Self ]]: ...
94
105
def visit_import (
95
- self , node : ast .Import , parents : Sequence [ast .AST ], ignore : Iterable [ str ] | None = None
106
+ self , node : ast .Import , parents : Sequence [ast .AST ], ignored : NameSet
96
107
) -> Generator [tuple [int , int , str , Self ]]: ...
97
108
98
109
class VariablesCheck (BaseASTCheck ):
99
110
codes : tuple [Literal ["N806" ], Literal ["N815" ], Literal ["N816" ]]
100
- N806 : str
101
- N815 : str
102
- N816 : str
111
+ N806 : Final [ str ]
112
+ N815 : Final [ str ]
113
+ N816 : Final [ str ]
103
114
@staticmethod
104
115
def is_namedtupe (node_value : ast .AST ) -> bool : ...
105
116
def visit_assign (
106
- self , node : ast .Assign , parents : Sequence [ast .AST ], ignore : Iterable [ str ] | None = None
117
+ self , node : ast .Assign , parents : Sequence [ast .AST ], ignored : NameSet
107
118
) -> Generator [tuple [int , int , str , Self ]]: ...
108
119
def visit_namedexpr (
109
- self , node : ast .NamedExpr , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
120
+ self , node : ast .NamedExpr , parents : Sequence [ast .AST ], ignored : NameSet
110
121
) -> Generator [tuple [int , int , str , Self ]]: ...
111
122
def visit_annassign (
112
- self , node : ast .AnnAssign , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
123
+ self , node : ast .AnnAssign , parents : Sequence [ast .AST ], ignored : NameSet
113
124
) -> Generator [tuple [int , int , str , Self ]]: ...
114
125
def visit_with (
115
- self , node : ast .With , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
126
+ self , node : ast .With , parents : Sequence [ast .AST ], ignored : NameSet
116
127
) -> Generator [tuple [int , int , str , Self ]]: ...
117
128
def visit_asyncwith (
118
- self , node : ast .AsyncWith , parents : Sequence [ast .AST ], ignore : Iterable [str ]
119
- ) -> Generator [tuple [int , int , str , Self ]]: ...
120
- def visit_for (
121
- self , node : ast .For , parents : Sequence [ast .AST ], ignore : Iterable [str ]
129
+ self , node : ast .AsyncWith , parents : Sequence [ast .AST ], ignored : NameSet
122
130
) -> Generator [tuple [int , int , str , Self ]]: ...
131
+ def visit_for (self , node : ast .For , parents : Sequence [ast .AST ], ignored : NameSet ) -> Generator [tuple [int , int , str , Self ]]: ...
123
132
def visit_asyncfor (
124
- self , node : ast .AsyncFor , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
133
+ self , node : ast .AsyncFor , parents : Sequence [ast .AST ], ignored : NameSet
125
134
) -> Generator [tuple [int , int , str , Self ]]: ...
126
135
def visit_excepthandler (
127
- self , node : ast .ExceptHandler , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
136
+ self , node : ast .ExceptHandler , parents : Sequence [ast .AST ], ignored : NameSet
128
137
) -> Generator [tuple [int , int , str , Self ]]: ...
129
138
def visit_generatorexp (
130
- self , node : ast .GeneratorExp , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
139
+ self , node : ast .GeneratorExp , parents : Sequence [ast .AST ], ignored : NameSet
131
140
) -> Generator [tuple [int , int , str , Self ]]: ...
132
141
def visit_listcomp (
133
- self , node : ast .ListComp , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
142
+ self , node : ast .ListComp , parents : Sequence [ast .AST ], ignored : NameSet
134
143
) -> Generator [tuple [int , int , str , Self ]]: ...
135
144
def visit_dictcomp (
136
- self , node : ast .DictComp , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
145
+ self , node : ast .DictComp , parents : Sequence [ast .AST ], ignored : NameSet
137
146
) -> Generator [tuple [int , int , str , Self ]]: ...
138
147
def visit_setcomp (
139
- self , node : ast .SetComp , parents : Sequence [ast .AST ], ignore : Iterable [ str ]
148
+ self , node : ast .SetComp , parents : Sequence [ast .AST ], ignored : NameSet
140
149
) -> Generator [tuple [int , int , str , Self ]]: ...
141
150
@staticmethod
142
151
def global_variable_check (name : str ) -> Literal ["N816" ] | None : ...
@@ -145,4 +154,10 @@ class VariablesCheck(BaseASTCheck):
145
154
@staticmethod
146
155
def function_variable_check (func : Callable [..., object ], var_name : str ) -> Literal ["N806" ] | None : ...
147
156
157
+ class TypeVarNameCheck (BaseASTCheck ):
158
+ N808 : Final [str ]
159
+ def visit_module (
160
+ self , node : ast .Module , parents : Sequence [ast .AST ], ignored : NameSet
161
+ ) -> Generator [tuple [int , int , str , Self ]]: ...
162
+
148
163
def is_mixed_case (name : str ) -> bool : ...
0 commit comments