1+ """Stub file discovery."""
2+
13from functools import cached_property
24from pathlib import Path
35
68
79
810class StubFile :
9- """A stdlib stub file ."""
11+ """Base class for stub files ."""
1012
1113 def __init__ (self , path : Path ) -> None :
1214 self .path = path
@@ -27,6 +29,8 @@ def module_parts(self) -> tuple[str, ...]:
2729
2830
2931class StdlibStubFile (StubFile ):
32+ """A stdlib stub file."""
33+
3034 @cached_property
3135 def module_parts (self ) -> tuple [str , ...]:
3236 relative = self .path .relative_to (STDLIB_PATH )
@@ -37,6 +41,8 @@ def module_parts(self) -> tuple[str, ...]:
3741
3842
3943class ThirdPartyStubFile (StubFile ):
44+ """A third-party stub file."""
45+
4046 @cached_property
4147 def upstream_distribution (self ) -> str :
4248 return self .path .relative_to (STUBS_PATH ).parts [0 ]
@@ -52,7 +58,8 @@ def module_parts(self) -> tuple[str, ...]:
5258
5359
5460def stdlib_stubs (version : str ) -> list [StdlibStubFile ]:
55- """Return the stdlib stubs available in the requested Python version."""
61+ """Return the stdlib stubs available for the requested Python version."""
62+
5663 module_versions = parse_stdlib_versions_file ()
5764 stubs : list [StdlibStubFile ] = []
5865
@@ -67,6 +74,12 @@ def stdlib_stubs(version: str) -> list[StdlibStubFile]:
6774
6875
6976def third_party_stubs (distribution : str | None = None ) -> list [ThirdPartyStubFile ]:
77+ """Return third-party stubs.
78+
79+ If distribution is None, return all third-party stubs. Otherwise,
80+ return only stubs for the given distribution.
81+ """
82+
7083 stubs : list [ThirdPartyStubFile ] = []
7184
7285 stub_path = distribution_path (distribution ) if distribution else STUBS_PATH
@@ -80,7 +93,7 @@ def third_party_stubs(distribution: str | None = None) -> list[ThirdPartyStubFil
8093
8194
8295def path_stubs (path : Path ) -> list [Path ]:
83- """Return all stubs in a certain path."""
96+ """Return paths to all stub files in a certain path."""
8497 if path .is_file ():
8598 return [path ] if path .suffix == ".pyi" and TESTS_DIR not in path .parts else []
8699 return sorted (p for p in path .rglob ("*.pyi" ) if TESTS_DIR not in p .parts )
0 commit comments