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

Function load_from_raw

mypy/parse.py:59–102  ·  view source on GitHub ↗

Load AST from parsed binary data and report stored errors. If imports_only is true, only deserialize imports and return a mostly empty AST.

(
    fnam: str,
    module: str | None,
    raw_data: FileRawData,
    errors: Errors,
    options: Options,
    imports_only: bool = False,
)

Source from the content-addressed store, hash-verified

57
58
59def load_from_raw(
60 fnam: str,
61 module: str | None,
62 raw_data: FileRawData,
63 errors: Errors,
64 options: Options,
65 imports_only: bool = False,
66) -> MypyFile:
67 """Load AST from parsed binary data and report stored errors.
68
69 If imports_only is true, only deserialize imports and return a mostly
70 empty AST.
71 """
72 from mypy.nativeparse import State, deserialize_imports, read_statements
73
74 state = State(options)
75 if imports_only:
76 defs = []
77 else:
78 data = ReadBuffer(raw_data.defs)
79 n = read_int(data)
80 defs = read_statements(state, data, n)
81 imports = deserialize_imports(raw_data.imports)
82
83 tree = MypyFile(defs, imports)
84 tree.path = fnam
85 tree.ignored_lines = raw_data.ignored_lines
86 tree.is_partial_stub_package = raw_data.is_partial_stub_package
87 tree.uses_template_strings = raw_data.uses_template_strings
88 tree.is_stub = fnam.endswith(".pyi")
89 if module is not None:
90 tree._fullname = module
91
92 # Report parse errors, this replicates the logic in parse().
93 all_errors = raw_data.raw_errors + state.errors
94 errors.set_file(fnam, module, options=options)
95 for error in all_errors:
96 # Note we never raise in this function, so it should not be called in coordinator.
97 report_parse_error(error, errors)
98 if imports_only:
99 # Preserve raw data when only de-serializing imports, it will be sent to
100 # the parallel workers.
101 tree.raw_data = raw_data
102 return tree
103
104
105def report_parse_error(error: ParseError, errors: Errors) -> None:

Callers 4

parse_parallelMethod · 0.90
parse_fileMethod · 0.90
parse_fileMethod · 0.90
parseFunction · 0.85

Calls 8

StateClass · 0.90
read_intFunction · 0.90
read_statementsFunction · 0.90
deserialize_importsFunction · 0.90
MypyFileClass · 0.90
report_parse_errorFunction · 0.85
set_fileMethod · 0.80
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…