Skip to content

Commit f6e60bd

Browse files
authored
Merge pull request #18 from tekktrik/dev/boolean-value-protocol
Add hardware value-property protocols
2 parents 6534d44 + a11a06a commit f6e60bd

File tree

1 file changed

+46
-0
lines changed
  • circuitpython_typing

1 file changed

+46
-0
lines changed

circuitpython_typing/io.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`circuitpython_typing.io`
7+
================================================================================
8+
9+
Type annotation definitions for IO-related objects
10+
11+
* Author(s): Alec Delaney
12+
"""
13+
14+
# Protocol was introduced in Python 3.8.
15+
try:
16+
from typing import Protocol
17+
except ImportError:
18+
from typing_extensions import Protocol
19+
20+
21+
class ROValueIO(Protocol):
22+
"""Hardware objects, like `analogio.AnalogIn`, that have read-only
23+
``value`` properties/attributes.
24+
"""
25+
26+
@property
27+
def value(self) -> float:
28+
"""Value property, that may return an `int` or `float` depending
29+
on the specifics of the class.
30+
"""
31+
32+
33+
class ValueIO(Protocol):
34+
"""Hardware objects, like `analogio.AnalogOut`, that have read and
35+
write ``value`` properties/attributes.
36+
"""
37+
38+
@property
39+
def value(self) -> float:
40+
"""Value property, that may return an `int` or `float` depending
41+
on the specifics of the class.
42+
"""
43+
44+
@value.setter
45+
def value(self, input_value: float, /):
46+
...

0 commit comments

Comments
 (0)