Skip to content

Commit

Permalink
Added clarifying comments
Browse files Browse the repository at this point in the history
  • Loading branch information
m-novikov committed Nov 28, 2017
1 parent 6b6ce1c commit a5726bf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,25 @@ class ModuleType:


class ImportContext:
"""
Describes module import context
Do we already discovered implementation?
What kind of module we discovered?
"""
def __init__(self) -> None:
self.has_py = False # type: bool
self.type = None # type: Optional[int]
# Paths can contain only one ".py" path, but multiple stubs
self.paths = [] # type: List[str]

def maybe_add_path(self, path: str, type: int) -> None:
"""
Add path to import context.
Modifies self.paths in case if arguments satisfy import context state
"""
assert path.endswith(('/',) + tuple(PYTHON_EXTENSIONS))

if self.type is not None and self.type != type:
return None

Expand All @@ -817,6 +830,8 @@ def maybe_add_path(self, path: str, type: int) -> None:
self.paths.append(path)

def _verify_module(self, path: str) -> bool:
# At this point we already know that that it's valid python path
# We only need to check file existence
if not is_file(path):
return False

Expand Down Expand Up @@ -860,6 +875,10 @@ def find_module(self, id: str) -> Optional[str]:
return None

def find_modules_recursive(self, module: str) -> List[BuildSource]:
"""
Discover module and all it's children
Remove duplicates from discovered paths
"""
hits = set() # type: Set[str]
result = [] # type: List[BuildSource]
for src in self._find_modules_recursive(module):
Expand Down Expand Up @@ -903,6 +922,9 @@ def _collect_paths(self, paths: List[str], last_comp: str) -> List[str]:
sepinit = '__init__'
ctx = ImportContext()

# Detect modules in following order: package, module, namespace.
# First hit determines module type, consistency of paths to given type
# ensured in ImportContext
for path_item in paths:
if is_module_path(path_item):
continue
Expand Down

0 comments on commit a5726bf

Please sign in to comment.