api: Use leading _ to hide internals in intellisense

Intellisense in VS Code (both jedi and ms python language server) picks
up all imported names and suggests them with equal priority for
code completion. By adding a leading underscore, intellisense lists
these with a lower priority, so they don't get in the way.

Also rename from builtins to _common while we are touching this to
better reflect the intention of the module (it contains types shared
by multiple modules, not builtin types like int).
This commit is contained in:
David Lechner
2020-03-25 20:24:32 +01:00
committed by laurensvalk
parent 43c006d836
commit 87c2b6857f
12 changed files with 53 additions and 51 deletions
+3 -3
View File
@@ -67,14 +67,14 @@ DC Motor
This class can be used to control classic LEGO motors using converter cables.
.. autoclass:: pybricks.builtins.DCMotor
.. autoclass:: pybricks._common.DCMotor
:noindex:
:no-members:
.. automethod:: pybricks.builtins.DCMotor.dc
.. automethod:: pybricks._common.DCMotor.dc
:noindex:
.. automethod:: pybricks.builtins.DCMotor.stop
.. automethod:: pybricks._common.DCMotor.stop
:noindex:
Ev3dev sensors
+7 -7
View File
@@ -117,21 +117,21 @@ you can set the settings at the beginning of your program. Alternatively, first
call ``stop()`` to make your ``Motor`` or ``DriveBase`` stop, and then change
the settings.
.. autoclass:: pybricks.builtins.Control
.. autoclass:: pybricks._common.Control
:no-members:
.. rubric:: Status
.. automethod:: pybricks.builtins.Control.done
.. automethod:: pybricks._common.Control.done
.. automethod:: pybricks.builtins.Control.stalled
.. automethod:: pybricks._common.Control.stalled
.. rubric:: Settings
.. automethod:: pybricks.builtins.Control.limits
.. automethod:: pybricks._common.Control.limits
.. automethod:: pybricks.builtins.Control.pid
.. automethod:: pybricks._common.Control.pid
.. automethod:: pybricks.builtins.Control.target_tolerances
.. automethod:: pybricks._common.Control.target_tolerances
.. automethod:: pybricks.builtins.Control.stall_tolerances
.. automethod:: pybricks._common.Control.stall_tolerances
+4 -4
View File
@@ -7,17 +7,17 @@
Motors without Rotation Sensors
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pybricks.builtins.DCMotor
.. autoclass:: pybricks._common.DCMotor
:noindex:
:no-members:
.. automethod:: pybricks.builtins.DCMotor.dc
.. automethod:: pybricks._common.DCMotor.dc
:noindex:
.. automethod:: pybricks.builtins.DCMotor.stop
.. automethod:: pybricks._common.DCMotor.stop
:noindex:
.. automethod:: pybricks.builtins.DCMotor.brake
.. automethod:: pybricks._common.DCMotor.brake
:noindex:
Motors with Rotation Sensors
+1 -1
View File
@@ -34,7 +34,7 @@ sys.path.insert(0, TOP_DIR)
from pybricks.hubs import EV3Brick # noqa E402
from pybricks.media.ev3dev import Image # noqa E402
from pybricks.builtins import Speaker # noqa E402
from pybricks._common import Speaker # noqa E402
# ON_RTD is whether we are on readthedocs.org
# this line of code grabbed from docs.readthedocs.org
+3 -3
View File
@@ -3,8 +3,8 @@
"""LEGO® MINDSTORMS® EV3 motors and sensors."""
from .parameters import Direction
from .builtins import Motor # noqa E402
from .parameters import Direction as _Direction
from ._common import Motor # noqa E402
class TouchSensor:
@@ -153,7 +153,7 @@ class InfraredSensor:
class GyroSensor:
"""LEGO® MINDSTORMS® EV3 Gyro Sensor."""
def __init__(self, port, positive_direction=Direction.CLOCKWISE):
def __init__(self, port, positive_direction=_Direction.CLOCKWISE):
"""
Arguments:
+12 -11
View File
@@ -2,26 +2,27 @@
# Copyright (c) 2018-2020 The Pybricks Authors
"""LEGO® Programmable Hubs."""
from .builtins import Speaker, Battery, ColorLight, KeyPad
from .media.ev3dev import Image
from ._common import (Speaker as _Speaker, Battery as _Battery,
ColorLight as _ColorLight, KeyPad as _KeyPad)
from .media.ev3dev import Image as _Image
class EV3Brick:
"""LEGO® MINDSTORMS® EV3 Brick."""
screen = Image('_screen_')
speaker = Speaker()
battery = Battery()
light = ColorLight()
buttons = KeyPad()
screen = _Image('_screen_')
speaker = _Speaker()
battery = _Battery()
light = _ColorLight()
buttons = _KeyPad()
class MoveHub:
"""LEGO® Powered Up Move Hub."""
battery = Battery()
light = ColorLight()
battery = _Battery()
light = _ColorLight()
class CityHub:
"""LEGO® Powered Up City Hub."""
battery = Battery()
light = ColorLight()
battery = _Battery()
light = _ColorLight()
+6 -6
View File
@@ -3,7 +3,7 @@
"""Images and Sounds for Pybricks on ev3dev."""
from ..parameters import Color
from ..parameters import Color as _Color
class Image:
@@ -57,7 +57,7 @@ class Image:
"""
pass
def draw_pixel(self, x, y, color=Color.BLACK):
def draw_pixel(self, x, y, color=_Color.BLACK):
"""Draws a single pixel on |this image|.
Arguments:
@@ -67,7 +67,7 @@ class Image:
"""
pass
def draw_line(self, x1, y1, x2, y2, width=1, color=Color.BLACK):
def draw_line(self, x1, y1, x2, y2, width=1, color=_Color.BLACK):
"""Draws a line on |this image|.
Arguments:
@@ -80,7 +80,7 @@ class Image:
"""
pass
def draw_box(self, x1, y1, x2, y2, r=0, fill=False, color=Color.BLACK):
def draw_box(self, x1, y1, x2, y2, r=0, fill=False, color=_Color.BLACK):
"""Draws a box on |this image|.
Arguments:
@@ -95,7 +95,7 @@ class Image:
"""
pass
def draw_circle(self, x, y, r=0, fill=False, color=Color.BLACK):
def draw_circle(self, x, y, r=0, fill=False, color=_Color.BLACK):
"""Draws a circle on |this image|.
Arguments:
@@ -134,7 +134,7 @@ class Image:
the ``source`` image is loaded from file.
"""
def draw_text(self, x, y, text, text_color=Color.BLACK, background_color=None):
def draw_text(self, x, y, text, text_color=_Color.BLACK, background_color=None):
"""Draws text on |this image|.
The most recent font set using :meth:`set_font` will be used or
+4 -4
View File
@@ -4,8 +4,8 @@
"""Use LEGO® MINDSTORMS® NXT motors and sensors with the EV3 brick."""
from pybricks.iodevices import AnalogSensor
from pybricks.builtins import ColorLight
from .iodevices import AnalogSensor as _AnalogSensor
from ._common import ColorLight as _ColorLight
class TouchSensor:
@@ -65,7 +65,7 @@ class LightSensor:
class ColorSensor:
"""LEGO® MINDSTORMS® NXT Color Sensor."""
light = ColorLight()
light = _ColorLight()
def __init__(self, port):
"""
@@ -242,7 +242,7 @@ class EnergyMeter:
pass
class VernierAdapter(AnalogSensor):
class VernierAdapter(_AnalogSensor):
"""LEGO® MINDSTORMS® Education NXT/EV3 Adapter for Vernier Sensors."""
def __init__(self, port, conversion=None):
+3 -3
View File
@@ -3,10 +3,10 @@
"""Constant parameters/arguments for the Pybricks API."""
from enum import Enum
from enum import Enum as _Enum
class _PybricksEnumMeta(type(Enum)):
class _PybricksEnumMeta(type(_Enum)):
def __dir__(cls):
yield '__class__'
yield '__name__'
@@ -14,7 +14,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):
+7 -6
View File
@@ -3,10 +3,11 @@
"""LEGO® Powered Up motor, sensors, and lights."""
from .builtins import KeyPad, Accelerometer, ColorLight, Motor
from ._common import (KeyPad as _KeyPad, Accelerometer as _Accelerometer,
ColorLight as _ColorLight, Motor as _Motor)
class Motor(Motor):
class Motor(_Motor):
"""Generic class to control motors with built-in rotation sensors."""
def reset_angle(self, angle=None):
@@ -24,8 +25,8 @@ class Motor(Motor):
class RemoteControl:
"""LEGO® Powered Up Bluetooth Remote Control/Handset."""
light = ColorLight()
buttons = KeyPad()
light = _ColorLight()
buttons = _KeyPad()
def __init__(self, device=None, timeout=10000):
"""Connect the handset to the hub.
@@ -41,7 +42,7 @@ class RemoteControl:
pass
class TiltSensor(Accelerometer):
class TiltSensor(_Accelerometer):
"""LEGO® Powered Up Tilt Sensor."""
def __init__(self, port):
@@ -56,7 +57,7 @@ class TiltSensor(Accelerometer):
class ColorDistanceSensor:
"""LEGO® Powered Up Color and Distance Sensor."""
light = ColorLight()
light = _ColorLight()
def __init__(self, port):
"""ColorDistanceSensor(port)
+3 -3
View File
@@ -3,19 +3,19 @@
"""Robotics module for the Pybricks API."""
from .builtins import Control
from ._common import Control as _Control
class DriveBase:
"""A robotic vehicle with two powered wheels and an optional support
wheel or caster."""
distance_control = Control()
distance_control = _Control()
"""The traveled distance and drive speed are controlled by a PID
controller. You can use this attribute to change its settings.
See :ref:`control` for an overview of available methods."""
heading_control = Control()
heading_control = _Control()
"""The robot turn angle and turn rate are controlled by a PID
controller. You can use this attribute to change its settings.
See :ref:`control` for an overview of available methods."""