1- """
2- AST analyzer for `ast.ClassDef` records.
3- """
4- from typing import List , Union
1+ """AST analyzer for `ast.ClassDef` records."""
2+ from typing import Union
53
64import handsdown .ast_parser .smart_ast as ast
75from handsdown .ast_parser .analyzers .base_analyzer import BaseAnalyzer
86from handsdown .ast_parser .type_defs import ASTFunctionDef
97
108
119class ClassAnalyzer (BaseAnalyzer ):
12- """
13- AST analyzer for `ast.ClassDef` records.
14- """
10+ """AST analyzer for `ast.ClassDef` records."""
1511
1612 def __init__ (self ) -> None :
1713 super ().__init__ ()
18- self .base_nodes : List [ast .expr ] = []
19- self .decorator_nodes : List [ast .expr ] = []
20- self .method_nodes : List [ASTFunctionDef ] = []
21- self .attribute_nodes : List [Union [ast .Assign , ast .AnnAssign ]] = []
14+ self .base_nodes : list [ast .expr ] = []
15+ self .decorator_nodes : list [ast .expr ] = []
16+ self .method_nodes : list [ASTFunctionDef ] = []
17+ self .attribute_nodes : list [Union [ast .Assign , ast .AnnAssign ]] = []
2218
2319 def visit_ClassDef (self , node : ast .ClassDef ) -> None :
2420 """
@@ -37,6 +33,7 @@ def my_func():
3733
3834 Arguments:
3935 node -- AST node.
36+
4037 """
4138 for decorator_node in node .decorator_list :
4239 self .decorator_nodes .append (decorator_node )
@@ -51,14 +48,12 @@ def _visit_FunctionDef(self, node: ASTFunctionDef) -> None:
5148 docstring = self .get_docstring (node )
5249
5350 # skip private methods with no docstrings
54- if name .startswith ("_" ):
55- if not name .startswith ("__" ) and not docstring :
56- return
51+ if name .startswith ("_" ) and not name .startswith ("__" ) and not docstring :
52+ return
5753
5854 # skip magic methods with no docstrings
59- if name .startswith ("__" ):
60- if name != "__init__" and not docstring :
61- return
55+ if name .startswith ("__" ) and name != "__init__" and not docstring :
56+ return
6257
6358 self .method_nodes .append (node )
6459
@@ -77,6 +72,7 @@ def my_method(self, arg):
7772
7873 Arguments:
7974 node -- AST node.
75+
8076 """
8177 self ._visit_FunctionDef (node )
8278
@@ -95,6 +91,7 @@ async def my_method(self, arg):
9591
9692 Arguments:
9793 node -- AST node.
94+
9895 """
9996 self ._visit_FunctionDef (node )
10097
@@ -121,6 +118,7 @@ class MyClass:
121118
122119 Arguments:
123120 node -- AST node.
121+
124122 """
125123 # skip multiple assignments
126124 if len (node .targets ) != 1 :
@@ -154,6 +152,7 @@ class MyClass:
154152
155153 Arguments:
156154 node -- AST node.
155+
157156 """
158157 # skip complex assignments
159158 if not isinstance (node .target , ast .Name ):
@@ -173,4 +172,5 @@ def generic_visit(self, node: ast.AST) -> None:
173172
174173 Arguments:
175174 node -- AST node.
175+
176176 """
0 commit comments