8000 Suppress errors from semantic analysis in dynamic (unannotated) functions. by gvanrossum · Pull Request #1415 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Suppress errors from semantic analysis in dynamic (unannotated) functions. #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Suppress errors from semantic analysis in dynamic (unannotated) funct…
…ions. Fix #1334.
  • Loading branch information
Guido van Rossum committed Apr 21, 2016 8000
commit 32a80a51a4779d30897db6acf284ee510bc20e92
6 changes: 4 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,18 @@ def __init__(self, data_dir: str,
self.custom_typing_module = custom_typing_module
self.source_set = source_set
self.reports = reports
check_untyped_defs = CHECK_UNTYPED_DEFS in self.flags
self.semantic_analyzer = SemanticAnalyzer(lib_path, self.errors,
pyversion=pyversion)
pyversion=pyversion,
check_untyped_defs=check_untyped_defs)
self.modules = self.semantic_analyzer.modules
self.semantic_analyzer_pass3 = ThirdPass(self.modules, self.errors)
self.type_checker = TypeChecker(self.errors,
self.modules,
self.pyversion,
DISALLOW_UNTYPED_CALLS in self.flags,
DISALLOW_UNTYPED_DEFS in self.flags,
CHECK_UNTYPED_DEFS in self.flags)
check_untyped_defs)
self.missing_modules = set() # type: Set[str]

def all_imported_modules_in_file(self,
Expand Down
14 changes: 13 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ class SemanticAnalyzer(NodeVisitor):
errors = None # type: Errors # Keeps track of generated errors

def __init__(self, lib_path: List[str], errors: Errors,
pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION) -> None:
pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION,
check_untyped_defs: bool = False) -> None:
"""Construct semantic analyzer.

Use lib_path to search for modules, and report analysis errors
Expand All @@ -211,6 +212,7 @@ def __init__(self, lib_path: List[str], errors: Errors,
self.errors = errors
self.modules = {}
self.pyversion = pyversion
self.check_untyped_defs = check_untyped_defs
self.postpone_nested_functions_stack = [FUNCTION_BOTH_PHASES]
self.postponed_functions_stack = []

Expand Down Expand Up @@ -244,10 +246,12 @@ def visit_file(self, file_node: MypyFile, fnam: str) -> None:
def visit_func_def(self, defn: FuncDef) -> None:
phase_info = self.postpone_nested_functions_stack[-1]
if phase_info != FUNCTION_SECOND_PHASE:
self.function_stack.append(defn)
# First phase of analysis for function.
self.errors.push_function(defn.name())
self.update_function_type_variables(defn)
self.errors.pop_function()
self.function_stack.pop()

defn.is_conditional = self.block_depth[-1] > 0

Expand Down Expand Up @@ -2204,9 +2208,17 @@ def name_already_defined(self, name: str, ctx: Context) -> None:
self.fail("Name '{}' already defined".format(name), ctx)

def fail(self, msg: str, ctx: Context) -> None:
if (self.function_stack and
self.function_stack[-1].is_dynamic() and
not self.check_untyped_defs):
return
self.errors.report(ctx.get_line(), msg)

def note(self, msg: str, ctx: Context) -> None:
if (self.function_stack and
self.function_stack[-1].is_dynamic() and
not self.check_untyped_defs):
return
self.errors.report(ctx.get_line(), msg, severity='note')

def undefined_name_extra_info(self, fullname: str) -> Optional[str]:
Expand Down
0