diff --git a/circuitpython_typing/__init__.py b/circuitpython_typing/__init__.py index a826ae2..1dff3d5 100644 --- a/circuitpython_typing/__init__.py +++ b/circuitpython_typing/__init__.py @@ -15,8 +15,24 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Typing.git" import array -from typing import Union, Optional -from typing_extensions import Protocol, TypeAlias # Safety import for Python 3.7 +from typing import TYPE_CHECKING, Optional, Union + +# Protocol was introduced in Python 3.8, TypeAlias in 3.10 +from typing_extensions import Protocol, TypeAlias + +# pylint: disable=used-before-assignment +if TYPE_CHECKING: + import alarm + import audiocore + import audiomixer + import audiomp3 + import rgbmatrix + import synthio + import ulab + from alarm.pin import PinAlarm + from alarm.time import TimeAlarm + from ulab.numpy import ndarray + # Lists below are alphabetized. diff --git a/circuitpython_typing/http.py b/circuitpython_typing/http.py index 3b83fcb..8b6fedd 100644 --- a/circuitpython_typing/http.py +++ b/circuitpython_typing/http.py @@ -11,9 +11,10 @@ * Author(s): Alec Delaney """ +from adafruit_requests import Response + # Protocol was introduced in Python 3.8. from typing_extensions import Protocol -from adafruit_requests import Response class HTTPProtocol(Protocol): diff --git a/circuitpython_typing/io.py b/circuitpython_typing/io.py index 20cd5c5..0bc56a2 100644 --- a/circuitpython_typing/io.py +++ b/circuitpython_typing/io.py @@ -38,7 +38,11 @@ def value(self) -> float: on the specifics of the class. """ + # TODO: this should be `value(self, input_value: float, /)` but can't + # because currently mpy files are built and the `/` param isn't supported + # in micro-python. + # https://github.com/adafruit/Adafruit_CircuitPython_Typing/issues/36 # pylint: disable=no-self-use,unused-argument @value.setter - def value(self, input_value: float, /): + def value(self, input_value: float): ... diff --git a/circuitpython_typing/led.py b/circuitpython_typing/led.py index 200a5e0..0dfca00 100644 --- a/circuitpython_typing/led.py +++ b/circuitpython_typing/led.py @@ -11,8 +11,9 @@ * Author(s): Alec Delaney """ +from typing import Tuple, Union + # Protocol was introduced in Python 3.8, TypeAlias in 3.10 -from typing import Union, Tuple from typing_extensions import Protocol, TypeAlias ColorBasedColorUnion: TypeAlias = Union[int, Tuple[int, int, int]] diff --git a/circuitpython_typing/pil.py b/circuitpython_typing/pil.py index 9dc8a5d..4807ea9 100644 --- a/circuitpython_typing/pil.py +++ b/circuitpython_typing/pil.py @@ -11,8 +11,10 @@ * Author(s): Alec Delaney """ -from typing import Tuple, Optional, Callable -from typing_extensions import Protocol # Safety import for Python 3.7 +from typing import Callable, Optional, Tuple + +# Protocol was introduced in Python 3.8 +from typing_extensions import Protocol class PixelAccess(Protocol): diff --git a/circuitpython_typing/socket.py b/circuitpython_typing/socket.py index cbd2287..c1eafab 100644 --- a/circuitpython_typing/socket.py +++ b/circuitpython_typing/socket.py @@ -16,7 +16,6 @@ # Protocol was introduced in Python 3.8, TypeAlias in 3.10 from typing_extensions import Protocol, TypeAlias - # Based on https://github.com/python/typeshed/blob/master/stdlib/_socket.pyi __all__ = [ @@ -126,4 +125,18 @@ def TLS_MODE(self) -> int: # pylint: disable=invalid-name """Constant representing that a socket's connection mode is TLS.""" -SSLContextType: TypeAlias = Union[SSLContext, "_FakeSSLContext"] +# pylint: disable=too-few-public-methods +class _FakeSSLSocket: + """Describes the structure every fake SSL socket type must have.""" + + +class _FakeSSLContext: + """Describes the structure every fake SSL context type must have.""" + + def wrap_socket( + self, socket: CircuitPythonSocketType, server_hostname: Optional[str] = None + ) -> _FakeSSLSocket: + """Wrap socket and return a new one that uses the methods from the original.""" + + +SSLContextType: TypeAlias = Union[SSLContext, _FakeSSLContext] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy