Skip to content

Commit b6b0e9a

Browse files
committed
merger
1 parent d488c2f commit b6b0e9a

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

mypy/build.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ def __init__(self, paths: Optional[Union[str, List[str]]], module: Optional[str]
9999
self.text = text
100100
self.type = type
101101

102-
def __repr__(self) -> str:
103-
return 'BuildSource(%s)' % self.module
104-
105102
@property
106103
def path(self) -> Optional[str]:
107104
if self.paths:
@@ -771,7 +768,7 @@ def is_pkg(p: str) -> bool:
771768
# of os.stat() calls is quickly more expensive than caching the
772769
# os.listdir() outcome, and the advantage of the latter is that it
773770
# gives us the case-correct filename on Windows and Mac.
774-
find_module_listdir_cache = {} # type: Dict[str, Optional[List[str]]]
771+
find_module_listdir_cache = {} # type: Dict[str, Set[str]]
775772

776773
# Cache for is_file()
777774
find_module_is_file_cache = {} # type: Dict[str, bool]
@@ -787,7 +784,7 @@ def find_module_clear_caches() -> None:
787784
find_module_isdir_cache.clear()
788785

789786

790-
def list_dir(path: str) -> Optional[List[str]]:
787+
def list_dir(path: str) -> Set[str]:
791788
"""Return a cached directory listing.
792789
793790
Returns None if the path doesn't exist or isn't a directory.
@@ -797,7 +794,7 @@ def list_dir(path: str) -> Optional[List[str]]:
797794
try:
798795
res = os.listdir(path)
799796
except OSError:
800-
res = None
797+
res = set()
801798
find_module_listdir_cache[path] = res
802799
return res
803800

@@ -816,7 +813,7 @@ def is_file(path: str) -> bool:
816813
res = False
817814
else:
818815
names = list_dir(head)
819-
res = names is not None and tail in names and os.path.isfile(path)
816+
res = tail in names and os.path.isfile(path)
820817
find_module_is_file_cache[path] = res
821818
return res
822819

@@ -879,12 +876,12 @@ def __init__(self,
879876

880877
self.lib_path = [os.path.normpath(p) for p in lib_path] # type: List[str]
881878
self.namespaces_allowed = namespaces_allowed
882-
self._find_module_cache = {} # type: Dict[str, Optional[BuildSource]]
879+
self.find_module_cache = {} # type: Dict[str, Optional[BuildSource]]
883880

884881
def find_module(self, id: str) -> Optional[BuildSource]:
885-
if id not in self._find_module_cache:
886-
self._find_module_cache[id] = self._find_module(id)
887-
return self._find_module_cache[id]
882+
if id not in self.find_module_cache:
883+
self.find_module_cache[id] = self._find_module(id)
884+
return self.find_module_cache[id]
888885

889886
def find_modules_recursive(self, module: str) -> List[BuildSource]:
890887
"""
@@ -923,7 +920,7 @@ def _find_modules_recursive(self, module: str) -> List[BuildSource]:
923920
return srcs
924921

925922
def _find_submodules(self, module: str, path: str) -> Iterator[str]:
926-
for item in list_dir(path) or []:
923+
for item in list_dir(path):
927924
if item.startswith(('__', '.')):
928925
continue
929926

@@ -2072,7 +2069,7 @@ def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph:
20722069
stubs_found=sum(g.path is not None and g.path.endswith('.pyi')
20732070
for g in graph.values()),
20742071
graph_load_time=(t1 - t0),
2075-
fm_cache_size=len(find_module_cache),
2072+
fm_cache_size=len(manager.module_discovery.find_module_cache),
20762073
fm_dir_cache_size=len(find_module_dir_cache),
20772074
fm_listdir_cache_size=len(find_module_listdir_cache),
20782075
fm_is_file_cache_size=len(find_module_is_file_cache),

0 commit comments

Comments
 (0)