Skip to content

Add hardware value-property protocols #18

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 2 commits into from
May 21, 2022
Merged
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
46 changes: 46 additions & 0 deletions circuitpython_typing/io.py
Original file line number Diff line number Diff line change
@@ -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, /):
...