Skip to content

Commit 66fb48c

Browse files
committed
Remove duplicate typing
1 parent 16d658d commit 66fb48c

File tree

1 file changed

+7
-87
lines changed

1 file changed

+7
-87
lines changed

adafruit_requests.py

Lines changed: 7 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -46,94 +46,14 @@
4646

4747
from adafruit_connection_manager import get_connection_manager
4848

49-
5049
if not sys.implementation.name == "circuitpython":
51-
from ssl import SSLContext
52-
from types import ModuleType, TracebackType
53-
from typing import Any, Dict, Optional, Tuple, Type, Union
54-
55-
try:
56-
from typing import Protocol
57-
except ImportError:
58-
from typing_extensions import Protocol
59-
60-
# Based on https://github.com/python/typeshed/blob/master/stdlib/_socket.pyi
61-
class CommonSocketType(Protocol):
62-
"""Describes the common structure every socket type must have."""
63-
64-
def send(self, data: bytes, flags: int = ...) -> None:
65-
"""Send data to the socket. The meaning of the optional flags kwarg is
66-
implementation-specific."""
67-
68-
def settimeout(self, value: Optional[float]) -> None:
69-
"""Set a timeout on blocking socket operations."""
70-
71-
def close(self) -> None:
72-
"""Close the socket."""
73-
74-
class CommonCircuitPythonSocketType(CommonSocketType, Protocol):
75-
"""Describes the common structure every CircuitPython socket type must have."""
76-
77-
def connect(
78-
self,
79-
address: Tuple[str, int],
80-
conntype: Optional[int] = ...,
81-
) -> None:
82-
"""Connect to a remote socket at the provided (host, port) address. The conntype
83-
kwarg optionally may indicate SSL or not, depending on the underlying interface.
84-
"""
85-
86-
class SupportsRecvWithFlags(Protocol):
87-
"""Describes a type that posseses a socket recv() method supporting the flags kwarg."""
88-
89-
def recv(self, bufsize: int = ..., flags: int = ...) -> bytes:
90-
"""Receive data from the socket. The return value is a bytes object representing
91-
the data received. The maximum amount of data to be received at once is specified
92-
by bufsize. The meaning of the optional flags kwarg is implementation-specific.
93-
"""
94-
95-
class SupportsRecvInto(Protocol):
96-
"""Describes a type that possesses a socket recv_into() method."""
97-
98-
def recv_into(
99-
self, buffer: bytearray, nbytes: int = ..., flags: int = ...
100-
) -> int:
101-
"""Receive up to nbytes bytes from the socket, storing the data into the provided
102-
buffer. If nbytes is not specified (or 0), receive up to the size available in the
103-
given buffer. The meaning of the optional flags kwarg is implementation-specific.
104-
Returns the number of bytes received."""
105-
106-
class CircuitPythonSocketType(
107-
CommonCircuitPythonSocketType,
108-
SupportsRecvInto,
109-
SupportsRecvWithFlags,
110-
Protocol,
111-
): # pylint: disable=too-many-ancestors
112-
"""Describes the structure every modern CircuitPython socket type must have."""
113-
114-
class StandardPythonSocketType(
115-
CommonSocketType, SupportsRecvInto, SupportsRecvWithFlags, Protocol
116-
):
117-
"""Describes the structure every standard Python socket type must have."""
118-
119-
def connect(self, address: Union[Tuple[Any, ...], str, bytes]) -> None:
120-
"""Connect to a remote socket at the provided address."""
121-
122-
SocketType = Union[
123-
CircuitPythonSocketType,
124-
StandardPythonSocketType,
125-
]
126-
127-
SocketpoolModuleType = ModuleType
128-
129-
class InterfaceType(Protocol):
130-
"""Describes the structure every interface type must have."""
131-
132-
@property
133-
def TLS_MODE(self) -> int: # pylint: disable=invalid-name
134-
"""Constant representing that a socket's connection mode is TLS."""
135-
136-
SSLContextType = Union[SSLContext, "_FakeSSLContext"]
50+
from types import TracebackType
51+
from typing import Any, Dict, Optional, Type
52+
from adafruit_connection_manager import (
53+
SocketType,
54+
SocketpoolModuleType,
55+
SSLContextType,
56+
)
13757

13858

13959
class _RawResponse:

0 commit comments

Comments
 (0)