diff --git a/circuitpython_typing/io.py b/circuitpython_typing/io.py new file mode 100644 index 0000000..05b6e62 --- /dev/null +++ b/circuitpython_typing/io.py @@ -0,0 +1,46 @@ +# 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, /): + ...