@@ -191,7 +191,8 @@ class SemanticAnalyzer(NodeVisitor):
191
191
errors = None # type: Errors # Keeps track of generated errors
192
192
193
193
def __init__ (self , lib_path : List [str ], errors : Errors ,
194
- pyversion : Tuple [int , int ] = defaults .PYTHON3_VERSION ) -> None :
194
+ pyversion : Tuple [int , int ] = defaults .PYTHON3_VERSION ,
195
+ check_untyped_defs : bool = False ) -> None :
195
196
"""Construct semantic analyzer.
196
197
197
198
Use lib_path to search for modules, and report analysis errors
@@ -211,6 +212,7 @@ def __init__(self, lib_path: List[str], errors: Errors,
211
212
self .errors = errors
212
213
self .modules = {}
213
214
self .pyversion = pyversion
215
+ self .check_untyped_defs = check_untyped_defs
214
216
self .postpone_nested_functions_stack = [FUNCTION_BOTH_PHASES ]
215
217
self .postponed_functions_stack = []
216
218
@@ -244,10 +246,12 @@ def visit_file(self, file_node: MypyFile, fnam: str) -> None:
244
246
def visit_func_def (self , defn : FuncDef ) -> None :
245
247
phase_info = self .postpone_nested_functions_stack [- 1 ]
246
248
if phase_info != FUNCTION_SECOND_PHASE :
249
+ self .function_stack .append (defn )
247
250
# First phase of analysis for function.
248
251
self .errors .push_function (defn .name ())
249
252
self .update_function_type_variables (defn )
250
253
self .errors .pop_function ()
254
+ self .function_stack .pop ()
251
255
252
256
defn .is_conditional = self .block_depth [- 1 ] > 0
253
257
@@ -2204,9 +2208,17 @@ def name_already_defined(self, name: str, ctx: Context) -> None:
2204
2208
self .fail ("Name '{}' already defined" .format (name ), ctx )
2205
2209
2206
2210
def fail (self , msg : str , ctx : Context ) -> None :
2211
+ if (self .function_stack and
2212
+ self .function_stack [- 1 ].is_dynamic () and
2213
+ not self .check_untyped_defs ):
2214
+ return
2207
2215
self .errors .report (ctx .get_line (), msg )
2208
2216
2209
2217
def note (self , msg : str , ctx : Context ) -> None :
2218
+ if (self .function_stack and
2219
+ self .function_stack [- 1 ].is_dynamic () and
2220
+ not self .check_untyped_defs ):
2221
+ return
2210
2222
self .errors .report (ctx .get_line (), msg , severity = 'note' )
2211
2223
2212
2224
def undefined_name_extra_info (self , fullname : str ) -> Optional [str ]:
0 commit comments