Skip to content

Commit

Permalink
pybricks.ev3/pupdevices: fix Motor code completion
Browse files Browse the repository at this point in the history
The Microsoft Python extension for VS code doesn't include imports in
type hints, so the Motor type wasn't working properly. We can fix this
by wrapping the import type in a new, empty class definition.

The DCMotor class was also missing from ev3devices and the typing for
the overloaded reset_angle method in pupdevices was missing. These are
fixed as well.
  • Loading branch information
dlech committed Feb 21, 2022
1 parent 6160511 commit 2ba7eda
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## Unreleased

### Fixed
- Fixed code completion for `DCMotor` and `Motor` classes in MS Python VS Code extension.
- Fixed missing `DCMotor` type in `ev3devices`.
- Fixed type hint for `Motor.reset_angle()` in `pupdevices`.

## 3.1.0 - 2021-12-16

### Added
Expand Down
12 changes: 10 additions & 2 deletions src/pybricks/ev3devices.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2020 The Pybricks Authors
# Copyright (c) 2018-2022 The Pybricks Authors

"""LEGO® MINDSTORMS® EV3 motors and sensors."""

from .parameters import Direction as _Direction
from ._common import Motor # noqa E402
from ._common import DCMotor as _DCMotor, Motor as _Motor


class DCMotor(_DCMotor):
pass


class Motor(_Motor):
pass


class TouchSensor:
Expand Down
7 changes: 5 additions & 2 deletions src/pybricks/ev3devices.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2020 The Pybricks Authors
# Copyright (c) 2020-2022 The Pybricks Authors

from typing import List, Optional, Tuple

from .parameters import Color, Direction, Port, Button
from ._common import Motor # noqa E402
from ._common import DCMotor as _DCMotor, Motor as _Motor

class DCMotor(_DCMotor): ...
class Motor(_Motor): ...

class TouchSensor:
def __init__(self, port: Port): ...
Expand Down
8 changes: 6 additions & 2 deletions src/pybricks/pupdevices.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2018-2020 The Pybricks Authors
# Copyright (c) 2018-2022 The Pybricks Authors

"""LEGO® Powered Up motor, sensors, and lights."""

from ._common import (Keypad as _Keypad, DCMotor,
from ._common import (Keypad as _Keypad, DCMotor as _DCMotor,
ColorLight as _ColorLight, Motor as _Motor,
LightArray as _LightArray, Light as _Light)

from .parameters import Direction as _Direction, Button as _Button


class DCMotor(_DCMotor):
pass


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

Expand Down
18 changes: 14 additions & 4 deletions src/pybricks/pupdevices.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2020 The Pybricks Authors
# Copyright (c) 2020-2022 The Pybricks Authors

from typing import Collection, List, Optional, Tuple, Union

from ._common import Keypad, DCMotor, ColorLight, LightArray, Motor as BaseMotor, Light as BaseLight
from ._common import (
Keypad,
DCMotor as _DCMotor,
ColorLight,
LightArray,
Motor as _Motor,
Light as BaseLight,
)

from .parameters import Color, Direction, Port

class Motor(BaseMotor): ...
class DCMotor(_DCMotor): ...

class Motor(_Motor):
def reset_angle(self, angle: Optional[int]) -> None: ...

class Remote:
light: ColorLight
Expand Down Expand Up @@ -63,7 +73,7 @@ class ForceSensor:
class ColorLightMatrix:
def __init__(self, port: Port) -> None: ...
def on(self, color: Union[Color, List[Color]]) -> None: ...
def off(self)-> None: ...
def off(self) -> None: ...

class InfraredSensor:
def __init__(self, port: Port): ...
Expand Down

0 comments on commit 2ba7eda

Please sign in to comment.