Skip to content

Commit a5726bf

Browse files
committed
Added clarifying comments
1 parent 6b6ce1c commit a5726bf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

mypy/build.py

+22
Original file line numberDiff line numberDiff line change
@@ -787,12 +787,25 @@ class ModuleType:
787787

788788

789789
class ImportContext:
790+
"""
791+
Describes module import context
792+
793+
Do we already discovered implementation?
794+
What kind of module we discovered?
795+
"""
790796
def __init__(self) -> None:
791797
self.has_py = False # type: bool
792798
self.type = None # type: Optional[int]
799+
# Paths can contain only one ".py" path, but multiple stubs
793800
self.paths = [] # type: List[str]
794801

795802
def maybe_add_path(self, path: str, type: int) -> None:
803+
"""
804+
Add path to import context.
805+
Modifies self.paths in case if arguments satisfy import context state
806+
"""
807+
assert path.endswith(('/',) + tuple(PYTHON_EXTENSIONS))
808+
796809
if self.type is not None and self.type != type:
797810
return None
798811

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

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

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

862877
def find_modules_recursive(self, module: str) -> List[BuildSource]:
878+
"""
879+
Discover module and all it's children
880+
Remove duplicates from discovered paths
881+
"""
863882
hits = set() # type: Set[str]
864883
result = [] # type: List[BuildSource]
865884
for src in self._find_modules_recursive(module):
@@ -903,6 +922,9 @@ def _collect_paths(self, paths: List[str], last_comp: str) -> List[str]:
903922
sepinit = '__init__'
904923
ctx = ImportContext()
905924

925+
# Detect modules in following order: package, module, namespace.
926+
# First hit determines module type, consistency of paths to given type
927+
# ensured in ImportContext
906928
for path_item in paths:
907929
if is_module_path(path_item):
908930
continue

0 commit comments

Comments
 (0)