Skip to content
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

Fix namedtuple type annotations #32

Merged
merged 1 commit into from
Dec 1, 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
16 changes: 8 additions & 8 deletions adafruit_nunchuk.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from adafruit_bus_device.i2c_device import I2CDevice

try:
from typing import Type
import typing # pylint: disable=unused-import
from busio import I2C
except ImportError:
pass
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(
i2c_dev.write(b"\xFB\x00")

@property
def values(self) -> Type[tuple]:
def values(self) -> _Values:
"""The current state of all values."""
self._read_data()
return self._Values(
Expand All @@ -82,33 +82,33 @@ def values(self) -> Type[tuple]:
)

@property
def joystick(self) -> Type[tuple]:
def joystick(self) -> _Joystick:
"""The current joystick position."""
return self._joystick()

@property
def buttons(self) -> Type[tuple]: # pylint: disable=invalid-name
def buttons(self) -> _Buttons: # pylint: disable=invalid-name
"""The current pressed state of buttons C and Z."""
return self._buttons()

@property
def acceleration(self) -> Type[tuple]:
def acceleration(self) -> _Acceleration:
"""The current accelerometer reading."""
return self._acceleration()

def _joystick(self, do_read: bool = True) -> Type[tuple]:
def _joystick(self, do_read: bool = True) -> _Joystick:
if do_read:
self._read_data()
return self._Joystick(self.buffer[0], self.buffer[1]) # x, y

def _buttons(self, do_read: bool = True) -> Type[tuple]:
def _buttons(self, do_read: bool = True) -> _Buttons:
if do_read:
self._read_data()
return self._Buttons(
not bool(self.buffer[5] & 0x02), not bool(self.buffer[5] & 0x01) # C # Z
)

def _acceleration(self, do_read: bool = True) -> Type[tuple]:
def _acceleration(self, do_read: bool = True) -> _Acceleration:
if do_read:
self._read_data()
return self._Acceleration(
Expand Down