Skip to content

Commit

Permalink
merger
Browse files Browse the repository at this point in the history
  • Loading branch information
m-novikov committed Dec 13, 2017
1 parent d488c2f commit b6b0e9a
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def __init__(self, paths: Optional[Union[str, List[str]]], module: Optional[str]
self.text = text
self.type = type

def __repr__(self) -> str:
return 'BuildSource(%s)' % self.module

@property
def path(self) -> Optional[str]:
if self.paths:
Expand Down Expand Up @@ -771,7 +768,7 @@ def is_pkg(p: str) -> bool:
# of os.stat() calls is quickly more expensive than caching the
# os.listdir() outcome, and the advantage of the latter is that it
# gives us the case-correct filename on Windows and Mac.
find_module_listdir_cache = {} # type: Dict[str, Optional[List[str]]]
find_module_listdir_cache = {} # type: Dict[str, Set[str]]

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


def list_dir(path: str) -> Optional[List[str]]:
def list_dir(path: str) -> Set[str]:
"""Return a cached directory listing.
Returns None if the path doesn't exist or isn't a directory.
Expand All @@ -797,7 +794,7 @@ def list_dir(path: str) -> Optional[List[str]]:
try:
res = os.listdir(path)
except OSError:
res = None
res = set()
find_module_listdir_cache[path] = res
return res

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

Expand Down Expand Up @@ -879,12 +876,12 @@ def __init__(self,

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

def find_module(self, id: str) -> Optional[BuildSource]:
if id not in self._find_module_cache:
self._find_module_cache[id] = self._find_module(id)
return self._find_module_cache[id]
if id not in self.find_module_cache:
self.find_module_cache[id] = self._find_module(id)
return self.find_module_cache[id]

def find_modules_recursive(self, module: str) -> List[BuildSource]:
"""
Expand Down Expand Up @@ -923,7 +920,7 @@ def _find_modules_recursive(self, module: str) -> List[BuildSource]:
return srcs

def _find_submodules(self, module: str, path: str) -> Iterator[str]:
for item in list_dir(path) or []:
for item in list_dir(path):
if item.startswith(('__', '.')):
continue

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

0 comments on commit b6b0e9a

Please sign in to comment.