MCPcopy Index your code
hub / github.com/python/mypy / visit_file

Method visit_file

mypy/semanal_pass1.py:58–82  ·  view source on GitHub ↗
(self, file: MypyFile, fnam: str, mod_id: str, options: Options)

Source from the content-addressed store, hash-verified

56 """
57
58 def visit_file(self, file: MypyFile, fnam: str, mod_id: str, options: Options) -> None:
59 self.platform = options.platform
60 self.cur_mod_id = mod_id
61 self.cur_mod_node = file
62 self.options = options
63 self.is_global_scope = True
64 self.skipped_lines: set[int] = set()
65
66 for i, defn in enumerate(file.defs):
67 defn.accept(self)
68 if isinstance(defn, AssertStmt) and assert_will_always_fail(defn, options):
69 # We've encountered an assert that's always false,
70 # e.g. assert sys.platform == 'lol'. Truncate the
71 # list of statements. This mutates file.defs too.
72 if i < len(file.defs) - 1:
73 next_def, last = file.defs[i + 1], file.defs[-1]
74 if last.end_line is not None:
75 # We are on a Python version recent enough to support end lines.
76 self.skipped_lines |= set(range(next_def.line, last.end_line + 1))
77 file.imports = [
78 i for i in file.imports if (i.line, i.column) <= (defn.line, defn.column)
79 ]
80 del file.defs[i + 1 :]
81 break
82 file.skipped_lines = self.skipped_lines
83
84 def visit_func_def(self, node: FuncDef) -> None:
85 old_global_scope = self.is_global_scope

Callers 1

Calls 7

assert_will_always_failFunction · 0.90
setClass · 0.85
enumerateFunction · 0.85
isinstanceFunction · 0.85
lenFunction · 0.85
rangeClass · 0.85
acceptMethod · 0.45

Tested by

no test coverage detected