Skip to content

Commit 6dd0de0

Browse files
committed
allow use in Python 3.7
1 parent 85e90eb commit 6dd0de0

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

circuitpython_typing/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
__version__ = "0.0.0-auto.0"
1515
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Typing.git"
1616

17-
from typing import Union, Protocol, Optional
17+
18+
from typing import Union, Optional
19+
20+
# Protocol was introduced in Python 3.8.
21+
try:
22+
from typing import Protocol
23+
except ImportError:
24+
from typing_extensions import Protocol
25+
1826
from array import array
1927

2028
ReadableBuffer = Union[bytes, bytearray, memoryview, array]
@@ -42,14 +50,16 @@ class ByteStream(Protocol):
4250
* `usb_cdc.Serial`
4351
"""
4452

45-
def read(self, count: Optional[int] = None, /) -> Optional[bytes]:
53+
# Should be `, /)`, but not available in Python 3.7.
54+
def read(self, count: Optional[int] = None) -> Optional[bytes]:
4655
"""Read ``count`` bytes from the stream.
4756
If ``count`` bytes are not immediately available,
4857
or if the parameter is not specified in the call,
4958
the outcome is implementation-dependent.
5059
"""
5160
...
5261

53-
def write(self, buf: ReadableBuffer, /) -> Optional[int]:
62+
# Should be `, /)`, but not available in Python 3.7.
63+
def write(self, buf: ReadableBuffer) -> Optional[int]:
5464
"""Write the bytes in ``buf`` to the stream."""
5565
...

circuitpython_typing/socket.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111

1212
from ssl import SSLContext
1313
from types import ModuleType
14-
from typing import Any, Optional, Protocol, Tuple, Union
14+
from typing import Any, Optional, Tuple, Union
15+
16+
# Protocol was introduced in Python 3.8.
17+
try:
18+
from typing import Protocol
19+
except ImportError:
20+
from typing_extensions import Protocol
21+
1522

1623
# Based on https://github.com/python/typeshed/blob/master/stdlib/_socket.pyi
1724

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
33
#
44
# SPDX-License-Identifier: MIT
5+
6+
typing_extensions; python_version <= '3.7'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# Author details
4040
author="Adafruit Industries",
4141
author_email="[email protected]",
42-
install_requires=[],
42+
install_requires=["typing_extensions; python_version <= '3.7'"],
4343
# Choose your license
4444
license="MIT",
4545
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)