Skip to content

Commit

Permalink
Add stubs for pkg_resources._vendor.packaging (#10423)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Jul 15, 2023
1 parent a83e559 commit 47fc836
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 9 deletions.
16 changes: 7 additions & 9 deletions stubs/setuptools/pkg_resources/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from re import Pattern
from typing import IO, Any, ClassVar, Protocol, TypeVar, overload, type_check_only
from typing_extensions import Literal, Self, TypeAlias

_Version: TypeAlias = Incomplete # from packaging.version
from ._vendor.packaging import requirements as packaging_requirements, version as packaging_version

_T = TypeVar("_T")
_D = TypeVar("_D", bound=Distribution)
Expand Down Expand Up @@ -83,16 +83,14 @@ class Environment:

def parse_requirements(strs: str | Iterable[str]) -> Generator[Requirement, None, None]: ...

class Requirement:
class RequirementParseError(packaging_requirements.InvalidRequirement): ...

class Requirement(packaging_requirements.Requirement):
unsafe_name: str
project_name: str
key: str
extras: tuple[str, ...]
extras: tuple[str, ...] # type: ignore[assignment] # incompatible override of attribute on base class
specs: list[tuple[str, str]]
url: str | None
# TODO: change this to packaging.markers.Marker | None once we can import
# packaging.markers
marker: Incomplete | None
def __init__(self, requirement_string: str) -> None: ...
@staticmethod
def parse(s: str | Iterable[str]) -> Requirement: ...
Expand Down Expand Up @@ -268,7 +266,7 @@ class Distribution(NullProvider):
@property
def version(self) -> str: ...
@property
def parsed_version(self) -> tuple[str, ...]: ...
def parsed_version(self) -> packaging_version.Version: ...
py_version: str
platform: str | None
precedence: int
Expand Down Expand Up @@ -339,7 +337,7 @@ class FileMetadata(EmptyProvider):

class PEP440Warning(RuntimeWarning): ...

parse_version = _Version
parse_version = packaging_version.Version

def yield_lines(iterable: _NestedStr) -> Generator[str, None, None]: ...
def split_sections(s: _NestedStr) -> Generator[tuple[str | None, list[str]], None, None]: ...
Expand Down
8 changes: 8 additions & 0 deletions stubs/setuptools/pkg_resources/_vendor/packaging/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__title__: str
__summary__: str
__uri__: str
__version__: str
__author__: str
__email__: str
__license__: str
__copyright__: str
13 changes: 13 additions & 0 deletions stubs/setuptools/pkg_resources/_vendor/packaging/markers.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
__all__ = ["InvalidMarker", "UndefinedComparison", "UndefinedEnvironmentName", "Marker", "default_environment"]

class InvalidMarker(ValueError): ...
class UndefinedComparison(ValueError): ...
class UndefinedEnvironmentName(ValueError): ...

def default_environment() -> dict[str, str]: ...

class Marker:
def __init__(self, marker: str) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def evaluate(self, environment: dict[str, str] | None = None) -> bool: ...
14 changes: 14 additions & 0 deletions stubs/setuptools/pkg_resources/_vendor/packaging/requirements.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .markers import Marker
from .specifiers import SpecifierSet

class InvalidRequirement(ValueError): ...

class Requirement:
name: str
url: str | None
extras: set[str]
specifier: SpecifierSet
marker: Marker | None
def __init__(self, requirement_str: str) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
66 changes: 66 additions & 0 deletions stubs/setuptools/pkg_resources/_vendor/packaging/specifiers.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import abc
from collections.abc import Iterable, Iterator
from typing import TypeVar
from typing_extensions import TypeAlias

from .version import Version

# These exist at runtime, hence the public names
UnparsedVersion: TypeAlias = Version | str
UnparsedVersionVar = TypeVar("UnparsedVersionVar", bound=UnparsedVersion) # noqa: Y001

class InvalidSpecifier(ValueError): ...

class BaseSpecifier(metaclass=abc.ABCMeta):
@abc.abstractmethod
def __str__(self) -> str: ...
@abc.abstractmethod
def __hash__(self) -> int: ...
@abc.abstractmethod
def __eq__(self, other: object) -> bool: ...
@property
@abc.abstractmethod
def prereleases(self) -> bool | None: ...
@prereleases.setter
def prereleases(self, value: bool) -> None: ...
@abc.abstractmethod
def contains(self, item: str, prereleases: bool | None = None) -> bool: ...
@abc.abstractmethod
def filter(self, iterable: Iterable[UnparsedVersionVar], prereleases: bool | None = None) -> Iterator[UnparsedVersionVar]: ...

class Specifier(BaseSpecifier):
def __init__(self, spec: str = "", prereleases: bool | None = None) -> None: ...
@property # type: ignore[override]
def prereleases(self) -> bool: ...
@prereleases.setter
def prereleases(self, value: bool) -> None: ...
@property
def operator(self) -> str: ...
@property
def version(self) -> str: ...
def __str__(self) -> str: ... # noqa: Y029 # needed as it's abstract on the superclass
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __contains__(self, item: Version | str) -> bool: ...
def contains(self, item: UnparsedVersion, prereleases: bool | None = None) -> bool: ...
def filter(self, iterable: Iterable[UnparsedVersionVar], prereleases: bool | None = None) -> Iterator[UnparsedVersionVar]: ...

class SpecifierSet(BaseSpecifier):
def __init__(self, spec: str = "", prereleases: bool | None = None) -> None: ...
@property
def prereleases(self) -> bool | None: ...
@prereleases.setter
def prereleases(self, value: bool) -> None: ...
@property
def operator(self) -> str: ...
@property
def version(self) -> str: ...
def __str__(self) -> str: ... # noqa: Y029 # needed as it's abstract on the superclass
def __hash__(self) -> int: ...
def __and__(self, other: SpecifierSet | str) -> SpecifierSet: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[Specifier]: ...
def __eq__(self, other: object) -> bool: ...
def __contains__(self, item: UnparsedVersion) -> bool: ...
def contains(self, item: UnparsedVersion, prereleases: bool | None = None, installed: bool | None = None) -> bool: ...
def filter(self, iterable: Iterable[UnparsedVersionVar], prereleases: bool | None = None) -> Iterator[UnparsedVersionVar]: ...
49 changes: 49 additions & 0 deletions stubs/setuptools/pkg_resources/_vendor/packaging/version.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from typing_extensions import Final

__all__ = ["VERSION_PATTERN", "parse", "Version", "InvalidVersion"]

def parse(version: str) -> Version: ...

class InvalidVersion(ValueError): ...

VERSION_PATTERN: Final[str]

class _BaseVersion:
def __hash__(self) -> int: ...
def __lt__(self, other: _BaseVersion) -> bool: ...
def __le__(self, other: _BaseVersion) -> bool: ...
def __ge__(self, other: _BaseVersion) -> bool: ...
def __gt__(self, other: _BaseVersion) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

class Version(_BaseVersion):
def __init__(self, version: str) -> None: ...
@property
def epoch(self) -> int: ...
@property
def release(self) -> tuple[int, ...]: ...
@property
def pre(self) -> tuple[str, int] | None: ...
@property
def post(self) -> int | None: ...
@property
def dev(self) -> int | None: ...
@property
def local(self) -> str | None: ...
@property
def public(self) -> str: ...
@property
def base_version(self) -> str: ...
@property
def is_prerelease(self) -> bool: ...
@property
def is_postrelease(self) -> bool: ...
@property
def is_devrelease(self) -> bool: ...
@property
def major(self) -> int: ...
@property
def minor(self) -> int: ...
@property
def micro(self) -> int: ...

0 comments on commit 47fc836

Please sign in to comment.