Skip to content

Commit 451985f

Browse files
authored
Reuse path_stubs
1 parent 89b212a commit 451985f

1 file changed

Lines changed: 3 additions & 21 deletions

File tree

lib/ts_utils/stubs.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,9 @@ def module_parts(self) -> tuple[str, ...]:
5858

5959
def stdlib_stubs(version: str) -> list[StdlibStubFile]:
6060
"""Return the stdlib stubs available for the requested Python version."""
61-
6261
module_versions = parse_stdlib_versions_file()
63-
stubs: list[StdlibStubFile] = []
64-
65-
for path in sorted(STDLIB_PATH.rglob("*.pyi")):
66-
if TESTS_DIR in path.parts:
67-
continue
68-
stub = StdlibStubFile(path)
69-
if module_versions.is_supported(stub.module_name, version):
70-
stubs.append(stub)
71-
72-
return stubs
62+
stubs = (StdlibStubFile(path) for path in path_stubs(STDLIB_PATH))
63+
return [stub for stub in stubs if module_versions.is_supported(stub.module_name, version)]
7364

7465

7566
def third_party_stubs(distribution: str | None = None) -> list[ThirdPartyStubFile]:
@@ -78,17 +69,8 @@ def third_party_stubs(distribution: str | None = None) -> list[ThirdPartyStubFil
7869
If distribution is None, return all third-party stubs. Otherwise,
7970
return only stubs for the given distribution.
8071
"""
81-
82-
stubs: list[ThirdPartyStubFile] = []
83-
8472
stub_path = distribution_path(distribution) if distribution else STUBS_PATH
85-
86-
for path in sorted(stub_path.rglob("*.pyi")):
87-
if TESTS_DIR in path.parts:
88-
continue
89-
stubs.append(ThirdPartyStubFile(path))
90-
91-
return stubs
73+
return [ThirdPartyStubFile(path) for path in path_stubs(stub_path)]
9274

9375

9476
def path_stubs(path: Path) -> list[Path]:

0 commit comments

Comments
 (0)