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