Skip to content

Commit be82bf7

Browse files
committed
Fix typecheck
1 parent f4903fa commit be82bf7

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

mypy/build.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
625625

626626
return res
627627

628-
def find_module(self, id):
628+
def find_module(self, id: str) -> Optional[str]:
629629
return self.module_discovery.find_module(id)
630630

631631
def is_module(self, id: str) -> bool:
@@ -787,9 +787,9 @@ class ModuleType:
787787

788788

789789
class ImportContext:
790-
def __init__(self):
790+
def __init__(self) -> None:
791791
self.has_py = False # type: bool
792-
self.type = None # type: int
792+
self.type = None # type: Optional[int]
793793
self.paths = [] # type: List[str]
794794

795795
def maybe_add_path(self, path: str, type: int) -> None:
@@ -824,7 +824,7 @@ def _verify_module(self, path: str) -> bool:
824824

825825
def _verify_namespace(self, path: str) -> bool:
826826
if os.path.isdir(path):
827-
files = set(list_dir(path))
827+
files = set(list_dir(path) or []) # type: Set[str]
828828
if not ('__init__.py' in files or '__init__.pyi' in files):
829829
return True
830830

@@ -886,8 +886,8 @@ def _find_modules_recursive(self, module: str) -> List[BuildSource]:
886886

887887
return srcs
888888

889-
def _find_submodules(self, module, path) -> Iterator[str]:
890-
for item in list_dir(path):
889+
def _find_submodules(self, module: str, path: str) -> Iterator[str]:
890+
for item in list_dir(path) or []:
891891
if item == '__init__.py' or item == '__init__.pyi':
892892
continue
893893

mypy/stubgen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def find_module_path_and_all(module: str, pyversion: Tuple[int, int],
156156
module_all = getattr(mod, '__all__', None)
157157
else:
158158
# Find module by going through search path.
159-
module_path = mypy.build.find_module(module, ['.'] + search_path)
159+
md = mypy.build.ModuleDiscovery(['.'] + search_path)
160+
module_path = md.find_module(module)
160161
if not module_path:
161162
raise SystemExit(
162163
"Can't find module '{}' (consider using --search-path)".format(module))

mypy/test/testcheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ def parse_module(self,
329329
module_names = m.group(1)
330330
out = []
331331
for module_name in module_names.split(' '):
332-
m = build.ModuleDiscovery([test_temp_dir], namespaces_allowed=False)
333-
path = m.find_module(module_name)
332+
md = build.ModuleDiscovery([test_temp_dir], namespaces_allowed=False)
333+
path = md.find_module(module_name)
334334
assert path is not None, "Can't find ad hoc case file"
335335
with open(path) as f:
336336
program_text = f.read()

mypy/test/testdmypy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ def parse_module(self,
270270
module_names = m.group(1)
271271
out = []
272272
for module_name in module_names.split(' '):
273-
m = build.ModuleDiscovery([test_temp_dir])
274-
path = m.find_module(module_name)
273+
md = build.ModuleDiscovery([test_temp_dir])
274+
path = md.find_module(module_name)
275275
assert path is not None, "Can't find ad hoc case file"
276276
with open(path) as f:
277277
program_text = f.read()

mypy/test/testmodulediscovery.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
from mypy.build import ModuleDiscovery, find_module_clear_caches
1+
import os
2+
23
from unittest import mock, TestCase
4+
from typing import List, Set
5+
6+
from mypy.build import ModuleDiscovery, find_module_clear_caches
37
from mypy.myunit import Suite, assert_equal
4-
import os
58

69

710
class ModuleDiscoveryTestCase(Suite):
8-
def set_up(self):
9-
self.files = {}
11+
def set_up(self) -> None:
12+
self.files = set() # type: Set[str]
1013

1114
self._setup_mock_filesystem()
1215

13-
def tear_down(self):
16+
def tear_down(self) -> None:
1417
self._teardown_mock_filesystem()
1518
find_module_clear_caches()
1619

17-
def _list_dir(self, path: str) -> list:
20+
def _list_dir(self, path: str) -> List:
1821
res = set()
1922

2023
if not path.endswith(os.path.sep):

0 commit comments

Comments
 (0)