163163from mypy .modules_state import modules_state
164164from mypy .nodes import Expression
165165from mypy .options import Options
166- from mypy .parse import load_from_raw , parse
166+ from mypy .parse import load_from_raw , parse , parse_native
167167from mypy .plugin import ChainedPlugin , Plugin , ReportConfigContext
168168from mypy .plugins .default import DefaultPlugin
169169from mypy .renaming import LimitedVariableRenameVisitor , VariableRenameVisitor
@@ -1114,7 +1114,9 @@ def parse_files_threaded_raw(self, states: list[State]) -> tuple[list[State], se
11141114 ignore_errors = state .ignore_all or state .options .ignore_errors
11151115 if ignore_errors :
11161116 self .errors .ignored_files .add (state .xpath )
1117- futures .append (executor .submit (state .parse_file_inner , state .source ))
1117+ futures .append (
1118+ executor .submit (state .parse_file_inner , state .source , parallel = True )
1119+ )
11181120 parallel_parsed_states .append (state )
11191121 parallel_parsed_states_set .add (state )
11201122 else :
@@ -1264,9 +1266,10 @@ def parse_file(
12641266 self ,
12651267 id : str ,
12661268 path : str ,
1267- source : str ,
1269+ source : str | None ,
12681270 options : Options ,
12691271 raw_data : FileRawData | None = None ,
1272+ parallel : bool = False ,
12701273 ) -> MypyFile :
12711274 """Parse the source of a file with the given name.
12721275
@@ -1277,7 +1280,11 @@ def parse_file(
12771280 # If possible, deserialize from known binary data instead of parsing from scratch.
12781281 tree = load_from_raw (path , id , raw_data , self .errors , options )
12791282 else :
1280- tree = parse (source , path , id , self .errors , options = options )
1283+ if source is not None :
1284+ tree = parse (source , path , id , self .errors , options = options )
1285+ else :
1286+ assert parallel
1287+ tree = parse_native (source , path , id , self .errors , options = options )
12811288 tree ._fullname = id
12821289 if self .stats_enabled :
12831290 with self .stats_lock :
@@ -3176,10 +3183,12 @@ def get_source(self) -> str:
31763183 self .time_spent_us += time_spent_us (t0 )
31773184 return source
31783185
3179- def parse_file_inner (self , source : str , raw_data : FileRawData | None = None ) -> None :
3186+ def parse_file_inner (
3187+ self , source : str | None , raw_data : FileRawData | None = None , parallel : bool = False
3188+ ) -> None :
31803189 t0 = time_ref ()
31813190 self .tree = self .manager .parse_file (
3182- self .id , self .xpath , source , options = self .options , raw_data = raw_data
3191+ self .id , self .xpath , source , self .options , raw_data , parallel
31833192 )
31843193 self .time_spent_us += time_spent_us (t0 )
31853194
0 commit comments