@@ -108,6 +108,15 @@ def find(f: Callable[[V], bool], seq: Sequence[V]) -> V:
108108 return None
109109
110110
111+ def is_no_type_check_decorator (expr : ast35 .expr ) -> bool :
112+ if isinstance (expr , ast35 .Name ):
113+ return expr .id == 'no_type_check'
114+ elif isinstance (expr , ast35 .Attribute ):
115+ if isinstance (expr .value , ast35 .Name ):
116+ return expr .value .id == 'typing' and expr .attr == 'no_type_check'
117+ return False
118+
119+
111120class ASTConverter (ast35 .NodeTransformer ):
112121 def __init__ (self ,
113122 pyversion : Tuple [int , int ],
@@ -268,15 +277,21 @@ def visit_AsyncFunctionDef(self, n: ast35.AsyncFunctionDef) -> Union[FuncDef, De
268277 def do_func_def (self , n : Union [ast35 .FunctionDef , ast35 .AsyncFunctionDef ],
269278 is_coroutine : bool = False ) -> Union [FuncDef , Decorator ]:
270279 """Helper shared between visit_FunctionDef and visit_AsyncFunctionDef."""
271- args = self .transform_args (n .args , n .lineno )
280+ no_type_check = bool (n .decorator_list and
281+ any (is_no_type_check_decorator (d ) for d in n .decorator_list ))
282+
283+ args = self .transform_args (n .args , n .lineno , no_type_check = no_type_check )
272284
273285 arg_kinds = [arg .kind for arg in args ]
274286 arg_names = [arg .variable .name () for arg in args ] # type: List[Optional[str]]
275287 arg_names = [None if argument_elide_name (name ) else name for name in arg_names ]
276288 if special_function_elide_names (n .name ):
277289 arg_names = [None ] * len (arg_names )
278290 arg_types = None # type: List[Type]
279- if n .type_comment is not None :
291+ if no_type_check :
292+ arg_types = [None ] * len (args )
293+ return_type = None
294+ elif n .type_comment is not None :
280295 try :
281296 func_type_ast = ast35 .parse (n .type_comment , '<func_type>' , 'func_type' )
282297 assert isinstance (func_type_ast , ast35 .FunctionType )
@@ -298,7 +313,7 @@ def do_func_def(self, n: Union[ast35.FunctionDef, ast35.AsyncFunctionDef],
298313 arg_types .insert (0 , AnyType ())
299314 except SyntaxError :
300315 self .fail (TYPE_COMMENT_SYNTAX_ERROR , n .lineno , n .col_offset )
301- arg_types = [AnyType () for _ in args ]
316+ arg_types = [AnyType ()] * len ( args )
302317 return_type = AnyType ()
303318 else :
304319 arg_types = [a .type_annotation for a in args ]
@@ -312,7 +327,10 @@ def do_func_def(self, n: Union[ast35.FunctionDef, ast35.AsyncFunctionDef],
312327
313328 func_type = None
314329 if any (arg_types ) or return_type :
315- if len (arg_types ) > len (arg_kinds ):
330+ if len (arg_types ) != 1 and any (isinstance (t , EllipsisType ) for t in arg_types ):
331+ self .fail ("Ellipses cannot accompany other argument types "
332+ "in function type signature." , n .lineno , 0 )
333+ elif len (arg_types ) > len (arg_kinds ):
316334 self .fail ('Type signature has too many arguments' , n .lineno , 0 )
317335 elif len (arg_types ) < len (arg_kinds ):
318336 self .fail ('Type signature has too few arguments' , n .lineno , 0 )
@@ -356,9 +374,16 @@ def set_type_optional(self, type: Type, initializer: Expression) -> None:
356374 if isinstance (type , UnboundType ):
357375 type .optional = optional
358376
359- def transform_args (self , args : ast35 .arguments , line : int ) -> List [Argument ]:
377+ def transform_args (self ,
378+ args : ast35 .arguments ,
379+ line : int ,
380+ no_type_check : bool = False ,
381+ ) -> List [Argument ]:
360382 def make_argument (arg : ast35 .arg , default : Optional [ast35 .expr ], kind : int ) -> Argument :
361- arg_type = TypeConverter (self .errors , line = line ).visit (arg .annotation )
383+ if no_type_check :
384+ arg_type = None
385+ else :
386+ arg_type = TypeConverter (self .errors , line = line ).visit (arg .annotation )
362387 return Argument (Var (arg .arg ), arg_type , self .visit (default ), kind )
363388
364389 new_args = []
@@ -752,7 +777,7 @@ def is_star2arg(k: ast35.keyword) -> bool:
752777 return CallExpr (self .visit (n .func ),
753778 arg_types ,
754779 arg_kinds ,
755- cast ("List[str]" , [None for _ in n .args ] ) + [k .arg for k in n .keywords ])
780+ cast ("List[str]" , [None ] * len ( n .args ) ) + [k .arg for k in n .keywords ])
756781
757782 # Num(object n) -- a number as a PyObject.
758783 @with_line
0 commit comments