3232# stdlib
3333import ast
3434import sys
35- from typing import Any , Generator , List , Tuple , Type , Union
35+ from typing import Any , Generator , List , Set , Tuple , Type , Union
3636
3737# 3rd party
3838from consolekit .terminal_colours import Fore
@@ -64,11 +64,12 @@ class Visitor(ast.NodeVisitor):
6464
6565 found_all : bool #: Flag to indicate a ``__all__`` variable has been found in the AST.
6666 last_import : int #: The lineno of the last top-level import
67- members : List [str ] #: List of functions and classed defined in the AST
67+ members : Set [str ] #: List of functions and classed defined in the AST
68+ use_endlineno : bool
6869
6970 def __init__ (self , use_endlineno : bool = False ) -> None :
7071 self .found_all = False
71- self .members : List [ str ] = []
72+ self .members = set ()
7273 self .last_import = 0
7374 self .use_endlineno = use_endlineno
7475
@@ -91,8 +92,30 @@ def handle_def(self, node: Union[ast.FunctionDef, ast.AsyncFunctionDef, ast.Clas
9192 :param node: The node being visited.
9293 """
9394
94- if not node .name .startswith ('_' ):
95- self .members .append (node .name )
95+ decorators = []
96+
97+ for deco in node .decorator_list :
98+ if isinstance (deco , ast .Name ):
99+ decorators .append (deco .id )
100+ elif isinstance (deco , ast .Attribute ):
101+ parts = [deco .attr ]
102+
103+ # last_part = deco.value
104+ #
105+ # while True:
106+ # if isinstance(last_part, ast.Attribute):
107+ # parts.append(last_part.attr)
108+ # last_part = last_part.value
109+ # elif isinstance(last_part, ast.Name):
110+ # parts.append(last_part.id)
111+ # break
112+ # else:
113+ # break
114+
115+ decorators .append ('.' .join (reversed (parts )))
116+
117+ if not node .name .startswith ('_' ) and "overload" not in decorators :
118+ self .members .add (node .name )
96119
97120 def visit_FunctionDef (self , node : ast .FunctionDef ):
98121 """
@@ -236,7 +259,7 @@ def check_and_add_all(filename: PathPlus, quote_type: str = '"') -> int:
236259 if not visitor .members :
237260 return 0
238261
239- members = repr (visitor .members ).replace (bad_quote , quote_type )
262+ members = repr (sorted ( visitor .members ) ).replace (bad_quote , quote_type )
240263
241264 lines = filename .read_text ().split ('\n ' )
242265
0 commit comments