From 8948bb1adc11e1c1810735ffec9db49ff81fb8ec Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Fri, 20 May 2022 21:42:00 -0400 Subject: [PATCH 1/2] Add io.py --- circuitpython_typing/io.py | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 circuitpython_typing/io.py diff --git a/circuitpython_typing/io.py b/circuitpython_typing/io.py new file mode 100644 index 0000000..49c8567 --- /dev/null +++ b/circuitpython_typing/io.py @@ -0,0 +1,44 @@ +# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney +# +# SPDX-License-Identifier: MIT + +""" +`circuitpython_typing.io` +================================================================================ + +Type annotation definitions for IO-related objects + +* Author(s): Alec Delaney +""" + +# Protocol was introduced in Python 3.8. +try: + from typing import Protocol +except ImportError: + from typing_extensions import Protocol + +class ROValueIO(Protocol): + """Hardware objects, like `analogio.AnalogIn`, that have read-only + ``value`` properties/attributes. + """ + + @property + def value(self) -> float: + """Value property, that may return an `int` or `float` depending + on the specifics of the class. + """ + +class ValueIO(Protocol): + """Hardware objects, like `analogio.AnalogOut`, that have read and + write ``value`` properties/attributes. + """ + + @property + def value(self) -> float: + """Value property, that may return an `int` or `float` depending + on the specifics of the class. + """ + + @value.setter + def value(self, input_value: float, /): + ... From a11a06a9b043d6828ad672e75d292861af4415df Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Fri, 20 May 2022 21:50:01 -0400 Subject: [PATCH 2/2] Reformatted per pre-commit --- circuitpython_typing/io.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/circuitpython_typing/io.py b/circuitpython_typing/io.py index 49c8567..05b6e62 100644 --- a/circuitpython_typing/io.py +++ b/circuitpython_typing/io.py @@ -17,6 +17,7 @@ except ImportError: from typing_extensions import Protocol + class ROValueIO(Protocol): """Hardware objects, like `analogio.AnalogIn`, that have read-only ``value`` properties/attributes. @@ -28,6 +29,7 @@ def value(self) -> float: on the specifics of the class. """ + class ValueIO(Protocol): """Hardware objects, like `analogio.AnalogOut`, that have read and write ``value`` properties/attributes.