@@ -18,14 +18,33 @@ def __init__(self, filepath, output):
1818 self .output = output
1919
2020 def visit_FunctionDef (self , node ):
21- if any ("delete_parameter" in ast .unparse (line ) for line in node .decorator_list ):
22- parents = []
23- if hasattr (node , "parent" ):
24- parent = node .parent
25- while hasattr (parent , "parent" ) and not isinstance (parent , ast .Module ):
26- parents .insert (0 , parent .name )
27- parent = parent .parent
28- self .output .write (f"{ '.' .join (self .context + parents )} .{ node .name } \n " )
21+ # delete_parameter adds a private sentinel value that leaks
22+ # we do not want that sentinel value in the type hints but it breaks typing
23+ # Does not apply to variadic arguments (args/kwargs)
24+ for dec in node .decorator_list :
25+ if "delete_parameter" in ast .unparse (dec ):
26+ deprecated_arg = dec .args [1 ].value
27+ if (
28+ node .args .vararg is not None
29+ and node .args .vararg .arg == deprecated_arg
30+ ):
31+ continue
32+ if (
33+ node .args .kwarg is not None
34+ and node .args .kwarg .arg == deprecated_arg
35+ ):
36+ continue
37+
38+ parents = []
39+ if hasattr (node , "parent" ):
40+ parent = node .parent
41+ while hasattr (parent , "parent" ) and not isinstance (
42+ parent , ast .Module
43+ ):
44+ parents .insert (0 , parent .name )
45+ parent = parent .parent
46+ self .output .write (f"{ '.' .join (self .context + parents )} .{ node .name } \n " )
47+ break
2948
3049 def visit_ClassDef (self , node ):
3150 for dec in node .decorator_list :
0 commit comments