move socket.error classes from _socket to socket (#12746)

They're implemented in C, but consider themselves to live in
socket.
This commit is contained in:
Stephen Morton
2024-10-05 18:19:34 -07:00
committed by GitHub
parent 8cb6df0201
commit f30d367c7a
2 changed files with 18 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
import sys
from _typeshed import ReadableBuffer, WriteableBuffer
from collections.abc import Iterable
from socket import error as error, gaierror as gaierror, herror as herror, timeout as timeout
from typing import Any, SupportsIndex, overload
from typing_extensions import TypeAlias
@@ -666,18 +667,6 @@ if sys.platform != "win32":
if sys.platform != "win32" and sys.platform != "darwin":
IPX_TYPE: int
# ===== Exceptions =====
error = OSError
class herror(error): ...
class gaierror(error): ...
if sys.version_info >= (3, 10):
timeout = TimeoutError
else:
class timeout(error): ...
# ===== Classes =====
class socket:
@@ -687,8 +676,9 @@ class socket:
def type(self) -> int: ...
@property
def proto(self) -> int: ...
# F811: "Redefinition of unused `timeout`"
@property
def timeout(self) -> float | None: ...
def timeout(self) -> float | None: ... # noqa: F811
if sys.platform == "win32":
def __init__(
self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | bytes | None = ...
@@ -788,7 +778,9 @@ def inet_ntoa(packed_ip: ReadableBuffer, /) -> str: ...
def inet_pton(address_family: int, ip_string: str, /) -> bytes: ...
def inet_ntop(address_family: int, packed_ip: ReadableBuffer, /) -> str: ...
def getdefaulttimeout() -> float | None: ...
def setdefaulttimeout(timeout: float | None, /) -> None: ...
# F811: "Redefinition of unused `timeout`"
def setdefaulttimeout(timeout: float | None, /) -> None: ... # noqa: F811
if sys.platform != "win32":
def sethostname(name: str, /) -> None: ...

View File

@@ -109,8 +109,6 @@ from _socket import (
_RetAddress as _RetAddress,
close as close,
dup as dup,
error as error,
gaierror as gaierror,
getdefaulttimeout as getdefaulttimeout,
gethostbyaddr as gethostbyaddr,
gethostbyname as gethostbyname,
@@ -121,7 +119,6 @@ from _socket import (
getservbyname as getservbyname,
getservbyport as getservbyport,
has_ipv6 as has_ipv6,
herror as herror,
htonl as htonl,
htons as htons,
if_indextoname as if_indextoname,
@@ -134,7 +131,6 @@ from _socket import (
ntohl as ntohl,
ntohs as ntohs,
setdefaulttimeout as setdefaulttimeout,
timeout as timeout,
)
from _typeshed import ReadableBuffer, Unused, WriteableBuffer
from collections.abc import Iterable
@@ -486,6 +482,18 @@ EBADF: int
EAGAIN: int
EWOULDBLOCK: int
# These errors are implemented in _socket at runtime
# but they consider themselves to live in socket so we'll put them here.
error = OSError
class herror(error): ...
class gaierror(error): ...
if sys.version_info >= (3, 10):
timeout = TimeoutError
else:
class timeout(error): ...
class AddressFamily(IntEnum):
AF_INET = 2
AF_INET6 = 10