@@ -366,10 +366,12 @@ class TypeChecker(NodeVisitor[Type]):
366366 current_node_deferred = False
367367 # This makes it an error to call an untyped function from a typed one
368368 disallow_untyped_calls = False
369+ # This makes it an error to define an untyped or partially-typed function
370+ disallow_untyped_funcs = False
369371
370372 def __init__ (self , errors : Errors , modules : Dict [str , MypyFile ],
371373 pyversion : Tuple [int , int ] = defaults .PYTHON3_VERSION ,
372- disallow_untyped_calls = False ) -> None :
374+ disallow_untyped_calls = False , disallow_untyped_funcs = False ) -> None :
373375 """Construct a type checker.
374376
375377 Use errors to report type check errors. Assume symtable has been
@@ -393,6 +395,7 @@ def __init__(self, errors: Errors, modules: Dict[str, MypyFile],
393395 self .pass_num = 0
394396 self .current_node_deferred = False
395397 self .disallow_untyped_calls = disallow_untyped_calls
398+ self .disallow_untyped_funcs = disallow_untyped_funcs
396399
397400 def visit_file (self , file_node : MypyFile , path : str ) -> None :
398401 """Type check a mypy file with the given path."""
@@ -658,6 +661,19 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: str) -> None:
658661 self .fail (messages .INIT_MUST_HAVE_NONE_RETURN_TYPE ,
659662 item .type )
660663
664+ if self .disallow_untyped_funcs :
665+ # Check for functions with unspecified/not fully specified types.
666+ def is_implicit_any (t : Type ) -> bool :
667+ return isinstance (t , AnyType ) and t .implicit
668+
669+ if fdef .type is None :
670+ self .fail (messages .FUNCTION_TYPE_EXPECTED , fdef )
671+ elif isinstance (fdef .type , CallableType ):
672+ if is_implicit_any (fdef .type .ret_type ):
673+ self .fail (messages .RETURN_TYPE_EXPECTED , fdef )
674+ if any (is_implicit_any (t ) for t in fdef .type .arg_types ):
675+ self .fail (messages .ARGUMENT_TYPE_EXPECTED , fdef )
676+
661677 if name in nodes .reverse_op_method_set :
662678 self .check_reverse_op_method (item , typ , name )
663679 elif name == '__getattr__' :
0 commit comments