Skip to content

Commit

Permalink
pybricks: Drop underscores on imports.
Browse files Browse the repository at this point in the history
Fixes #101
  • Loading branch information
laurensvalk committed Jun 10, 2022
1 parent 6500440 commit 1151947
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 52 deletions.
6 changes: 3 additions & 3 deletions doc/main/iodevices/dcmotor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
13 changes: 6 additions & 7 deletions src/pybricks/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -63,12 +62,12 @@ def name(self) -> str:
"""


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.
Expand Down Expand Up @@ -290,7 +289,7 @@ def load(self) -> int:
"""


class Motor(DCMotor):
class CommonMotor(CommonDCMotor):
"""Generic class to control motors with built-in rotation sensors."""

control = Control()
Expand All @@ -306,7 +305,7 @@ def __init__(
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.
Expand Down
10 changes: 5 additions & 5 deletions src/pybricks/ev3devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions src/pybricks/iodevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from typing import Dict, Tuple, Optional, overload

from ._common import CommonDCMotor
from .parameters import Port


Expand Down Expand Up @@ -74,6 +75,10 @@ def read(self, mode: int) -> Tuple:
"""


class DCMotor(CommonDCMotor):
"""DC Motor for LEGO® MINDSTORMS EV3."""


class Ev3devSensor:
"""Read values of an ev3dev-compatible sensor."""

Expand Down
4 changes: 2 additions & 2 deletions src/pybricks/media/ev3dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pybricks/nxtdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/pybricks/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@

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__"
for member in cls:
yield member.name


class _PybricksEnum(_Enum, metaclass=_PybricksEnumMeta):
class _PybricksEnum(Enum, metaclass=_PybricksEnumMeta):
def __dir__(self):
yield "__class__"
for member in type(self):
Expand Down
47 changes: 23 additions & 24 deletions src/pybricks/pupdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -41,16 +40,16 @@ def reset_angle(self, angle: Optional[int]) -> None:
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]
Expand Down Expand Up @@ -113,7 +112,7 @@ def tilt(self) -> Tuple[int, int]:
class ColorDistanceSensor(CommonColorSensor):
"""LEGO® Powered Up Color and Distance Sensor."""

light = _ColorLight()
light = ColorLight()

def distance(self) -> int:
"""distance() -> int: %
Expand Down Expand Up @@ -156,13 +155,13 @@ def __init__(
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)
Expand Down
13 changes: 6 additions & 7 deletions src/pybricks/robotics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -143,7 +142,7 @@ def settings(self, *args):
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.
Expand All @@ -155,7 +154,7 @@ def straight(self, distance, then=_Stop.HOLD, wait=True) -> None:
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.
Expand All @@ -167,7 +166,7 @@ def turn(self, angle, then=_Stop.HOLD, wait=True) -> None:
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.
Expand Down

0 comments on commit 1151947

Please sign in to comment.