@@ -371,6 +371,23 @@ def lookup_fully_qualified(self, fullname: str) -> Optional[SymbolTableNode]:
371371 assert self ._modules is not None
372372 return lookup_fully_qualified (fullname , self ._modules )
373373
374+ def get_additional_deps (self , file : MypyFile ) -> List [Tuple [int , str , int ]]:
375+ """Customize dependencies for a module.
376+
377+ This hook allows adding in new dependencies for a module. It
378+ is called after parsing a file but before analysis. This can
379+ be useful if a library has dependencies that are dynamic based
380+ on configuration information, for example.
381+
382+ Returns a list of (priority, module name, line number) tuples.
383+
384+ The line number can be -1 when there is not a known real line number.
385+
386+ Priorities are defined in mypy.build (but maybe shouldn't be).
387+ 10 is a good choice for priority.
388+ """
389+ return []
390+
374391 def get_type_analyze_hook (self , fullname : str
375392 ) -> Optional [Callable [[AnalyzeTypeContext ], Type ]]:
376393 """Customize behaviour of the type analyzer for given full names.
@@ -395,7 +412,7 @@ def get_function_hook(self, fullname: str
395412 """Adjust the return type of a function call.
396413
397414 This method is called after type checking a call. Plugin may adjust the return
398- type inferred by mypy, and/or emmit some error messages. Note, this hook is also
415+ type inferred by mypy, and/or emit some error messages. Note, this hook is also
399416 called for class instantiation calls, so that in this example:
400417
401418 from lib import Class, do_stuff
@@ -561,6 +578,9 @@ def set_modules(self, modules: Dict[str, MypyFile]) -> None:
561578 def lookup_fully_qualified (self , fullname : str ) -> Optional [SymbolTableNode ]:
562579 return self .plugin .lookup_fully_qualified (fullname )
563580
581+ def get_additional_deps (self , file : MypyFile ) -> List [Tuple [int , str , int ]]:
582+ return self .plugin .get_additional_deps (file )
583+
564584 def get_type_analyze_hook (self , fullname : str
565585 ) -> Optional [Callable [[AnalyzeTypeContext ], Type ]]:
566586 return self .plugin .get_type_analyze_hook (fullname )
@@ -626,6 +646,12 @@ def set_modules(self, modules: Dict[str, MypyFile]) -> None:
626646 for plugin in self ._plugins :
627647 plugin .set_modules (modules )
628648
649+ def get_additional_deps (self , file : MypyFile ) -> List [Tuple [int , str , int ]]:
650+ deps = []
651+ for plugin in self ._plugins :
652+ deps .extend (plugin .get_additional_deps (file ))
653+ return deps
654+
629655 def get_type_analyze_hook (self , fullname : str
630656 ) -> Optional [Callable [[AnalyzeTypeContext ], Type ]]:
631657 return self ._find_hook (lambda plugin : plugin .get_type_analyze_hook (fullname ))
0 commit comments