Skip to content

Commit 45263eb

Browse files
authored
Merge pull request #35 from justmobilize/typing-fixes
Typing fixes
2 parents 0dc12df + af887aa commit 45263eb

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

circuitpython_typing/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,24 @@
1515
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Typing.git"
1616

1717
import array
18-
from typing import Union, Optional
19-
from typing_extensions import Protocol, TypeAlias # Safety import for Python 3.7
18+
from typing import TYPE_CHECKING, Optional, Union
19+
20+
# Protocol was introduced in Python 3.8, TypeAlias in 3.10
21+
from typing_extensions import Protocol, TypeAlias
22+
23+
# pylint: disable=used-before-assignment
24+
if TYPE_CHECKING:
25+
import alarm
26+
import audiocore
27+
import audiomixer
28+
import audiomp3
29+
import rgbmatrix
30+
import synthio
31+
import ulab
32+
from alarm.pin import PinAlarm
33+
from alarm.time import TimeAlarm
34+
from ulab.numpy import ndarray
35+
2036

2137
# Lists below are alphabetized.
2238

circuitpython_typing/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
* Author(s): Alec Delaney
1212
"""
1313

14+
from adafruit_requests import Response
15+
1416
# Protocol was introduced in Python 3.8.
1517
from typing_extensions import Protocol
16-
from adafruit_requests import Response
1718

1819

1920
class HTTPProtocol(Protocol):

circuitpython_typing/io.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ def value(self) -> float:
3838
on the specifics of the class.
3939
"""
4040

41+
# TODO: this should be `value(self, input_value: float, /)` but can't
42+
# because currently mpy files are built and the `/` param isn't supported
43+
# in micro-python.
44+
# https://github.com/adafruit/Adafruit_CircuitPython_Typing/issues/36
4145
# pylint: disable=no-self-use,unused-argument
4246
@value.setter
43-
def value(self, input_value: float, /):
47+
def value(self, input_value: float):
4448
...

circuitpython_typing/led.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
* Author(s): Alec Delaney
1212
"""
1313

14+
from typing import Tuple, Union
15+
1416
# Protocol was introduced in Python 3.8, TypeAlias in 3.10
15-
from typing import Union, Tuple
1617
from typing_extensions import Protocol, TypeAlias
1718

1819
ColorBasedColorUnion: TypeAlias = Union[int, Tuple[int, int, int]]

circuitpython_typing/pil.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
* Author(s): Alec Delaney
1212
"""
1313

14-
from typing import Tuple, Optional, Callable
15-
from typing_extensions import Protocol # Safety import for Python 3.7
14+
from typing import Callable, Optional, Tuple
15+
16+
# Protocol was introduced in Python 3.8
17+
from typing_extensions import Protocol
1618

1719

1820
class PixelAccess(Protocol):

circuitpython_typing/socket.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# Protocol was introduced in Python 3.8, TypeAlias in 3.10
1717
from typing_extensions import Protocol, TypeAlias
1818

19-
2019
# Based on https://github.com/python/typeshed/blob/master/stdlib/_socket.pyi
2120

2221
__all__ = [
@@ -126,4 +125,18 @@ def TLS_MODE(self) -> int: # pylint: disable=invalid-name
126125
"""Constant representing that a socket's connection mode is TLS."""
127126

128127

129-
SSLContextType: TypeAlias = Union[SSLContext, "_FakeSSLContext"]
128+
# pylint: disable=too-few-public-methods
129+
class _FakeSSLSocket:
130+
"""Describes the structure every fake SSL socket type must have."""
131+
132+
133+
class _FakeSSLContext:
134+
"""Describes the structure every fake SSL context type must have."""
135+
136+
def wrap_socket(
137+
self, socket: CircuitPythonSocketType, server_hostname: Optional[str] = None
138+
) -> _FakeSSLSocket:
139+
"""Wrap socket and return a new one that uses the methods from the original."""
140+
141+
142+
SSLContextType: TypeAlias = Union[SSLContext, _FakeSSLContext]

0 commit comments

Comments
 (0)