Skip to content

allow use in Python 3.7 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions circuitpython_typing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Typing.git"

from typing import Union, Protocol, Optional

from typing import Union, Optional

# Protocol was introduced in Python 3.8.
try:
from typing import Protocol
except ImportError:
from typing_extensions import Protocol

from array import array

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

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

def write(self, buf: ReadableBuffer, /) -> Optional[int]:
# Should be `, /)`, but not available in Python 3.7.
def write(self, buf: ReadableBuffer) -> Optional[int]:
"""Write the bytes in ``buf`` to the stream."""
...
9 changes: 8 additions & 1 deletion circuitpython_typing/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@

from ssl import SSLContext
from types import ModuleType
from typing import Any, Optional, Protocol, Tuple, Union
from typing import Any, Optional, Tuple, Union

# Protocol was introduced in Python 3.8.
try:
from typing import Protocol
except ImportError:
from typing_extensions import Protocol


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

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
#
# SPDX-License-Identifier: MIT

typing_extensions; python_version <= '3.7'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# Author details
author="Adafruit Industries",
author_email="[email protected]",
install_requires=[],
install_requires=["typing_extensions; python_version <= '3.7'"],
# Choose your license
license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down