MCPcopy
hub / github.com/python/mypy / parse_file

Method parse_file

mypy/build.py:1278–1306  ·  view source on GitHub ↗

Parse the source of a file with the given name. Raise CompileError if there is a parse error.

(
        self,
        id: str,
        path: str,
        source: str,
        options: Options,
        raw_data: FileRawData | None = None,
    )

Source from the content-addressed store, hash-verified

1276 return find_module_simple(id, self) is not None
1277
1278 def parse_file(
1279 self,
1280 id: str,
1281 path: str,
1282 source: str,
1283 options: Options,
1284 raw_data: FileRawData | None = None,
1285 ) -> MypyFile:
1286 """Parse the source of a file with the given name.
1287
1288 Raise CompileError if there is a parse error.
1289 """
1290 file_exists = self.fscache.exists(path, real_only=True)
1291 t0 = time.time()
1292 if raw_data:
1293 # If possible, deserialize from known binary data instead of parsing from scratch.
1294 tree = load_from_raw(path, id, raw_data, self.errors, options)
1295 else:
1296 tree = parse(source, path, id, self.errors, options=options, file_exists=file_exists)
1297 tree._fullname = id
1298 if self.stats_enabled:
1299 with self.stats_lock:
1300 self.add_stats(
1301 files_parsed=1,
1302 modules_parsed=int(not tree.is_stub),
1303 stubs_parsed=int(tree.is_stub),
1304 parse_time=time.time() - t0,
1305 )
1306 return tree
1307
1308 def load_fine_grained_deps(self, id: str) -> dict[str, set[str]]:
1309 t0 = time.time()

Callers

nothing calls this directly

Calls 5

add_statsMethod · 0.95
load_from_rawFunction · 0.90
parseFunction · 0.90
intClass · 0.85
existsMethod · 0.80

Tested by

no test coverage detected