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

Method parse_parallel

mypy/build.py:1047–1098  ·  view source on GitHub ↗

Perform parallel parsing of states. Note: this duplicates a bit of logic from State.parse_file(). This is done as an optimization to parallelize only those parts of the code that can be parallelized efficiently.

(self, sequential_states: list[State], parallel_states: list[State])

Source from the content-addressed store, hash-verified

1045 self.post_parse_all(states)
1046
1047 def parse_parallel(self, sequential_states: list[State], parallel_states: list[State]) -> None:
1048 """Perform parallel parsing of states.
1049
1050 Note: this duplicates a bit of logic from State.parse_file(). This is done
1051 as an optimization to parallelize only those parts of the code that can be
1052 parallelized efficiently.
1053 """
1054 parallel_parsed_states, parallel_parsed_states_set = self.parse_files_threaded_raw(
1055 sequential_states, parallel_states
1056 )
1057
1058 for state in parallel_parsed_states:
1059 # New parser returns serialized ASTs. Deserialize full trees only if not using
1060 # parallel workers.
1061 with state.wrap_context():
1062 assert state.tree is not None
1063 raw_data = state.tree.raw_data
1064 if raw_data is not None:
1065 # Apply inline mypy config before deserialization, since
1066 # some options (e.g. implicit_optional) affect deserialization
1067 state.source_hash = raw_data.source_hash
1068 state.apply_inline_configuration(raw_data.mypy_comments)
1069 state.tree = load_from_raw(
1070 state.xpath,
1071 state.id,
1072 raw_data,
1073 self.errors,
1074 state.options,
1075 imports_only=bool(self.workers),
1076 )
1077 if self.errors.is_blockers():
1078 self.log("Bailing due to parse errors")
1079 self.errors.raise_error()
1080
1081 for state in parallel_states:
1082 assert state.tree is not None
1083 if state in parallel_parsed_states_set:
1084 if state.tree.raw_data is not None:
1085 # source_hash was already extracted above, but raw_data
1086 # may have been preserved for workers (imports_only=True).
1087 pass
1088 elif state.source_hash is None:
1089 # At least namespace packages may not have source.
1090 state.get_source()
1091 state.early_errors = list(self.errors.error_info_map.get(state.xpath, []))
1092 state.semantic_analysis_pass1()
1093 self.ast_cache[state.id] = (state.tree, state.early_errors, state.source_hash)
1094 self.modules[state.id] = state.tree
1095 if state.tree.raw_data is not None:
1096 state.size_hint = len(state.tree.raw_data.defs) + MIN_SIZE_HINT
1097 state.check_blockers()
1098 state.setup_errors()
1099
1100 def parse_files_threaded_raw(
1101 self, sequential_states: list[State], parallel_states: list[State]

Callers 1

parse_allMethod · 0.95

Calls 15

logMethod · 0.95
load_from_rawFunction · 0.90
boolClass · 0.85
listClass · 0.85
lenFunction · 0.85
wrap_contextMethod · 0.80
is_blockersMethod · 0.80
raise_errorMethod · 0.80
get_sourceMethod · 0.80

Tested by

no test coverage detected