Skip to content

Commit eb8ab07

Browse files
Add typing stubs for Python 3, mypy configuration, etc.
1 parent df2f51e commit eb8ab07

19 files changed

+2278
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ dist
1919
htmlcov
2020
build
2121
.tox
22+
.pyright
23+
.mypy_cache
2224
.idea
2325
_testdist-0.1

.hgignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\.(py[co]|log|zip|coverage|json)$
1+
\.(py[co]|log|zip|coverage|json|mypy_cache|pyright)$
22
tests/run/
33
tests/keys/random_seed
44
docs/(_build|themes)/

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Released: Not yet.
1616
- Fix shebang computation for source builds of Python. Thanks to Eli
1717
Schwartz for the patch.
1818

19+
Typing stubs for Python 3 were added. _frozen_importlib and
20+
_frozen_importlib_externals were replaced with importlib.machinery.
21+
1922
0.3.6
2023
~~~~~
2124

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
include README.rst CHANGES.rst LICENSE.txt CONTRIBUTORS.txt
2-
include distlib/*.exe
2+
include distlib/*.exe distlib/*.pyi distlib/py.typed
33
recursive-include tests *
44
recursive-include PC *
5-
global-exclude *.log __pycache__ *.pyc *.pyo
5+
global-exclude *.log __pycache__ *.pyc *.pyo .mypy_cache .pytype
66
exclude tests/*pypi*
77
prune tests/pypiserver
88
prune tests/packages

distlib/__init__.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
from logging import Logger
3+
4+
NullHandler: type
5+
__version__: str
6+
logger: Logger
7+
8+
class DistlibException(Exception): ...

distlib/compat.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# type: ignore

distlib/database.pyi

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
from __future__ import annotations
2+
from .locators import Locator
3+
from .metadata import Metadata
4+
from .resources import Resource, ResourceContainer, ResourceFinder
5+
from .util import cached_property, ExportEntry
6+
from .version import VersionScheme
7+
from codecs import StreamReader
8+
from collections.abc import Iterator
9+
from io import BufferedReader, StringIO
10+
from logging import Logger
11+
from typing_extensions import (
12+
Literal,
13+
Self,
14+
TypedDict,
15+
TypeVar,
16+
Unpack,
17+
)
18+
19+
# START STUB ONLY
20+
21+
class _dist_td(TypedDict, total=False):
22+
path: str | None
23+
fileobj: BufferedReader | StreamReader | StringIO | None
24+
mapping: dict[str, str] | None
25+
scheme: str
26+
27+
class _locations_td(TypedDict, total=False):
28+
prefix: str
29+
purelib: str
30+
platlib: str
31+
scripts: str
32+
headers: str
33+
data: str
34+
namespace: list[str]
35+
lib: str # used internally
36+
37+
_PathVar = TypeVar("_PathVar", bound=list[str])
38+
39+
# END STUB ONLY
40+
41+
__all__ = [
42+
"Distribution",
43+
"BaseInstalledDistribution",
44+
"InstalledDistribution",
45+
"EggInfoDistribution",
46+
"DistributionPath",
47+
]
48+
49+
COMMANDS_FILENAME: str
50+
DIST_FILES: tuple[str, str, str, str, str, str, str]
51+
DISTINFO_EXT: str
52+
EXPORTS_FILENAME: str
53+
logger: Logger
54+
new_dist_class: type[InstalledDistribution]
55+
old_dist_class: type[EggInfoDistribution]
56+
57+
def get_dependent_dists( # documented
58+
dists: list[Distribution], dist: Distribution
59+
) -> list[Distribution]: ...
60+
def get_required_dists( # documented to return a list, implementation returns a set
61+
dists: list[Distribution], dist: Distribution
62+
) -> set[Distribution]: ...
63+
def make_dist(name: str, version: str, **kwargs: Unpack[_dist_td]) -> Distribution: ...
64+
def make_graph( # improperly documented or implemented; test_dependency_finder passes
65+
# in a set from finder.find
66+
dists: set[Distribution] | list[Distribution], scheme: str = ...
67+
) -> DependencyGraph: ...
68+
69+
class Distribution(): # documented
70+
build_time_dependency: bool
71+
# Not obvious from source, but it appears 'context' is the
72+
# execution_context parameter to distlib.markers.interpet.
73+
context: dict[str, str] | None
74+
digest: tuple[str, str] | None # documented as a property
75+
digests: dict[str, str] # documented as a property
76+
download_urls: set[str]
77+
extras: list[str] | set[str] | None
78+
key: str
79+
locator: Locator | None # documented as a property
80+
metadata: Metadata # documented as a property
81+
name: str # documented as a property
82+
requested: bool
83+
version: str # documented as a property
84+
def __eq__(self, other: object) -> bool: ...
85+
def __hash__(self) -> int: ...
86+
def __init__(self, metadata: Metadata) -> None: ...
87+
def _get_requirements(self, req_attr: str) -> set[str]: ...
88+
@property
89+
def build_requires(self) -> set[str]: ...
90+
@property
91+
def dev_requires(self) -> set[str]: ...
92+
@property
93+
def download_url(self) -> str: ... # documented
94+
def matches_requirement(self, req: str) -> bool: ...
95+
@property
96+
def meta_requires(self) -> set[str]: ...
97+
@property
98+
def name_and_version(self) -> str: ...
99+
@property
100+
def provides(self) -> list[str]: ...
101+
@property
102+
def run_requires(self) -> set[str]: ...
103+
@property
104+
def source_url(self) -> str | None: ...
105+
@property
106+
def test_requires(self) -> set[str]: ...
107+
108+
class BaseInstalledDistribution(Distribution):
109+
dist_path: DistributionPath | None
110+
hasher: str | None
111+
path: str
112+
def __init__(
113+
self, metadata: Metadata, path: str, env: DistributionPath | None = ...
114+
) -> None: ...
115+
def get_hash(self, data: bytes, hasher: str | None = ...) -> str: ...
116+
117+
class DependencyGraph():
118+
adjacency_list: dict[ # documented
119+
Distribution, list[tuple[Distribution, str | None]]
120+
]
121+
missing: dict[Distribution, list[str]] # documented
122+
reverse_list: dict[Distribution, list[str]] # documented
123+
def __init__(self) -> None: ...
124+
def _repr_dist(self, dist: Distribution) -> str: ...
125+
def add_distribution(self, distribution: Distribution) -> None: ... # documented
126+
def add_edge( # documented
127+
self, x: Distribution, y: Distribution, label: str | None = ...
128+
) -> None: ...
129+
def add_missing( # documented
130+
self,
131+
distribution: Distribution,
132+
requirement: str
133+
) -> None: ...
134+
def repr_node(self, dist: Distribution, level: int = ...) -> str: ... # documented
135+
def to_dot(self, f: StringIO, skip_disconnected: bool = ...) -> None: ...
136+
def topological_sort(self) -> tuple[list[Distribution], list[Distribution]]: ...
137+
138+
class DistributionPath(): # documented
139+
_cache: _Cache
140+
_cache_egg: _Cache
141+
_cache_enabled: bool
142+
_include_dist: bool
143+
_include_egg: bool
144+
_scheme: VersionScheme
145+
path: list[str]
146+
def __init__( # documented
147+
self, path: list[str] | None = ..., include_egg: bool = ...
148+
) -> None: ...
149+
def _generate_cache(self) -> None: ...
150+
def _get_cache_enabled(self) -> bool: ...
151+
def _set_cache_enabled(self, value: bool) -> None: ...
152+
def _yield_distributions(self) -> Iterator[Distribution]: ...
153+
@property
154+
def cache_enabled(self) -> bool: ...
155+
def clear_cache(self) -> None: ... # documented
156+
@classmethod
157+
def distinfo_dirname(cls, name: str, version: str) -> str: ...
158+
def get_distribution(self, name: str) -> Distribution | None: ... # documented
159+
def get_distributions(self) -> Iterator[Distribution]: ... # documented
160+
def get_exported_entries( # documented
161+
self, category: str, name: str | None = ...
162+
) -> Iterator[ExportEntry]: ...
163+
def get_file_path(self, name: str, relative_path: str) -> str: ...
164+
def provides_distribution(
165+
self, name: str, version: str | None = ...
166+
) -> Iterator[Distribution]: ...
167+
168+
class EggInfoDistribution(BaseInstalledDistribution):
169+
modules: list[str]
170+
path: str
171+
requested: bool
172+
shared_locations: dict[str, str]
173+
def __eq__(self, other: Self | None | object) -> bool: ...
174+
def __init__(self, path: str, env: DistributionPath | None = ...) -> None: ...
175+
def _get_metadata(self, path: str | bytes) -> Metadata: ...
176+
def check_installed_files(self) -> list[tuple[str, str, bool, bool]]: ...
177+
def list_distinfo_files(self, absolute: bool = ...) -> Iterator[str]: ...
178+
def list_installed_files( # documented
179+
self
180+
) -> list[tuple[str, str | None, int | None]]: ...
181+
182+
class InstalledDistribution(BaseInstalledDistribution):
183+
finder: ResourceFinder | None
184+
hasher: str
185+
locator: None
186+
modules: list[str]
187+
requested: bool # documented as a property
188+
def __eq__(self, other: object) -> bool: ...
189+
def __init__(
190+
self,
191+
path: str,
192+
metadata: Metadata | None = ...,
193+
env: DistributionPath | None = ...,
194+
) -> None: ...
195+
def _get_records(self) -> list[tuple[str, str | None, str | None]]: ...
196+
def check_installed_files( # documented
197+
self,
198+
) -> list[None | tuple[
199+
str,
200+
Literal["exists", "size", "hash"],
201+
str | bool,
202+
str | bool]]: ...
203+
@cached_property
204+
def exports(self) -> dict[str, dict[str, ExportEntry]]: ... # documented
205+
def get_distinfo_file(self, path: str) -> str: ...
206+
def get_distinfo_resource(
207+
self, path: str
208+
) -> Resource | ResourceContainer | None: ...
209+
def get_resource_path(self, relative_path: str) -> str: ...
210+
def list_distinfo_files(self) -> Iterator[str]: ... # documented
211+
def list_installed_files( # documented
212+
self
213+
) -> Iterator[tuple[str, str, str] | None]: ...
214+
def read_exports( # improperly documented to take a filename parameter
215+
self
216+
) -> dict[str, dict[str, ExportEntry]]: ...
217+
@cached_property
218+
def shared_locations(self) -> _locations_td: ...
219+
def write_exports( # improperly documented to take a filename parameter
220+
self,
221+
exports: dict[str, dict[str, ExportEntry]]
222+
) -> None: ...
223+
def write_installed_files(
224+
self, paths: list[str], prefix: str, dry_run: bool = ...
225+
) -> str | None: ...
226+
def write_shared_locations(
227+
self, paths: _locations_td, dry_run: bool = ...
228+
) -> str | None: ...
229+
230+
class _Cache():
231+
generated: bool
232+
name: dict[str, list[Distribution]]
233+
path: dict[str, Distribution]
234+
def __init__(self) -> None: ...
235+
def add(self, dist: Distribution) -> None: ...
236+
def clear(self) -> None: ...

0 commit comments

Comments
 (0)