|
1 | 1 | """Self check mypy package"""
|
2 | 2 | import sys
|
3 | 3 | import os.path
|
4 |
| -from typing import List, Optional, Set |
| 4 | +from typing import List, Set |
5 | 5 |
|
6 | 6 | from mypy.test.helpers import Suite, run_mypy
|
7 | 7 |
|
8 | 8 |
|
9 | 9 | class TypeshedSuite(Suite):
|
10 |
| - def check_stubs(self, version: str, name: Optional[str] = None) -> None: |
11 |
| - if name is None: |
12 |
| - name = version |
13 |
| - seen = {'__builtin__', } |
14 |
| - modules = ['__builtin__'] |
| 10 | + def check_stubs(self, version: str, *directories: str) -> None: |
| 11 | + if not directories: |
| 12 | + directories = (version,) |
15 | 13 | for stub_type in ['stdlib', 'third_party']:
|
16 |
| - stubdir = os.path.join('typeshed', stub_type, name) |
17 |
| - for f in find_files(stubdir, suffix='.pyi'): |
18 |
| - module = file_to_module(f[len(stubdir) + 1:]) |
19 |
| - if module not in seen: |
20 |
| - seen.add(module) |
21 |
| - modules.extend(['-m', module]) |
22 |
| - if version == "3": |
23 |
| - version = "3.4" |
24 |
| - if modules: |
25 |
| - modules.remove('__builtin__') |
26 |
| - run_mypy(['--python-version={}'.format(version)] + modules) |
| 14 | + for dir in directories: |
| 15 | + seen = {'__builtin__'} # we don't want to check __builtin__, as it causes problems |
| 16 | + modules = [] |
| 17 | + stubdir = os.path.join('typeshed', stub_type, dir) |
| 18 | + for f in find_files(stubdir, suffix='.pyi'): |
| 19 | + module = file_to_module(f[len(stubdir) + 1:]) |
| 20 | + if module not in seen: |
| 21 | + seen.add(module) |
| 22 | + modules.extend(['-m', module]) |
| 23 | + |
| 24 | + if modules: |
| 25 | + run_mypy(['--python-version={}'.format(version)] + modules) |
27 | 26 |
|
28 | 27 | def test_2(self) -> None:
|
29 |
| - self.check_stubs("2.7", name="2") |
30 |
| - |
31 |
| - def test_2and3_2(self) -> None: |
32 |
| - self.check_stubs("2.7", name="2and3") |
33 |
| - |
34 |
| - def test_2and3_3(self) -> None: |
35 |
| - sys_ver_str = '.'.join(map(str, sys.version_info[:2])) |
36 |
| - self.check_stubs(sys_ver_str, name="2and3") |
| 28 | + self.check_stubs("2.7", "2", "2and3") |
37 | 29 |
|
38 | 30 | def test_3(self) -> None:
|
39 |
| - self.check_stubs("3") |
| 31 | + sys_ver_str = '.'.join(map(str, sys.version_info[:2])) |
| 32 | + self.check_stubs(sys_ver_str, "3", "2and3") |
40 | 33 |
|
41 | 34 | def test_34(self) -> None:
|
42 | 35 | self.check_stubs("3.4")
|
|
0 commit comments