File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 2121from typing import Any , Literal , NamedTuple , Protocol
2222
2323from astroid .const import PY310_PLUS
24- from astroid .modutils import EXT_LIB_DIRS
24+ from astroid .modutils import EXT_LIB_DIRS , cached_os_path_isfile
2525
2626from . import util
2727
@@ -167,7 +167,7 @@ def find_module(
167167 for suffix in suffixes :
168168 package_file_name = "__init__" + suffix
169169 file_path = os .path .join (package_directory , package_file_name )
170- if os . path . isfile (file_path ):
170+ if cached_os_path_isfile (file_path ):
171171 return ModuleSpec (
172172 name = modname ,
173173 location = package_directory ,
@@ -176,7 +176,7 @@ def find_module(
176176 for suffix , type_ in ImportlibFinder ._SUFFIXES :
177177 file_name = modname + suffix
178178 file_path = os .path .join (entry , file_name )
179- if os . path . isfile (file_path ):
179+ if cached_os_path_isfile (file_path ):
180180 return ModuleSpec (name = modname , location = file_path , type = type_ )
181181 return None
182182
Original file line number Diff line number Diff line change 2424 NoSourceFile ,
2525 _cache_normalize_path_ ,
2626 _has_init ,
27+ cached_os_path_isfile ,
2728 file_info_from_modpath ,
2829 get_source_file ,
2930 is_module_name_part_of_extension_package_whitelist ,
@@ -471,6 +472,7 @@ def clear_cache(self) -> None:
471472 LookupMixIn .lookup ,
472473 _cache_normalize_path_ ,
473474 _has_init ,
475+ cached_os_path_isfile ,
474476 util .is_namespace ,
475477 ObjectModel .attributes ,
476478 ClassDef ._metaclass_lookup_attribute ,
Original file line number Diff line number Diff line change @@ -604,6 +604,12 @@ def is_relative(modname: str, from_file: str) -> bool:
604604 )
605605
606606
607+ @lru_cache (maxsize = 1024 )
608+ def cached_os_path_isfile (path : str | os .PathLike ) -> bool :
609+ """A cached version of os.path.isfile that helps avoid repetitive I/O"""
610+ return os .path .isfile (path )
611+
612+
607613# internal only functions #####################################################
608614
609615
You can’t perform that action at this time.
0 commit comments