diff --git a/CHANGELOG.md b/CHANGELOG.md index 3731d15..5d56350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## Unreleased +### Changed +- Moved remaining type hints from `.pyi` files to the python stub modules, and + fixed numerous errors in the type hints throughout. + ## 3.2.0b1-r1 - 2022-06-09 ## Added diff --git a/doc/main/iodevices/dcmotor.rst b/doc/main/iodevices/dcmotor.rst index c776dae..18b1f16 100644 --- a/doc/main/iodevices/dcmotor.rst +++ b/doc/main/iodevices/dcmotor.rst @@ -9,12 +9,12 @@ EV3 DC Motor .. figure:: ../../main/images/rcxmotor.png :width: 40 % -.. autoclass:: pybricks._common.DCMotor +.. autoclass:: pybricks.iodevices.DCMotor :noindex: :no-members: - .. automethod:: pybricks._common.DCMotor.dc + .. automethod:: pybricks.iodevices.DCMotor.dc :noindex: - .. automethod:: pybricks._common.DCMotor.stop + .. automethod:: pybricks.iodevices.DCMotor.stop :noindex: diff --git a/src/pybricks/_common.py b/src/pybricks/_common.py index 47d2b42..b008d35 100644 --- a/src/pybricks/_common.py +++ b/src/pybricks/_common.py @@ -4,11 +4,10 @@ """Generic cross-platform module for typical devices like lights, displays, speakers, and batteries.""" -from .parameters import Direction, Stop, Button, Port, Color, Side, Number +from typing import Union, Iterable, overload, Optional, Tuple, Collection from .geometry import Matrix, Axis - -from typing import Union, Iterable, overload, Optional, Tuple, Collection +from .parameters import Direction, Stop, Button, Port, Color, Side, Number class System: @@ -63,12 +62,12 @@ class System: """ -class DCMotor: +class CommonDCMotor: """Generic class to control simple motors without rotation sensors, such as train motors.""" def __init__(self, port: Port, positive_direction: Direction = Direction.CLOCKWISE): - """DCMotor(port, positive_direction=Direction.CLOCKWISE) + """__init__(port, positive_direction=Direction.CLOCKWISE) Arguments: port (Port): Port to which the motor is connected. @@ -290,7 +289,7 @@ class Control: """ -class Motor(DCMotor): +class CommonMotor(CommonDCMotor): """Generic class to control motors with built-in rotation sensors.""" control = Control() @@ -306,7 +305,7 @@ class Motor(DCMotor): gears: Optional[Union[Collection[int], Collection[Collection[int]]]] = None, reset_angle: bool = True, ): - """Motor(port, positive_direction=Direction.CLOCKWISE, gears=None, reset_angle=True) + """__init__(port, positive_direction=Direction.CLOCKWISE, gears=None, reset_angle=True) Arguments: port (Port): Port to which the motor is connected. diff --git a/src/pybricks/ev3devices.py b/src/pybricks/ev3devices.py index 323ce50..4559402 100644 --- a/src/pybricks/ev3devices.py +++ b/src/pybricks/ev3devices.py @@ -3,14 +3,14 @@ """LEGO® MINDSTORMS® EV3 motors and sensors.""" -from .parameters import Direction, Port, Color, Button -from ._common import Motor as _Motor - from typing import Optional, Tuple, List +from ._common import CommonMotor +from .parameters import Direction, Port, Color, Button -class Motor(_Motor): - pass + +class Motor(CommonMotor): + """LEGO® MINDSTORMS® EV3 Motor.""" class TouchSensor: diff --git a/src/pybricks/iodevices.py b/src/pybricks/iodevices.py index b94591d..cb8a093 100644 --- a/src/pybricks/iodevices.py +++ b/src/pybricks/iodevices.py @@ -5,6 +5,7 @@ from typing import Dict, Tuple, Optional, overload +from ._common import CommonDCMotor from .parameters import Port @@ -74,6 +75,10 @@ class LUMPDevice: """ +class DCMotor(CommonDCMotor): + """DC Motor for LEGO® MINDSTORMS EV3.""" + + class Ev3devSensor: """Read values of an ev3dev-compatible sensor.""" diff --git a/src/pybricks/media/ev3dev.py b/src/pybricks/media/ev3dev.py index 5a5f9d1..70f33fc 100644 --- a/src/pybricks/media/ev3dev.py +++ b/src/pybricks/media/ev3dev.py @@ -5,10 +5,10 @@ from __future__ import annotations -from ..parameters import Color - from typing import Union, Literal, overload, Optional, Any +from ..parameters import Color + class Image: """Object representing a graphics image. This can either be an in-memory diff --git a/src/pybricks/nxtdevices.py b/src/pybricks/nxtdevices.py index 835b8fc..a69d13a 100644 --- a/src/pybricks/nxtdevices.py +++ b/src/pybricks/nxtdevices.py @@ -6,8 +6,8 @@ from .parameters import Port -from .iodevices import AnalogSensor from ._common import ColorLight, CommonColorSensor +from .iodevices import AnalogSensor from typing import Callable, Optional, Tuple diff --git a/src/pybricks/parameters.py b/src/pybricks/parameters.py index 6972d0d..5067474 100644 --- a/src/pybricks/parameters.py +++ b/src/pybricks/parameters.py @@ -5,15 +5,16 @@ from __future__ import annotations +from enum import Enum from typing import Union -from enum import Enum as _Enum + from .geometry import Matrix Number = Union[int, float] -class _PybricksEnumMeta(type(_Enum)): +class _PybricksEnumMeta(type(Enum)): def __dir__(cls): yield "__class__" yield "__name__" @@ -21,7 +22,7 @@ class _PybricksEnumMeta(type(_Enum)): yield member.name -class _PybricksEnum(_Enum, metaclass=_PybricksEnumMeta): +class _PybricksEnum(Enum, metaclass=_PybricksEnumMeta): def __dir__(self): yield "__class__" for member in type(self): diff --git a/src/pybricks/pupdevices.py b/src/pybricks/pupdevices.py index 1486f03..299ef01 100644 --- a/src/pybricks/pupdevices.py +++ b/src/pybricks/pupdevices.py @@ -6,24 +6,23 @@ from typing import Collection, Optional, Union, overload, Tuple from ._common import ( - Keypad as _Keypad, - DCMotor as _DCMotor, - ColorLight as _ColorLight, - Motor as _Motor, - LightArray as _LightArray, - CommonColorSensor, AmbientColorSensor, + ColorLight, + CommonColorSensor, + CommonDCMotor, + CommonMotor, + Keypad, + LightArray, ) - -from .parameters import Button as _Button, Color, Direction, Port +from .parameters import Button, Color, Direction, Port -class DCMotor(_DCMotor): - pass +class DCMotor(CommonDCMotor): + """LEGO® Powered Up motor without rotation sensors.""" -class Motor(_Motor): - """Generic class to control motors with built-in rotation sensors.""" +class Motor(CommonMotor): + """LEGO® Powered Up motor with rotation sensors.""" def reset_angle(self, angle: Optional[int]) -> None: """reset_angle(angle=None) @@ -41,16 +40,16 @@ class Motor(_Motor): class Remote: """LEGO® Powered Up Bluetooth Remote Control.""" - light = _ColorLight() - buttons = _Keypad( + light = ColorLight() + buttons = Keypad( ( - _Button.LEFT_MINUS, - _Button.RIGHT_MINUS, - _Button.LEFT, - _Button.CENTER, - _Button.RIGHT, - _Button.LEFT_PLUS, - _Button.RIGHT_PLUS, + Button.LEFT_MINUS, + Button.RIGHT_MINUS, + Button.LEFT, + Button.CENTER, + Button.RIGHT, + Button.LEFT_PLUS, + Button.RIGHT_PLUS, ) ) addresss: Union[str, None] @@ -113,7 +112,7 @@ class TiltSensor: class ColorDistanceSensor(CommonColorSensor): """LEGO® Powered Up Color and Distance Sensor.""" - light = _ColorLight() + light = ColorLight() def distance(self) -> int: """distance() -> int: % @@ -156,13 +155,13 @@ class PFMotor(DCMotor): class ColorSensor(AmbientColorSensor): """LEGO® SPIKE Color Sensor.""" - lights = _LightArray(3) + lights = LightArray(3) class UltrasonicSensor: """LEGO® SPIKE Color Sensor.""" - lights = _LightArray(3) + lights = LightArray(3) def __init__(self, port: Port): """UltrasonicSensor(port) diff --git a/src/pybricks/robotics.py b/src/pybricks/robotics.py index c137824..b5accc2 100644 --- a/src/pybricks/robotics.py +++ b/src/pybricks/robotics.py @@ -3,12 +3,11 @@ """Robotics module for the Pybricks API.""" -from ._common import Control, Motor - -from .parameters import Stop as _Stop, Number - from typing import Tuple, Optional, overload +from ._common import Control, CommonMotor as Motor +from .parameters import Stop, Number + class DriveBase: """A robotic vehicle with two powered wheels and an optional support @@ -143,7 +142,7 @@ class DriveBase: deceleration of the robot. """ - def straight(self, distance, then=_Stop.HOLD, wait=True) -> None: + def straight(self, distance, then=Stop.HOLD, wait=True) -> None: """straight(distance, then=Stop.HOLD, wait=True) Drives straight for a given distance and then stops. @@ -155,7 +154,7 @@ class DriveBase: with the rest of the program. """ - def turn(self, angle, then=_Stop.HOLD, wait=True) -> None: + def turn(self, angle, then=Stop.HOLD, wait=True) -> None: """turn(angle, then=Stop.HOLD, wait=True) Turns in place by a given angle and then stops. @@ -167,7 +166,7 @@ class DriveBase: with the rest of the program. """ - def curve(self, radius, angle, then=_Stop.HOLD, wait=True) -> None: + def curve(self, radius, angle, then=Stop.HOLD, wait=True) -> None: """curve(radius, angle, then=Stop.HOLD, wait=True) Drives an arc along a circle of a given radius, by a given angle.