Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2012973

Browse files
committed
get_all_stub_files should also return the module names
1 parent 685d33b commit 2012973

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

tests/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def test_subdir(self) -> None:
4545
def test_get_all_stub_files(self) -> None:
4646
all_stubs = typeshed_client.get_all_stub_files(version=(2, 7), typeshed_dir=TEST_TYPESHED)
4747
self.assertEqual(set(all_stubs), {
48-
TEST_TYPESHED / 'stdlib/2/lib.pyi',
49-
TEST_TYPESHED / 'stdlib/2and3/conditions.pyi',
50-
TEST_TYPESHED / 'stdlib/2and3/shared.pyi',
48+
('lib', TEST_TYPESHED / 'stdlib/2/lib.pyi'),
49+
('conditions', TEST_TYPESHED / 'stdlib/2and3/conditions.pyi'),
50+
('shared', TEST_TYPESHED / 'stdlib/2and3/shared.pyi'),
5151
})
5252

5353

typeshed_client/finder.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ def parse_stub_file(path: Path) -> ast3.AST:
7272

7373

7474
def get_all_stub_files(version: Tuple[int, int] = sys.version_info[:2],
75-
typeshed_dir: Optional[Path] = None) -> Iterable[Path]:
76-
"""Returns paths to all stub files for a given Python version."""
75+
typeshed_dir: Optional[Path] = None) -> Iterable[Tuple[str, Path]]:
76+
"""Returns paths to all stub files for a given Python version.
77+
78+
Returns pairs of (module name, module path).
79+
80+
"""
7781
if typeshed_dir is None:
7882
typeshed_dir = find_typeshed()
7983
seen: Set[str] = set()
@@ -86,5 +90,15 @@ def get_all_stub_files(version: Tuple[int, int] = sys.version_info[:2],
8690
continue
8791
if relative_path in seen:
8892
continue
89-
yield full_path
93+
yield _path_to_module(relative_path), full_path
9094
seen.add(relative_path)
95+
96+
97+
def _path_to_module(path: Path) -> str:
98+
"""Returns the module name corresponding to a file path."""
99+
parts = path.parts
100+
if parts[-1] == '__init__.pyi':
101+
parts = parts[-1]
102+
if parts[-1].endswith('.pyi'):
103+
parts = parts[:-1] + (parts[-1].rstrip('.pyi'),)
104+
return '.'.join(parts)

0 commit comments

Comments
 (0)