Skip to content

Add Missing Type Annotations #17

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 3 commits into from
Sep 3, 2022
Merged
Changes from 2 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
12 changes: 9 additions & 3 deletions adafruit_us100.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@

import time

try:
from typing import Optional
from busio import UART
except ImportError:
pass


class US100:
"""Control a US-100 ultrasonic range sensor."""

def __init__(self, uart):
def __init__(self, uart: UART) -> None:
self._uart = uart

@property
def distance(self):
def distance(self) -> Optional[float]:
"""Return the distance measured by the sensor in cm.
This is the function that will be called most often in user code.
If no signal is received, return ``None``. This can happen when the
Expand Down Expand Up @@ -67,7 +73,7 @@ def distance(self):
return dist

@property
def temperature(self):
def temperature(self) -> Optional[int]:
"""Return the on-chip temperature, in Celsius"""
for _ in range(2): # Attempt to read twice.
self._uart.write(bytes([0x50]))
Expand Down