mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-16 08:47:39 +08:00
Add additional type annotations to ipaddress stub (#1654)
Makes heavier use of generics to minimize code. Fixes some incorrect types. Also reordered to allow easy comparison against class listings and documentation.
This commit is contained in:
@@ -1,201 +1,150 @@
|
||||
from typing import Any, Iterable, Iterator, Optional, SupportsInt, Tuple, TypeVar, Union
|
||||
import sys
|
||||
from typing import (Any, Container, Generic, Iterable, Iterator, Optional,
|
||||
overload, SupportsInt, Tuple, TypeVar, Union)
|
||||
|
||||
IPV4LENGTH = ... # type: int
|
||||
IPV6LENGTH = ... # type: int
|
||||
# Undocumented length constants
|
||||
IPV4LENGTH: int
|
||||
IPV6LENGTH: int
|
||||
|
||||
class AddressValueError(ValueError): ...
|
||||
class NetmaskValueError(ValueError): ...
|
||||
_A = TypeVar("_A", IPv4Address, IPv6Address)
|
||||
_N = TypeVar("_N", IPv4Network, IPv6Network)
|
||||
_T = TypeVar("_T")
|
||||
|
||||
class _TotalOrderingMixin:
|
||||
def __eq__(self, other): ...
|
||||
def __ne__(self, other): ...
|
||||
def __lt__(self, other): ...
|
||||
def __le__(self, other): ...
|
||||
def __gt__(self, other): ...
|
||||
def __ge__(self, other): ...
|
||||
def ip_address(address: object) -> Union[IPv4Address, IPv6Address]: ...
|
||||
def ip_network(address: object, strict: bool = ...) -> Union[IPv4Network, IPv6Network]: ...
|
||||
def ip_interface(address: object) -> Union[IPv4Interface, IPv6Interface]: ...
|
||||
|
||||
class _IPAddressBase(_TotalOrderingMixin):
|
||||
class _IPAddressBase:
|
||||
def __eq__(self, other: Any) -> bool: ...
|
||||
def __ge__(self: _T, other: _T) -> bool: ...
|
||||
def __gt__(self: _T, other: _T) -> bool: ...
|
||||
def __le__(self: _T, other: _T) -> bool: ...
|
||||
def __lt__(self: _T, other: _T) -> bool: ...
|
||||
def __ne__(self, other: Any) -> bool: ...
|
||||
@property
|
||||
def exploded(self): ...
|
||||
def compressed(self) -> str: ...
|
||||
@property
|
||||
def compressed(self): ...
|
||||
def exploded(self) -> str: ...
|
||||
if sys.version_info >= (3, 5):
|
||||
@property
|
||||
def reverse_pointer(self) -> str: ...
|
||||
@property
|
||||
def version(self): ...
|
||||
def version(self) -> int: ...
|
||||
|
||||
class _BaseAddress(_IPAddressBase, SupportsInt):
|
||||
def __init__(self, address) -> None: ...
|
||||
def __int__(self) -> int: ...
|
||||
def __eq__(self, other): ...
|
||||
def __lt__(self, other): ...
|
||||
def __add__(self, other): ...
|
||||
def __sub__(self, other): ...
|
||||
def __hash__(self): ...
|
||||
|
||||
class _BaseNetwork(_IPAddressBase):
|
||||
def __init__(self, address) -> None: ...
|
||||
def hosts(self): ...
|
||||
def __iter__(self): ...
|
||||
def __getitem__(self, n): ...
|
||||
def __lt__(self, other): ...
|
||||
def __eq__(self, other): ...
|
||||
def __hash__(self): ...
|
||||
def __contains__(self, other): ...
|
||||
def overlaps(self, other): ...
|
||||
@property
|
||||
def broadcast_address(self): ...
|
||||
@property
|
||||
def hostmask(self): ...
|
||||
@property
|
||||
def with_prefixlen(self): ...
|
||||
@property
|
||||
def with_netmask(self): ...
|
||||
@property
|
||||
def with_hostmask(self): ...
|
||||
@property
|
||||
def num_addresses(self): ...
|
||||
@property
|
||||
def prefixlen(self): ...
|
||||
def address_exclude(self, other): ...
|
||||
def compare_networks(self, other): ...
|
||||
def subnets(self, prefixlen_diff=..., new_prefix=...): ...
|
||||
def supernet(self, prefixlen_diff=..., new_prefix=...): ...
|
||||
@property
|
||||
def is_multicast(self): ...
|
||||
@property
|
||||
def is_reserved(self): ...
|
||||
@property
|
||||
def is_link_local(self): ...
|
||||
@property
|
||||
def is_private(self): ...
|
||||
@property
|
||||
def is_global(self): ...
|
||||
@property
|
||||
def is_unspecified(self): ...
|
||||
@property
|
||||
def is_loopback(self): ...
|
||||
|
||||
class _BaseV4:
|
||||
def __init__(self, address) -> None: ...
|
||||
@property
|
||||
def max_prefixlen(self): ...
|
||||
@property
|
||||
def version(self): ...
|
||||
|
||||
class IPv4Address(_BaseV4, _BaseAddress):
|
||||
def __init__(self, address: object) -> None: ...
|
||||
def __add__(self: _T, other: int) -> _T: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def __int__(self) -> int: ...
|
||||
def __sub__(self: _T, other: int) -> _T: ...
|
||||
if sys.version_info >= (3, 4):
|
||||
@property
|
||||
def is_global(self) -> bool: ...
|
||||
@property
|
||||
def packed(self) -> bytes: ...
|
||||
@property
|
||||
def is_reserved(self) -> bool: ...
|
||||
@property
|
||||
def is_private(self) -> bool: ...
|
||||
@property
|
||||
def is_multicast(self) -> bool: ...
|
||||
@property
|
||||
def is_unspecified(self) -> bool: ...
|
||||
def is_link_local(self) -> bool: ...
|
||||
@property
|
||||
def is_loopback(self) -> bool: ...
|
||||
@property
|
||||
def is_link_local(self) -> bool: ...
|
||||
def is_multicast(self) -> bool: ...
|
||||
@property
|
||||
def is_private(self) -> bool: ...
|
||||
@property
|
||||
def is_reserved(self) -> bool: ...
|
||||
@property
|
||||
def is_unspecified(self) -> bool: ...
|
||||
@property
|
||||
def max_prefixlen(self) -> int: ...
|
||||
@property
|
||||
def packed(self) -> bytes: ...
|
||||
|
||||
class IPv4Interface(IPv4Address):
|
||||
network = ... # type: IPv4Network
|
||||
netmask = ... # type: IPv4Address
|
||||
hostmask = ... # type: IPv4Address
|
||||
def __init__(self, address: object) -> None: ...
|
||||
def __eq__(self, other: Any) -> bool: ...
|
||||
def __lt__(self, other: Any) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
class _BaseNetwork(_IPAddressBase, Container, Iterable[_A], Generic[_A]):
|
||||
network_address: _A
|
||||
netmask: _A
|
||||
def __init__(self, address: object, strict: bool = ...) -> None: ...
|
||||
def __contains__(self, other: Any) -> bool: ...
|
||||
def __getitem__(self, n: int) -> _A: ...
|
||||
def __iter__(self) -> Iterator[_A]: ...
|
||||
def address_exclude(self: _T, other: _T) -> Iterator[_T]: ...
|
||||
@property
|
||||
def ip(self) -> IPv4Address: ...
|
||||
def broadcast_address(self) -> _A: ...
|
||||
def compare_networks(self: _T, other: _T) -> int: ...
|
||||
def hosts(self) -> Iterator[_A]: ...
|
||||
@property
|
||||
def with_prefixlen(self) -> str: ...
|
||||
def is_global(self) -> bool: ...
|
||||
@property
|
||||
def is_link_local(self) -> bool: ...
|
||||
@property
|
||||
def is_loopback(self) -> bool: ...
|
||||
@property
|
||||
def is_multicast(self) -> bool: ...
|
||||
@property
|
||||
def is_private(self) -> bool: ...
|
||||
@property
|
||||
def is_reserved(self) -> bool: ...
|
||||
@property
|
||||
def is_unspecified(self) -> bool: ...
|
||||
@property
|
||||
def max_prefixlen(self) -> int: ...
|
||||
@property
|
||||
def num_addresses(self) -> int: ...
|
||||
def overlaps(self: _T, other: _T) -> bool: ...
|
||||
@property
|
||||
def prefixlen(self) -> int: ...
|
||||
def subnets(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> Iterator[_T]: ...
|
||||
def supernet(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> Iterator[_T]: ...
|
||||
@property
|
||||
def with_hostmask(self) -> str: ...
|
||||
@property
|
||||
def with_netmask(self) -> str: ...
|
||||
@property
|
||||
def with_prefixlen(self) -> str: ...
|
||||
|
||||
class _BaseInterface(_BaseAddress, Generic[_A, _N]):
|
||||
hostmask: _A
|
||||
netmask: _A
|
||||
network: _N
|
||||
@property
|
||||
def ip(self) -> _A: ...
|
||||
@property
|
||||
def with_hostmask(self) -> str: ...
|
||||
@property
|
||||
def with_netmask(self) -> str: ...
|
||||
@property
|
||||
def with_prefixlen(self) -> str: ...
|
||||
|
||||
class IPv4Network(_BaseV4, _BaseNetwork):
|
||||
network_address = ... # type: IPv4Address
|
||||
netmask = ... # type: IPv4Address
|
||||
hosts = ... # type: Iterator[IPv4Address]
|
||||
def __init__(self, address: object, strict: bool = ...) -> None: ...
|
||||
@property
|
||||
def is_global(self) -> bool: ...
|
||||
class IPv4Address(_BaseAddress): ...
|
||||
class IPv4Network(_BaseNetwork[IPv4Address]): ...
|
||||
class IPv4Interface(IPv4Address, _BaseInterface[IPv4Address, IPv4Network]): ...
|
||||
|
||||
class _BaseV6:
|
||||
def __init__(self, address) -> None: ...
|
||||
@property
|
||||
def max_prefixlen(self): ...
|
||||
@property
|
||||
def version(self): ...
|
||||
|
||||
class IPv6Address(_BaseV6, _BaseAddress):
|
||||
def __init__(self, address: object) -> None: ...
|
||||
@property
|
||||
def packed(self) -> bytes: ...
|
||||
@property
|
||||
def is_multicast(self) -> bool: ...
|
||||
@property
|
||||
def is_reserved(self) -> bool: ...
|
||||
@property
|
||||
def is_link_local(self) -> bool: ...
|
||||
@property
|
||||
def is_site_local(self) -> bool: ...
|
||||
@property
|
||||
def is_private(self) -> bool: ...
|
||||
@property
|
||||
def is_global(self) -> bool: ...
|
||||
@property
|
||||
def is_unspecified(self) -> bool: ...
|
||||
@property
|
||||
def is_loopback(self) -> bool: ...
|
||||
class IPv6Address(_BaseAddress):
|
||||
@property
|
||||
def ipv4_mapped(self) -> Optional[IPv4Address]: ...
|
||||
@property
|
||||
def teredo(self) -> Optional[Tuple[IPv4Address, IPv4Address]]: ...
|
||||
def is_site_local(self) -> bool: ...
|
||||
@property
|
||||
def sixtofour(self) -> Optional[IPv4Address]: ...
|
||||
@property
|
||||
def teredo(self) -> Optional[Tuple[IPv4Address, IPv4Address]]: ...
|
||||
|
||||
class IPv6Interface(IPv6Address):
|
||||
network = ... # type: IPv6Network
|
||||
netmask = ... # type: IPv6Address
|
||||
hostmask = ... # type: IPv6Address
|
||||
def __init__(self, address: object) -> None: ...
|
||||
def __eq__(self, other: Any) -> bool: ...
|
||||
def __lt__(self, other: Any) -> bool: ...
|
||||
def __hash__(self) -> int: ...
|
||||
@property
|
||||
def ip(self) -> IPv6Address: ...
|
||||
@property
|
||||
def with_prefixlen(self) -> str: ...
|
||||
@property
|
||||
def with_netmask(self) -> str: ...
|
||||
@property
|
||||
def with_hostmask(self) -> str: ...
|
||||
@property
|
||||
def is_unspecified(self) -> bool: ...
|
||||
@property
|
||||
def is_loopback(self) -> bool: ...
|
||||
|
||||
class IPv6Network(_BaseV6, _BaseNetwork):
|
||||
network_address = ... # type: IPv6Address
|
||||
netmask = ... # type: IPv6Address
|
||||
def __init__(self, address: object, strict: bool = ...) -> None: ...
|
||||
def hosts(self) -> Iterator[IPv6Address]: ...
|
||||
class IPv6Network(_BaseNetwork[IPv6Address]):
|
||||
@property
|
||||
def is_site_local(self) -> bool: ...
|
||||
|
||||
_ip_address = Union[IPv4Address, IPv6Address]
|
||||
_ip_network = Union[IPv4Network, IPv6Network]
|
||||
_ip_interface = Union[IPv4Interface, IPv6Interface]
|
||||
_AnyIPAddress = TypeVar("_AnyIPAddress", IPv4Address, IPv6Address)
|
||||
class IPv6Interface(IPv6Address, _BaseInterface[IPv6Address, IPv6Network]): ...
|
||||
|
||||
def ip_address(address: object) -> _ip_address: ...
|
||||
def ip_network(address: object, strict: bool = ...) -> _ip_network: ...
|
||||
def ip_interface(address: object) -> _ip_interface: ...
|
||||
def v4_int_to_packed(address: int) -> bytes: ...
|
||||
def v6_int_to_packed(address: int) -> bytes: ...
|
||||
def summarize_address_range(first: _AnyIPAddress, _AnyIPAddress) -> Iterator[_AnyIPAddress]: ...
|
||||
def collapse_addresses(addresses: Iterable[_AnyIPAddress]) -> Iterator[_AnyIPAddress]: ...
|
||||
def get_mixed_type_key(obj): ...
|
||||
@overload
|
||||
def summarize_address_range(first: IPv4Address, last: IPv4Address) -> Iterator[IPv4Network]: ...
|
||||
@overload
|
||||
def summarize_address_range(first: IPv6Address, last: IPv6Address) -> Iterator[IPv6Network]: ...
|
||||
def collapse_addresses(addresses: Iterable[_N]) -> Iterator[_N]: ...
|
||||
@overload
|
||||
def get_mixed_type_key(obj: _A) -> Tuple[int, _A]: ...
|
||||
@overload
|
||||
def get_mixed_type_key(obj: IPv4Network) -> Tuple[int, IPv4Address, IPv4Address]: ...
|
||||
@overload
|
||||
def get_mixed_type_key(obj: IPv6Network) -> Tuple[int, IPv6Address, IPv6Address]: ...
|
||||
|
||||
class AddressValueError(ValueError): ...
|
||||
class NetmaskValueError(ValueError): ...
|
||||
|
||||
Reference in New Issue
Block a user