diff --git a/doc/common/extensions/awaitable.py b/doc/common/extensions/awaitable.py index d668242..0d2b4a8 100644 --- a/doc/common/extensions/awaitable.py +++ b/doc/common/extensions/awaitable.py @@ -26,7 +26,7 @@ def _is_async(self: _FunctionDefProperties) -> bool: try: return_type = self._obj.__annotations__["return"] - except Exception: + except (AttributeError, KeyError): return False return "MaybeAwaitable" in str(return_type) diff --git a/doc/common/extensions/requirements.py b/doc/common/extensions/requirements.py index f3691f6..21bbe63 100644 --- a/doc/common/extensions/requirements.py +++ b/doc/common/extensions/requirements.py @@ -22,6 +22,7 @@ import os +from typing import ClassVar from docutils import nodes from docutils.parsers.rst import Directive, directives @@ -35,7 +36,7 @@ JS_FILE = "requirements.js" class PybricksRequirementsDirective(Directive): has_content = True - option_spec = {"header": directives.unchanged} + option_spec: ClassVar = {"header": directives.unchanged} required_arguments = 0 optional_arguments = 10 diff --git a/doc/main/conf.py b/doc/main/conf.py index 74abf9b..026312f 100644 --- a/doc/main/conf.py +++ b/doc/main/conf.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # # Pybricks documentation build configuration file # @@ -36,7 +35,9 @@ if tags.has("ide"): # noqa F821 html_css_files.append("css/ide.css") html_js_files = ["js/ide.js"] -exec(open(os.path.abspath("../common/conf.py")).read()) +# Shared config must run in this namespace so it sees the globals above. +with open(os.path.abspath("../common/conf.py")) as _f: + exec(_f.read()) # noqa: S102 # Build hub specific example scripts. sys.path.append(os.path.abspath("../../examples/pup/hub_common")) diff --git a/examples/ev3/bluetooth_pc/pcclient.py b/examples/ev3/bluetooth_pc/pcclient.py index f101f6c..fd71f3e 100644 --- a/examples/ev3/bluetooth_pc/pcclient.py +++ b/examples/ev3/bluetooth_pc/pcclient.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 from pybricks.messaging import BluetoothMailboxClient, TextMailbox # This demo makes your PC talk to an EV3 over Bluetooth. diff --git a/examples/ev3/bluetooth_pc/pcserver.py b/examples/ev3/bluetooth_pc/pcserver.py index 9d76247..a018222 100644 --- a/examples/ev3/bluetooth_pc/pcserver.py +++ b/examples/ev3/bluetooth_pc/pcserver.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 from pybricks.messaging import BluetoothMailboxServer, TextMailbox # This demo makes your PC talk to an EV3 over Bluetooth. diff --git a/examples/ev3/ps4/.gitignore b/examples/ev3/ps4/.gitignore deleted file mode 100644 index 00f2d38..0000000 --- a/examples/ev3/ps4/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -__pycache__/ -*.pyc -.venv/ diff --git a/examples/ev3/ps4/.vscode/extensions.json b/examples/ev3/ps4/.vscode/extensions.json deleted file mode 100644 index f8f1a44..0000000 --- a/examples/ev3/ps4/.vscode/extensions.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. - // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp - - // List of extensions which should be recommended for users of this workspace. - "recommendations": [ - "lego-education.ev3-micropython" - ], - // List of extensions recommended by VS Code that should not be recommended for users of this workspace. - "unwantedRecommendations": [ - "ms-python.python" - ] -} \ No newline at end of file diff --git a/examples/ev3/ps4/.vscode/launch.json b/examples/ev3/ps4/.vscode/launch.json deleted file mode 100644 index d933aeb..0000000 --- a/examples/ev3/ps4/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Download and Run", - "type": "ev3devBrowser", - "request": "launch", - "program": "/home/robot/${workspaceRootFolderName}/main.py", - "interactiveTerminal": false - } - ] -} diff --git a/examples/ev3/ps4/.vscode/settings.json b/examples/ev3/ps4/.vscode/settings.json deleted file mode 100644 index b0968c1..0000000 --- a/examples/ev3/ps4/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -// Place your settings in this file to overwrite default and user settings. -{ - "files.eol": "\n", - "debug.openDebug": "neverOpen", - "python.linting.enabled": false, - "python.languageServer": "None" -} diff --git a/examples/ev3/ps4/main.py b/examples/ev3/ps4/main.py deleted file mode 100644 index 08290fc..0000000 --- a/examples/ev3/ps4/main.py +++ /dev/null @@ -1,142 +0,0 @@ -import struct - -from pybricks.ev3devices import Motor -from pybricks.parameters import Port - -# This program uses the two PS4 sticks to control two EV3 Large Servo Motors -# using tank like controls. For a full map of all PS4 buttons, trackpad, and -# motion checkout: https://github.com/codeadamca/python-connect-ps4 - -# Initialize EV3 motors -left_motor = Motor(Port.B) -right_motor = Motor(Port.C) -left_speed = 0 -right_speed = 0 - -# Locate the event file you want to react to, on my setup the PS4 controller -# button events are located in /dev/input/event4 -infile_path = "/dev/input/event4" -in_file = open(infile_path, "rb") - -# Define the format the event data will be read. -# https://docs.python.org/3/library/struct.html#format-characters -FORMAT = "llHHi" -EVENT_SIZE = struct.calcsize(FORMAT) -event = in_file.read(EVENT_SIZE) - - -# A helper function for converting stick values (0 to 255) to more usable -# numbers (-100 to 100) -def scale(val, src, dst): - - result = float(val - src[0]) / (src[1] - src[0]) - result = result * (dst[1] - dst[0]) + dst[0] - return result - - -# Create a loop to react to events -# This loop reacts to all main PS4 button and stick events. I have left out -# buttons like share and options, but can easily be added in by referring -# to the table at: https://github.com/codeadamca/python-connect-ps4 - - -while event: - # Place event data into variables - (tv_sec, tv_usec, ev_type, code, value) = struct.unpack(FORMAT, event) - - # If a button was pressed or released - if ev_type == 1: - # React to the X button - if code == 304 and value == 0: - print("The X button was released") - elif code == 304 and value == 1: - print("The X button was pressed") - - # React to the Circle button - elif code == 305 and value == 0: - print("The Circle button was released") - elif code == 305 and value == 1: - print("The Circle button was pressed") - - # React to the Triangle button - elif code == 307 and value == 0: - print("The Triangle button was released") - elif code == 307 and value == 1: - print("The Triangle button was pressed") - - # React to the Square button - elif code == 308 and value == 0: - print("The Square button was released") - elif code == 308 and value == 1: - print("The Square button was pressed") - - # React to the L1 button - elif code == 310 and value == 0: - print("The L1 button was released") - elif code == 310 and value == 1: - print("The L1 button was pressed") - - # React to the R1 button - elif code == 311 and value == 0: - print("The R1 button was released") - elif code == 311 and value == 1: - print("The R1 button was pressed") - - # React to the L2 button - elif code == 312 and value == 0: - print("The L2 button was released") - elif code == 312 and value == 1: - print("The L2 button was pressed") - - # React to the R2 button - elif code == 313 and value == 0: - print("The R2 button was released") - elif code == 313 and value == 1: - print("The R2 button was pressed") - - elif ev_type == 3: - # The sticks often trigger non-stop events, comment this out if you are - # not using the sticks as part of your project, or it becomes hard to - # read other data - - # React to the left stick vertical - if code == 1: - print("The left stick vertical is at ", value) - left_speed = scale(value, (0, 255), (100, -100)) - - # React to the left stick horizontal - elif code == 0: - print("The left stick horizontal is at ", value) - - # React to the right stick vertical - elif code == 4: - print("The right stick vertical is at ", value) - right_speed = scale(value, (0, 255), (100, -100)) - - # React to the right stick horizontal - elif code == 3: - print("The right stick horizontal is at ", value) - - # React to the Directional pad - if code == 16 and value == -1: - print("The horizontal directional pad is left") - elif code == 16 and value == 1: - print("The horizontal directional pad is right") - elif code == 16 and value == 0: - print("The horizontal directional pad is released") - - elif code == 17 and value == -1: - print("The vertical directional pad is up") - elif code == 17 and value == 1: - print("The horizontal directional pad is down") - elif code == 17 and value == 0: - print("The horizontal directional pad is released") - - # Set motor speed - left_motor.dc(left_speed) - right_motor.dc(right_speed) - - # Read the next event - event = in_file.read(EVENT_SIZE) - -in_file.close() diff --git a/src/ubuiltins/__init__.py b/src/ubuiltins/__init__.py index fcabd7f..1ee7f70 100644 --- a/src/ubuiltins/__init__.py +++ b/src/ubuiltins/__init__.py @@ -23,14 +23,10 @@ import builtins from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping, Sequence from typing import ( Any, - Dict, - List, Literal, SupportsComplex, SupportsFloat, SupportsInt, - TypeVar, - Union, overload, ) @@ -50,7 +46,9 @@ _complex = complex _dict = dict _float = float _int = int +_list = list _str = str +_tuple = tuple _type = type @@ -171,8 +169,8 @@ class bytes: def __init__(self, source: _str, encoding: _str) -> None: ... def __init__(self, *args): - r""" - bytes(​) + """ + bytes(\u200b) bytes(integer) bytes(iterable) bytes(string, encoding) @@ -207,8 +205,8 @@ class bytearray: def __init__(self, source: _bytes | _bytearray | _str | Iterable[_int]) -> None: ... def __init__(self, *args): - r""" - bytearray(​) + """ + bytearray(\u200b) bytearray(integer) bytearray(iterable) bytearray(string) @@ -328,17 +326,17 @@ class dict: @overload -def dir() -> list[_str]: ... +def dir() -> _list[_str]: ... @overload -def dir(object: Any) -> list[_str]: ... +def dir(object: Any) -> _list[_str]: ... -def dir(*args) -> list[_str]: +def dir(*args) -> _list[_str]: """ - dir() -> List[str] - dir(object) -> List[str] + dir() -> list[str] + dir(object) -> list[str] Gets a list of attributes of an object. @@ -354,11 +352,11 @@ def dir(*args) -> list[_str]: @overload -def divmod(a: _int, b: _int) -> tuple[_int, _int]: ... +def divmod(a: _int, b: _int) -> _tuple[_int, _int]: ... @overload -def divmod(a: _float, b: _float) -> tuple[_float, _float]: ... +def divmod(a: _float, b: _float) -> _tuple[_float, _float]: ... def divmod(a, b): @@ -689,7 +687,7 @@ class int: """ -def isinstance(object: Any, classinfo: _type | tuple[_type]) -> _bool: +def isinstance(object: Any, classinfo: _type | _tuple[_type]) -> _bool: """ isinstance(object, classinfo) -> bool @@ -705,7 +703,7 @@ def isinstance(object: Any, classinfo: _type | tuple[_type]) -> _bool: """ -def issubclass(cls: _type, classinfo: _type | tuple[_type]) -> _bool: +def issubclass(cls: _type, classinfo: _type | _tuple[_type]) -> _bool: """ issubclass(cls, classinfo) -> bool diff --git a/src/uerrno/__init__.py b/src/uerrno/__init__.py index e9d7172..b5defd7 100644 --- a/src/uerrno/__init__.py +++ b/src/uerrno/__init__.py @@ -9,8 +9,6 @@ This module provides access to symbolic error codes for `OSError` exception. """ -from typing import Dict - EAGAIN: int """ The operation is not complete and should be tried again soon. diff --git a/src/uio/__init__.py b/src/uio/__init__.py index 0460299..18f6d0c 100644 --- a/src/uio/__init__.py +++ b/src/uio/__init__.py @@ -11,7 +11,7 @@ This module contains ``stream`` objects that behave like files. # TODO: open() is not implemented on Powered Up hubs -from typing import Union, overload +from typing import overload # TODO: MicroPython streams implement '__enter__', '__exit__', 'close', 'read', # 'readinto', 'readline', 'write', 'flush', 'seek', 'tell'