Skip to content

Improve ipaddress module #7129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions stdlib/ipaddress.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import sys
from _typeshed import Self
from typing import Any, Container, Generic, Iterable, Iterator, SupportsInt, TypeVar, overload
from typing_extensions import Literal

# Undocumented length constants
IPV4LENGTH: int
IPV6LENGTH: int
IPV4LENGTH: Literal[32]
IPV6LENGTH: Literal[128]

_A = TypeVar("_A", IPv4Address, IPv6Address)
_N = TypeVar("_N", IPv4Network, IPv6Network)

def ip_address(address: object) -> IPv4Address | IPv6Address: ...
def ip_network(address: object, strict: bool = ...) -> IPv4Network | IPv6Network: ...
def ip_interface(address: object) -> IPv4Interface | IPv6Interface: ...
_RawIPAddress = int | str | bytes | IPv4Address | IPv6Address
_RawNetworkPart = IPv4Network | IPv6Network | IPv4Interface | IPv6Interface

def ip_address(address: _RawIPAddress) -> IPv4Address | IPv6Address: ...
def ip_network(address: _RawIPAddress | _RawNetworkPart, strict: bool = ...) -> IPv4Network | IPv6Network: ...
def ip_interface(address: _RawIPAddress | _RawNetworkPart) -> IPv4Interface | IPv6Interface: ...

class _IPAddressBase:
def __eq__(self, other: object) -> bool: ...
Expand Down Expand Up @@ -115,11 +119,23 @@ class _BaseInterface(_BaseAddress, Generic[_A, _N]):
@property
def with_prefixlen(self) -> str: ...

class IPv4Address(_BaseAddress): ...
class IPv4Network(_BaseNetwork[IPv4Address]): ...
class _BaseV4:
@property
def version(self) -> Literal[4]: ...
@property
def max_prefixlen(self) -> Literal[32]: ...

class IPv4Address(_BaseV4, _BaseAddress): ...
class IPv4Network(_BaseV4, _BaseNetwork[IPv4Address]): ...
class IPv4Interface(IPv4Address, _BaseInterface[IPv4Address, IPv4Network]): ...

class IPv6Address(_BaseAddress):
class _BaseV6:
@property
def version(self) -> Literal[6]: ...
@property
def max_prefixlen(self) -> Literal[128]: ...

class IPv6Address(_BaseV6, _BaseAddress):
@property
def ipv4_mapped(self) -> IPv4Address | None: ...
@property
Expand All @@ -132,7 +148,7 @@ class IPv6Address(_BaseAddress):
@property
def scope_id(self) -> str | None: ...

class IPv6Network(_BaseNetwork[IPv6Address]):
class IPv6Network(_BaseV6, _BaseNetwork[IPv6Address]):
@property
def is_site_local(self) -> bool: ...

Expand Down