2727
2828import mypy .strconv
2929from mypy .options import Options
30- from mypy .util import short_type
30+ from mypy .util import is_typeshed_file , short_type
3131from mypy .visitor import ExpressionVisitor , NodeVisitor , StatementVisitor
3232
3333if TYPE_CHECKING :
@@ -283,6 +283,7 @@ class MypyFile(SymbolNode):
283283 "is_partial_stub_package" ,
284284 "plugin_deps" ,
285285 "future_import_flags" ,
286+ "_is_typeshed_file" ,
286287 )
287288
288289 __match_args__ = ("name" , "path" , "defs" )
@@ -319,6 +320,7 @@ class MypyFile(SymbolNode):
319320 plugin_deps : dict [str , set [str ]]
320321 # Future imports defined in this file. Populated during semantic analysis.
321322 future_import_flags : set [str ]
323+ _is_typeshed_file : bool | None
322324
323325 def __init__ (
324326 self ,
@@ -346,6 +348,7 @@ def __init__(
346348 self .is_cache_skeleton = False
347349 self .is_partial_stub_package = False
348350 self .future_import_flags = set ()
351+ self ._is_typeshed_file = None
349352
350353 def local_definitions (self ) -> Iterator [Definition ]:
351354 """Return all definitions within the module (including nested).
@@ -371,6 +374,12 @@ def is_package_init_file(self) -> bool:
371374 def is_future_flag_set (self , flag : str ) -> bool :
372375 return flag in self .future_import_flags
373376
377+ def is_typeshed_file (self , options : Options ) -> bool :
378+ # Cache result since this is called a lot
379+ if self ._is_typeshed_file is None :
380+ self ._is_typeshed_file = is_typeshed_file (options .abs_custom_typeshed_dir , self .path )
381+ return self ._is_typeshed_file
382+
374383 def serialize (self ) -> JsonDict :
375384 return {
376385 ".class" : "MypyFile" ,
0 commit comments