@@ -85,6 +85,36 @@ class State:
8585}
8686
8787
88+ class _SafeAction (argparse .Action ):
89+ def __call__ (
90+ self ,
91+ parser : argparse .ArgumentParser ,
92+ namespace : argparse .Namespace ,
93+ values : object ,
94+ option_string : Optional [str ] = ...,
95+ ) -> None :
96+ namespace .none_return = True
97+ namespace .scalar_return = True
98+ namespace .annotate_magics = True
99+
100+
101+ class _AggressiveAction (_SafeAction ):
102+ def __call__ (
103+ self ,
104+ parser : argparse .ArgumentParser ,
105+ namespace : argparse .Namespace ,
106+ values : object ,
107+ option_string : Optional [str ] = ...,
108+ ) -> None :
109+ super ().__call__ (parser , namespace , values , option_string )
110+ namespace .bool_param = True
111+ namespace .int_param = True
112+ namespace .float_param = True
113+ namespace .str_param = True
114+ namespace .bytes_param = True
115+ namespace .annotate_imprecise_magics = True
116+
117+
88118class AutotypeCommand (VisitorBasedCodemodCommand ):
89119
90120 # Add a description so that future codemodders can see what this does.
@@ -187,6 +217,18 @@ def add_args(arg_parser: argparse.ArgumentParser) -> None:
187217 default = False ,
188218 help = "Only apply pyanalyze suggestions that do not require imports" ,
189219 )
220+ arg_parser .add_argument (
221+ "--safe" ,
222+ action = _SafeAction ,
223+ help = "Apply all safe transformations" ,
224+ nargs = "?" ,
225+ )
226+ arg_parser .add_argument (
227+ "--aggressive" ,
228+ action = _AggressiveAction ,
229+ help = "Apply all transformations that do not require arguments" ,
230+ nargs = "?" ,
231+ )
190232
191233 def __init__ (
192234 self ,
@@ -205,6 +247,8 @@ def __init__(
205247 int_param : bool = False ,
206248 pyanalyze_report : Optional [str ] = None ,
207249 only_without_imports : bool = False ,
250+ safe : bool = False ,
251+ aggressive : bool = False ,
208252 ) -> None :
209253 super ().__init__ (context )
210254 param_type_pairs = [
0 commit comments