mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 09:37:25 +00:00
all: ruff check --fix.
Mainly fixes and sorts imports.
This commit is contained in:
@@ -11,7 +11,7 @@ return types. This extension:
|
||||
call these functions.
|
||||
"""
|
||||
|
||||
from typing import Sequence
|
||||
from collections.abc import Sequence
|
||||
|
||||
from docutils import nodes
|
||||
from sphinx.addnodes import desc_sig_keyword
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from docutils.parsers.rst import Directive
|
||||
from docutils import nodes
|
||||
from pathlib import Path
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import Directive
|
||||
|
||||
SPHINX_IMAGE_PATH = "blockimg"
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class PybricksClasslinkDirective(Directive):
|
||||
link = name if len(self.arguments) == 1 else self.arguments[1]
|
||||
|
||||
html = (
|
||||
'<a href="{0}.html">'.format(link.lower())
|
||||
f'<a href="{link.lower()}.html">'
|
||||
+ '<dl class="py class">'
|
||||
+ "<dt>"
|
||||
+ '<em class="property">class </em>'
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from colorsys import hsv_to_rgb
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import Directive
|
||||
|
||||
from pybricks.parameters import Color
|
||||
from colorsys import hsv_to_rgb
|
||||
|
||||
|
||||
class PybricksColorDirective(Directive):
|
||||
@@ -18,19 +20,17 @@ class PybricksColorDirective(Directive):
|
||||
r, g, b = hsv_to_rgb(color.h / 360, color.s / 100, color.v / 100)
|
||||
|
||||
# Convert RGB to HEX
|
||||
rgbhex = "#{0:02x}{1:02x}{2:02x}".format(
|
||||
round(r * 255), round(g * 255), round(b * 255)
|
||||
)
|
||||
rgbhex = f"#{round(r * 255):02x}{round(g * 255):02x}{round(b * 255):02x}"
|
||||
|
||||
# Render a small block of the given color
|
||||
css = "background-color: {0}; color: {0}; width: 50px;".format(rgbhex)
|
||||
css = f"background-color: {rgbhex}; color: {rgbhex}; width: 50px;"
|
||||
|
||||
if name == "WHITE":
|
||||
css += (
|
||||
"border-style: solid; border-width: 0.5px;" + "border-color: #666666;"
|
||||
)
|
||||
|
||||
html = '<div id="test" style="{0}">_</div>'.format(css)
|
||||
html = f'<div id="test" style="{css}">_</div>'
|
||||
|
||||
# Return the node
|
||||
node = nodes.raw("", html, format="html")
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from os import path, makedirs
|
||||
from os import makedirs, path
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import Directive
|
||||
|
||||
from sphinx.util.osutil import copyfile
|
||||
|
||||
# Base feature set.
|
||||
@@ -72,7 +71,7 @@ class PybricksRequirementsStaticDirective(Directive):
|
||||
makedirs(destdir)
|
||||
|
||||
for hub in HUB_FEATURES:
|
||||
uri = "compat_{0}.png".format(hub)
|
||||
uri = f"compat_{hub}.png"
|
||||
src_uri = path.join(env.app.builder.srcdir, "diagrams", uri)
|
||||
build_uri = path.join(env.app.builder.outdir, "_images", uri)
|
||||
copyfile(src_uri, build_uri)
|
||||
@@ -103,17 +102,17 @@ class PybricksRequirementsStaticDirective(Directive):
|
||||
)
|
||||
|
||||
# Generate full table.
|
||||
html = """
|
||||
html = f"""
|
||||
<div class="wy-table-responsive">
|
||||
<table class="docutils align-default requirements-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
{0}
|
||||
{compat_row}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
""".format(compat_row)
|
||||
"""
|
||||
|
||||
# Return the node.
|
||||
node = nodes.raw("", html, format="html")
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
|
||||
|
||||
import os
|
||||
from docutils.parsers.rst import Directive, directives
|
||||
from docutils import nodes
|
||||
from docutils.statemachine import StringList
|
||||
from sphinx.util.osutil import copyfile
|
||||
from sphinx.util import logging
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import Directive, directives
|
||||
from docutils.statemachine import StringList
|
||||
from sphinx.util import logging
|
||||
from sphinx.util.osutil import copyfile
|
||||
|
||||
CSS_FILE = "requirements.css"
|
||||
JS_FILE = "requirements.js"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Pybricks documentation build configuration file
|
||||
#
|
||||
|
||||
@@ -10,7 +10,7 @@ remain a strict subset of that implementation when it comes to low-level
|
||||
implementation details.
|
||||
"""
|
||||
|
||||
from socket import socket, AF_BLUETOOTH, BTPROTO_RFCOMM, SOCK_STREAM
|
||||
from socket import AF_BLUETOOTH, BTPROTO_RFCOMM, SOCK_STREAM, socket
|
||||
from socketserver import ThreadingMixIn
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
# Copyright (C) 2020,2023 The Pybricks Authors
|
||||
|
||||
from errno import ECONNRESET
|
||||
from struct import pack, unpack
|
||||
from socket import BDADDR_ANY
|
||||
from socketserver import StreamRequestHandler
|
||||
from struct import pack, unpack
|
||||
from threading import Lock
|
||||
|
||||
from .bluetooth import ThreadingRFCOMMServer, ThreadingRFCOMMClient
|
||||
from .bluetooth import ThreadingRFCOMMClient, ThreadingRFCOMMServer
|
||||
|
||||
|
||||
def resolve(brick):
|
||||
@@ -128,7 +128,7 @@ class TextMailbox(Mailbox):
|
||||
"""
|
||||
|
||||
def encode(self, value):
|
||||
return ("{}\0".format(value)).encode("utf-8")
|
||||
return (f"{value}\0").encode()
|
||||
|
||||
def decode(self, payload):
|
||||
return payload.decode().strip("\0")
|
||||
@@ -217,7 +217,7 @@ class MailboxHandlerMixIn:
|
||||
mbox_len = len(mbox) + 1
|
||||
payload_len = len(payload)
|
||||
send_len = 7 + mbox_len + payload_len
|
||||
fmt = "<HHBBB{}sH{}s".format(mbox_len, payload_len)
|
||||
fmt = f"<HHBBB{mbox_len}sH{payload_len}s"
|
||||
data = pack(
|
||||
fmt,
|
||||
send_len,
|
||||
@@ -239,7 +239,7 @@ class MailboxHandlerMixIn:
|
||||
addr = resolve(brick)
|
||||
self._addresses[brick] = addr
|
||||
if addr is None:
|
||||
raise ValueError('no paired devices matching "{}"'.format(brick))
|
||||
raise ValueError(f'no paired devices matching "{brick}"')
|
||||
self._clients[addr].send(data)
|
||||
|
||||
def wait_for_mailbox_update(self, mbox):
|
||||
@@ -334,7 +334,7 @@ class BluetoothMailboxClient(MailboxHandlerMixIn):
|
||||
"""
|
||||
addr = resolve(brick)
|
||||
if addr is None:
|
||||
raise ValueError('no paired devices matching "{}"'.format(brick))
|
||||
raise ValueError(f'no paired devices matching "{brick}"')
|
||||
client = MailboxRFCOMMClient(self, addr)
|
||||
if self._clients.setdefault(addr, client) is not client:
|
||||
raise ValueError("connection with this address already exists")
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from uctypes import addressof, sizeof, struct
|
||||
from usocket import socket, SOCK_STREAM
|
||||
|
||||
from _thread import start_new_thread
|
||||
|
||||
from pybricks.bluetooth import str2ba, sockaddr_rc, AF_BLUETOOTH, BTPROTO_RFCOMM
|
||||
from pybricks.tools import wait, StopWatch
|
||||
from pybricks.bluetooth import AF_BLUETOOTH, BTPROTO_RFCOMM, sockaddr_rc, str2ba
|
||||
from uctypes import addressof, sizeof, struct
|
||||
from usocket import SOCK_STREAM, socket
|
||||
|
||||
from pybricks.tools import StopWatch, wait
|
||||
|
||||
|
||||
def get_bluetooth_rfcomm_socket(address, channel):
|
||||
@@ -37,7 +37,7 @@ class SpikePrimeStreamReader:
|
||||
if self.values() is not None:
|
||||
return
|
||||
wait(100)
|
||||
raise IOError("No data received")
|
||||
raise OSError("No data received")
|
||||
|
||||
def disconnect(self):
|
||||
self.sock.close()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from connection import SpikePrimeStreamReader
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
|
||||
from connection import SpikePrimeStreamReader
|
||||
|
||||
# Beep!
|
||||
ev3 = EV3Brick()
|
||||
ev3.speaker.beep()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.ev3devices import Motor
|
||||
from pybricks.robotics import DriveBase
|
||||
from pybricks.parameters import Port
|
||||
|
||||
from connection import SpikePrimeStreamReader
|
||||
|
||||
from pybricks.ev3devices import Motor
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.robotics import DriveBase
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Beep!
|
||||
ev3 = EV3Brick()
|
||||
ev3.speaker.beep()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.parameters import Button
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from menu import wait_for_button
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.parameters import Button
|
||||
|
||||
from menu import wait_for_button
|
||||
|
||||
# Initialize the EV3.
|
||||
ev3 = EV3Brick()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.ev3devices import Motor
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.parameters import Port
|
||||
|
||||
# Create your objects here
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.parameters import Color
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import struct
|
||||
|
||||
from pybricks.ev3devices import Motor
|
||||
from pybricks.parameters import Port
|
||||
|
||||
import struct
|
||||
|
||||
# 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.iodevices import AnalogSensor
|
||||
from pybricks.parameters import Port, Color
|
||||
from pybricks.parameters import Color, Port
|
||||
from pybricks.tools import wait
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import math
|
||||
|
||||
from pybricks.media.ev3dev import Font, Image
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.parameters import Color
|
||||
from pybricks.tools import wait
|
||||
from pybricks.media.ev3dev import Font, Image
|
||||
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
@@ -63,7 +63,7 @@ for t in range(200):
|
||||
|
||||
# Print every 10th value on right side
|
||||
if t % 10 == 0:
|
||||
right.print("{:10.2f}{:10.2f}".format(x1, y1))
|
||||
right.print(f"{x1:10.2f}{y1:10.2f}")
|
||||
|
||||
wait(100)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from pybricks.media.ev3dev import Image, ImageFile
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.media.ev3dev import Image, ImageFile
|
||||
|
||||
# It takes some time to load images from the SD card, so it is best to load
|
||||
# them once at the beginning of a program like this:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from pybricks.media.ev3dev import Font
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.media.ev3dev import Font
|
||||
|
||||
# It takes some time for fonts to load from file, so it is best to only
|
||||
# load them once at the beginning of the program like this:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
from pybricks.media.ev3dev import SoundFile
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from pybricks.media.ev3dev import SoundFile
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.iodevices import UARTDevice
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.media.ev3dev import SoundFile
|
||||
|
||||
# Initialize the EV3
|
||||
ev3 = EV3Brick()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.nxtdevices import VernierAdapter
|
||||
|
||||
from math import log
|
||||
|
||||
from pybricks.nxtdevices import VernierAdapter
|
||||
from pybricks.parameters import Port
|
||||
|
||||
|
||||
# Conversion formula for Surface Temperature Sensor
|
||||
def convert_raw_to_temperature(voltage):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the motor.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from micropython import const, opt_level, mem_info, qstr_info, stack_use
|
||||
from micropython import const, mem_info, opt_level, qstr_info, stack_use
|
||||
|
||||
# Get stack at start.
|
||||
stack_start = stack_use()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
|
||||
from pybricks.pupdevices import Motor
|
||||
from uerrno import ENODEV
|
||||
|
||||
try:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.tools import wait
|
||||
from pybricks.messaging import BLERadio
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
radio = BLERadio(broadcast_channel=1)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.tools import wait
|
||||
from pybricks.messaging import BLERadio
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
radio = BLERadio(observe_channels=[1])
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# ThisHub = MoveHub CityHub TechnicHub EssentialHub
|
||||
from pybricks.hubs import ThisHub
|
||||
from pybricks.parameters import Color, Button
|
||||
from pybricks.tools import wait, StopWatch
|
||||
from pybricks.parameters import Button, Color
|
||||
from pybricks.tools import StopWatch, wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = ThisHub()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# ThisHub = TechnicHub PrimeHub EssentialHub
|
||||
from pybricks.hubs import ThisHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.parameters import Axis
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = ThisHub()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# ThisHub = TechnicHub PrimeHub EssentialHub
|
||||
from pybricks.hubs import ThisHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.parameters import Axis
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub. In this case, specify that the hub is mounted with the
|
||||
# top side facing forward and the front side facing to the right.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from pybricks.hubs import ThisHub
|
||||
from pybricks.parameters import Color
|
||||
from pybricks.tools import wait
|
||||
from umath import sin, pi
|
||||
from umath import pi, sin
|
||||
|
||||
# Initialize the hub.
|
||||
hub = ThisHub()
|
||||
|
||||
@@ -30,6 +30,6 @@ for file_path in file_paths:
|
||||
# Open destination script:
|
||||
with open(gen_path, "w") as dest_file:
|
||||
# Read script line by line.
|
||||
for line in template.readlines():
|
||||
for line in template:
|
||||
# Replace hub name if present.
|
||||
dest_file.writelines(line.replace("ThisHub", hub))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from pybricks.hubs import PrimeHub
|
||||
from pybricks.parameters import Icon, Side
|
||||
from pybricks.tools import wait
|
||||
|
||||
from urandom import randint
|
||||
|
||||
# Initialize the hub.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from pybricks.hubs import PrimeHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.parameters import Icon
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = PrimeHub()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.hubs import PrimeHub
|
||||
from pybricks.tools import wait, Matrix
|
||||
from pybricks.tools import Matrix, wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = PrimeHub()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from pybricks.hubs import PrimeHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.parameters import Side
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = PrimeHub()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Light
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Light
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the light.
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from pybricks.pupdevices import Light
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.tools import wait, StopWatch
|
||||
|
||||
from umath import pi, cos
|
||||
from pybricks.pupdevices import Light
|
||||
from pybricks.tools import StopWatch, wait
|
||||
from umath import cos, pi
|
||||
|
||||
# Initialize the light and a StopWatch.
|
||||
light = Light(Port.A)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port, Stop
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
|
||||
# Initialize motors on port A and B.
|
||||
track_motor = Motor(Port.A)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize motors on port A and B.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Direction, Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port, Direction
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A with the positive direction as counterclockwise.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Direction, Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port, Direction
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A with the positive direction as counterclockwise.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize motors on port A and B.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
|
||||
# Initialize a motor on port A.
|
||||
example_motor = Motor(Port.A)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
|
||||
# Initialize a motor on port A.
|
||||
example_motor = Motor(Port.A)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import DCMotor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import DCMotor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the motor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import DCMotor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import DCMotor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor without rotation sensors on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Direction, Port
|
||||
from pybricks.pupdevices import DCMotor
|
||||
from pybricks.parameters import Port, Direction
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor without rotation sensors on port A,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import DCMotor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import DCMotor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize a motor without rotation sensors on port A.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Color, Port
|
||||
from pybricks.pupdevices import ColorDistanceSensor, PFMotor
|
||||
from pybricks.parameters import Port, Color
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Color, Direction, Port
|
||||
from pybricks.pupdevices import ColorDistanceSensor, PFMotor
|
||||
from pybricks.parameters import Port, Color, Direction
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Remote
|
||||
from pybricks.parameters import Button
|
||||
from pybricks.pupdevices import Remote
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Connect to the remote.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Remote
|
||||
from pybricks.parameters import Button, Color
|
||||
from pybricks.pupdevices import Remote
|
||||
|
||||
|
||||
def button_to_color(buttons):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Remote
|
||||
from pybricks.parameters import Color
|
||||
from pybricks.pupdevices import Remote
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Connect to the remote.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from pybricks.parameters import Direction, Port, Button
|
||||
from pybricks.parameters import Button, Direction, Port
|
||||
from pybricks.pupdevices import Motor, Remote
|
||||
from pybricks.robotics import Car
|
||||
from pybricks.tools import wait
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Direction, Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.robotics import DriveBase
|
||||
from pybricks.tools import multitask, run_task
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Direction, Port
|
||||
from pybricks.pupdevices import Motor
|
||||
from pybricks.parameters import Port, Direction
|
||||
from pybricks.robotics import DriveBase
|
||||
|
||||
# Initialize both motors. In this example, the motor on the
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Color, Port
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.parameters import Port, Color
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Color, Port
|
||||
from pybricks.pupdevices import ColorSensor
|
||||
from pybricks.parameters import Port, Color
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import ColorDistanceSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import ColorDistanceSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Color, Port
|
||||
from pybricks.pupdevices import ColorDistanceSensor
|
||||
from pybricks.parameters import Port, Color
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Color, Port
|
||||
from pybricks.pupdevices import ColorDistanceSensor
|
||||
from pybricks.parameters import Port, Color
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import ColorDistanceSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import ColorDistanceSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.parameters import Color, Port
|
||||
from pybricks.pupdevices import ColorDistanceSensor
|
||||
from pybricks.parameters import Port, Color
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import ForceSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import ForceSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import ForceSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import ForceSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
@@ -28,8 +28,7 @@ def wait_for_force():
|
||||
force = button.force()
|
||||
|
||||
# Update the maximum if the measured force is larger.
|
||||
if force > maximum:
|
||||
maximum = force
|
||||
maximum = max(maximum, force)
|
||||
|
||||
# Wait and then measure again.
|
||||
wait(10)
|
||||
@@ -42,4 +41,4 @@ def wait_for_force():
|
||||
# the peak force and repeat.
|
||||
while True:
|
||||
peak = wait_for_force()
|
||||
print("Released. Peak force: {0} N\n".format(peak))
|
||||
print(f"Released. Peak force: {peak} N\n")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import InfraredSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import InfraredSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import TiltSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import TiltSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pybricks.pupdevices import UltrasonicSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.pupdevices import UltrasonicSensor
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from pybricks.pupdevices import UltrasonicSensor
|
||||
from pybricks.parameters import Port
|
||||
from pybricks.tools import wait, StopWatch
|
||||
|
||||
from pybricks.pupdevices import UltrasonicSensor
|
||||
from pybricks.tools import StopWatch, wait
|
||||
from umath import pi, sin
|
||||
|
||||
# Initialize the sensor.
|
||||
|
||||
@@ -8,7 +8,9 @@ from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from . import _common
|
||||
from .parameters import Axis, Button as _Button, Image as _Image
|
||||
from .parameters import Axis
|
||||
from .parameters import Button as _Button
|
||||
from .parameters import Image as _Image
|
||||
|
||||
|
||||
class EV3Brick:
|
||||
@@ -132,7 +134,6 @@ class EssentialHub:
|
||||
front_side (Axis): The axis that passes through the *front side* of
|
||||
the hub.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class PrimeHub:
|
||||
|
||||
@@ -53,7 +53,7 @@ class BLERadio:
|
||||
) -> MaybeAwaitable: ...
|
||||
|
||||
@overload
|
||||
def broadcast(self, data: bool | int | float | str | bytes) -> MaybeAwaitable: ...
|
||||
def broadcast(self, data: bool | float | str | bytes) -> MaybeAwaitable: ...
|
||||
|
||||
def broadcast(self, data: object) -> MaybeAwaitable:
|
||||
"""broadcast(data)
|
||||
|
||||
@@ -9,10 +9,11 @@ import os
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, overload
|
||||
|
||||
from .tools import Matrix as _Matrix, vector as _vector
|
||||
from .tools import Matrix as _Matrix
|
||||
from .tools import vector as _vector
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any, Literal, Optional, Union
|
||||
from typing import Any, Literal
|
||||
|
||||
if TYPE_CHECKING or os.environ.get("SPHINX_BUILD") == "True":
|
||||
Number = int | float
|
||||
@@ -54,7 +55,7 @@ class _PybricksEnum(Enum, metaclass=_PybricksEnumMeta):
|
||||
yield member.name
|
||||
|
||||
def __str__(self):
|
||||
return "{}.{}".format(type(self).__name__, self.name)
|
||||
return f"{type(self).__name__}.{self.name}"
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
@@ -123,7 +124,7 @@ class Color:
|
||||
return iter((self.h, self.s, self.v))
|
||||
|
||||
def __repr__(self):
|
||||
return "Color(h={}, s={}, v={})".format(self.h, self.s, self.v)
|
||||
return f"Color(h={self.h}, s={self.s}, v={self.v})"
|
||||
|
||||
def __eq__(self, other: Color) -> bool:
|
||||
return self.h == other.h and self.s == other.s and self.v == other.v
|
||||
@@ -577,7 +578,7 @@ class Image:
|
||||
# is generated.
|
||||
|
||||
@overload
|
||||
def __init__(self, /, source: Union[Image, ImageFile]): ...
|
||||
def __init__(self, /, source: Image | ImageFile): ...
|
||||
|
||||
@overload
|
||||
def __init__(
|
||||
@@ -698,8 +699,8 @@ class Image:
|
||||
self,
|
||||
x: int,
|
||||
y: int,
|
||||
source: Union[Image, ImageFile],
|
||||
transparent: Optional[Color] = None,
|
||||
source: Image | ImageFile,
|
||||
transparent: Color | None = None,
|
||||
) -> None:
|
||||
"""draw_image(x, y, source, transparent=None)
|
||||
|
||||
@@ -717,7 +718,7 @@ class Image:
|
||||
no transparency.
|
||||
"""
|
||||
|
||||
def load_image(self, source: Union[Image, ImageFile]) -> None:
|
||||
def load_image(self, source: Image | ImageFile) -> None:
|
||||
"""load_image(source)
|
||||
|
||||
Clears this image, then draws the ``source`` image centered in
|
||||
@@ -734,7 +735,7 @@ class Image:
|
||||
y: int,
|
||||
text: str,
|
||||
text_color: Color = Color.BLACK,
|
||||
background_color: Optional[Color] = None,
|
||||
background_color: Color | None = None,
|
||||
) -> None:
|
||||
"""draw_text(x, y, text, text_color=Color.BLACK, background_color=None)
|
||||
|
||||
|
||||
@@ -566,7 +566,6 @@ class ColorLightMatrix:
|
||||
port (Port): Port to which the device is connected.
|
||||
|
||||
"""
|
||||
...
|
||||
|
||||
def on(self, color: Color | Collection[Color]) -> MaybeAwaitable:
|
||||
"""on(colors)
|
||||
@@ -579,14 +578,12 @@ class ColorLightMatrix:
|
||||
to that color. If a list of colors is given, then each light is
|
||||
set to that color.
|
||||
"""
|
||||
...
|
||||
|
||||
def off(self) -> MaybeAwaitable:
|
||||
"""off()
|
||||
|
||||
Turns all lights off.
|
||||
"""
|
||||
...
|
||||
|
||||
|
||||
class InfraredSensor:
|
||||
|
||||
@@ -141,7 +141,7 @@ class Matrix:
|
||||
"""
|
||||
|
||||
@property
|
||||
def T(self) -> Matrix: # noqa: N802
|
||||
def T(self) -> Matrix:
|
||||
"""Returns a new :class:`.Matrix` that is the transpose of the
|
||||
original."""
|
||||
|
||||
|
||||
+37
-40
@@ -19,17 +19,13 @@ The following functions and exceptions can be used without importing anything.
|
||||
Most functions and classes in this module do not accept keyword arguments.
|
||||
"""
|
||||
|
||||
import builtins
|
||||
from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping, Sequence
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
Hashable,
|
||||
Iterable,
|
||||
Iterator,
|
||||
List,
|
||||
Literal,
|
||||
Mapping,
|
||||
Sequence,
|
||||
SupportsComplex,
|
||||
SupportsFloat,
|
||||
SupportsInt,
|
||||
@@ -39,10 +35,11 @@ from typing import (
|
||||
overload,
|
||||
)
|
||||
|
||||
from typing_extensions import Self
|
||||
|
||||
import uio
|
||||
import usys
|
||||
|
||||
|
||||
# These get overridden later on, but we still want to use the originals
|
||||
# for the purpose of typing the doc strings.
|
||||
_bool = bool
|
||||
@@ -146,7 +143,7 @@ class bool:
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
"""
|
||||
bool()
|
||||
bool(\u200b)
|
||||
bool(x)
|
||||
|
||||
Creates a boolean value, which is either ``True`` or ``False``.
|
||||
@@ -170,7 +167,7 @@ class bytes:
|
||||
def __init__(self, source: _int) -> None: ...
|
||||
|
||||
@overload
|
||||
def __init__(self, source: Union[_bytes, _bytearray, Iterable[_int]]) -> None: ...
|
||||
def __init__(self, source: _bytes | _bytearray | Iterable[_int]) -> None: ...
|
||||
|
||||
@overload
|
||||
def __init__(self, source: _str, encoding: _str) -> None: ...
|
||||
@@ -210,7 +207,7 @@ class bytearray:
|
||||
|
||||
@overload
|
||||
def __init__(
|
||||
self, source: Union[_bytes, _bytearray, _str, Iterable[_int]]
|
||||
self, source: _bytes | _bytearray | _str | Iterable[_int]
|
||||
) -> None: ...
|
||||
|
||||
def __init__(self, *args):
|
||||
@@ -278,14 +275,14 @@ class complex:
|
||||
|
||||
@overload
|
||||
def __init__(
|
||||
self, real: Union[_float, SupportsFloat, _complex, SupportsComplex]
|
||||
self, real: _float | SupportsFloat | _complex | SupportsComplex
|
||||
) -> None: ...
|
||||
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
real: Union[_float, SupportsFloat, _complex, SupportsComplex],
|
||||
imag: Union[_float, SupportsFloat, _complex, SupportsComplex],
|
||||
real: _float | SupportsFloat | _complex | SupportsComplex,
|
||||
imag: _float | SupportsFloat | _complex | SupportsComplex,
|
||||
) -> None: ...
|
||||
|
||||
@overload
|
||||
@@ -335,14 +332,14 @@ 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]
|
||||
@@ -361,11 +358,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):
|
||||
@@ -524,7 +521,7 @@ def getattr(*args):
|
||||
"""
|
||||
|
||||
|
||||
def globals() -> Dict[_str, Any]:
|
||||
def globals() -> builtins.dict[_str, Any]:
|
||||
"""
|
||||
globals() -> dict
|
||||
|
||||
@@ -652,7 +649,7 @@ class int:
|
||||
def __init__(self, x: _str, base: _int) -> None: ...
|
||||
|
||||
@overload
|
||||
def __init__(self, x: Union[_int, SupportsInt]) -> None: ...
|
||||
def __init__(self, x: _int | SupportsInt) -> None: ...
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
"""int(x=0)
|
||||
@@ -696,7 +693,7 @@ class int:
|
||||
"""
|
||||
|
||||
|
||||
def isinstance(object: Any, classinfo: Union[_type, Tuple[_type]]) -> _bool:
|
||||
def isinstance(object: Any, classinfo: _type | tuple[_type]) -> _bool:
|
||||
"""
|
||||
isinstance(object, classinfo) -> bool
|
||||
|
||||
@@ -712,7 +709,7 @@ def isinstance(object: Any, classinfo: Union[_type, Tuple[_type]]) -> _bool:
|
||||
"""
|
||||
|
||||
|
||||
def issubclass(cls: _type, classinfo: Union[_type, Tuple[_type]]) -> _bool:
|
||||
def issubclass(cls: _type, classinfo: _type | tuple[_type]) -> _bool:
|
||||
"""
|
||||
issubclass(cls, classinfo) -> bool
|
||||
|
||||
@@ -727,7 +724,7 @@ def issubclass(cls: _type, classinfo: Union[_type, Tuple[_type]]) -> _bool:
|
||||
"""
|
||||
|
||||
|
||||
def iter(object: Union[Iterable, Sequence]) -> Iterator:
|
||||
def iter(object: Iterable | Sequence) -> Iterator:
|
||||
"""
|
||||
iter(object) -> Iterator
|
||||
|
||||
@@ -764,7 +761,7 @@ class list:
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
"""
|
||||
list()
|
||||
list(\u200b)
|
||||
list(iterable)
|
||||
|
||||
Creates a new list. If no argument is given, this creates an empty
|
||||
@@ -908,7 +905,7 @@ def ord(c: _str) -> _int:
|
||||
"""
|
||||
|
||||
|
||||
def pow(base: Union[_int, _float], exp: Union[_int, _float]) -> Union[_int, _float]:
|
||||
def pow(base: _int | _float, exp: _int | _float) -> _int | _float:
|
||||
"""
|
||||
pow(base, exp) -> Number
|
||||
|
||||
@@ -1066,7 +1063,7 @@ class set:
|
||||
iterable: An iterable of hashable objects.
|
||||
"""
|
||||
|
||||
def copy(self: _Self) -> _Self:
|
||||
def copy(self) -> Self:
|
||||
"""
|
||||
copy() -> set
|
||||
|
||||
@@ -1076,7 +1073,7 @@ class set:
|
||||
A new set.
|
||||
"""
|
||||
|
||||
def difference(self: _Self, *others: set) -> _Self:
|
||||
def difference(self, *others: set) -> Self:
|
||||
"""
|
||||
difference(other1, other2, ...) -> set
|
||||
|
||||
@@ -1093,7 +1090,7 @@ class set:
|
||||
A new set.
|
||||
"""
|
||||
|
||||
def intersection(self: _Self, *others: set) -> _Self:
|
||||
def intersection(self, *others: set) -> Self:
|
||||
"""
|
||||
intersection(other1, other2, ...) -> set
|
||||
|
||||
@@ -1163,7 +1160,7 @@ class set:
|
||||
``True`` if this set is a superset of *other*, otherwise ``False``.
|
||||
"""
|
||||
|
||||
def symmetric_difference(self: _Self, other: set) -> _Self:
|
||||
def symmetric_difference(self, other: set) -> Self:
|
||||
"""
|
||||
symmetric_difference(other) -> bool
|
||||
|
||||
@@ -1180,7 +1177,7 @@ class set:
|
||||
A new set.
|
||||
"""
|
||||
|
||||
def union(self: _Self, *others: set) -> _Self:
|
||||
def union(self, *others: set) -> Self:
|
||||
"""
|
||||
union(other1, other2, ...) -> set
|
||||
|
||||
@@ -1215,13 +1212,13 @@ class set:
|
||||
|
||||
def __ne__(self, other: set) -> bool: ...
|
||||
|
||||
def __sub__(self: _Self, other: set) -> _Self: ...
|
||||
def __sub__(self, other: set) -> Self: ...
|
||||
|
||||
def __and__(self: _Self, other: set) -> _Self: ...
|
||||
def __and__(self, other: set) -> Self: ...
|
||||
|
||||
def __or__(self: _Self, other: set) -> _Self: ...
|
||||
def __or__(self, other: set) -> Self: ...
|
||||
|
||||
def __xor__(self: _Self, other: set) -> _Self: ...
|
||||
def __xor__(self, other: set) -> Self: ...
|
||||
|
||||
|
||||
def setattr(object: Any, name: _str, value: Any) -> None:
|
||||
@@ -1251,7 +1248,7 @@ class slice:
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
"""
|
||||
slice()
|
||||
slice(\u200b)
|
||||
|
||||
Creating instances of this class is not supported.
|
||||
|
||||
@@ -1260,7 +1257,7 @@ class slice:
|
||||
"""
|
||||
|
||||
|
||||
def sorted(iterable: Iterable, key=None, reverse=False) -> List:
|
||||
def sorted(iterable: Iterable, key=None, reverse=False) -> builtins.list:
|
||||
"""
|
||||
Sorts objects.
|
||||
|
||||
@@ -1296,7 +1293,7 @@ class str:
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
str()
|
||||
str(\u200b)
|
||||
str(object)
|
||||
str(object, encoding)
|
||||
|
||||
@@ -1372,7 +1369,7 @@ class tuple:
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
"""
|
||||
tuple()
|
||||
tuple(\u200b)
|
||||
tuple(iterable)
|
||||
|
||||
Creates a new tuple. If no argument is given, this creates an empty
|
||||
@@ -1398,7 +1395,7 @@ class type:
|
||||
"""
|
||||
|
||||
|
||||
def zip(*iterables: Iterable) -> Iterable[Tuple]:
|
||||
def zip(*iterables: Iterable) -> Iterable[builtins.tuple]:
|
||||
"""
|
||||
zip(iter_a, iter_b, ...) -> Iterable[Tuple]
|
||||
|
||||
@@ -1446,7 +1443,7 @@ class BaseException:
|
||||
use :class:`Exception`).
|
||||
"""
|
||||
|
||||
args: Tuple
|
||||
args: builtins.tuple
|
||||
"""
|
||||
The tuple of arguments given to the exception constructor.
|
||||
"""
|
||||
|
||||
@@ -59,7 +59,7 @@ The operation timed out.
|
||||
# TODO: ev3dev has additional constants
|
||||
# https://github.com/pybricks/pybricks-micropython/blob/11f19bc9c24fde66aa8ad42233a345e6683f5beb/bricks/ev3dev/mpconfigport.h#L156-L203
|
||||
|
||||
errorcode: Dict[int, str]
|
||||
errorcode: dict[int, str]
|
||||
"""
|
||||
Dictionary that maps numeric error codes to strings with symbolic error code.
|
||||
"""
|
||||
|
||||
+4
-4
@@ -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 overload, Union
|
||||
from typing import Union, overload
|
||||
|
||||
# TODO: MicroPython streams implement '__enter__', '__exit__', 'close', 'read',
|
||||
# 'readinto', 'readline', 'write', 'flush', 'seek', 'tell'
|
||||
@@ -23,14 +23,14 @@ class BytesIO:
|
||||
def __init__(self) -> None: ...
|
||||
|
||||
@overload
|
||||
def __init__(self, data: Union[bytes, bytearray]) -> None: ...
|
||||
def __init__(self, data: bytes | bytearray) -> None: ...
|
||||
|
||||
@overload
|
||||
def __init__(self, alloc_size: int) -> None: ...
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
"""
|
||||
BytesIO()
|
||||
BytesIO(\u200b)
|
||||
BytesIO(data)
|
||||
BytesIO(alloc_size)
|
||||
|
||||
@@ -64,7 +64,7 @@ class StringIO:
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
"""
|
||||
StringIO()
|
||||
StringIO(\u200b)
|
||||
StringIO(string)
|
||||
StringIO(alloc_size)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Convert between Python objects and the JSON data format.
|
||||
from typing import IO, Any, Tuple
|
||||
|
||||
|
||||
def dump(object: Any, stream: IO, separators: Tuple[str, str] = (", ", ": ")):
|
||||
def dump(object: Any, stream: IO, separators: tuple[str, str] = (", ", ": ")):
|
||||
"""
|
||||
dump(object, stream, separators=(", ", ": "))
|
||||
|
||||
@@ -26,7 +26,7 @@ def dump(object: Any, stream: IO, separators: Tuple[str, str] = (", ", ": ")):
|
||||
"""
|
||||
|
||||
|
||||
def dumps(object: Any, separators: Tuple[str, str] = (", ", ": ")) -> str:
|
||||
def dumps(object: Any, separators: tuple[str, str] = (", ", ": ")) -> str:
|
||||
"""
|
||||
dumps(object, separators=(", ", ": "))
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ Math functions.
|
||||
|
||||
from typing import Tuple as Tuple
|
||||
|
||||
|
||||
e = 2.718282
|
||||
"""The mathematical constant e."""
|
||||
|
||||
@@ -264,7 +263,7 @@ def fabs(x: float) -> float:
|
||||
"""
|
||||
|
||||
|
||||
def modf(x: float) -> Tuple[float, float]:
|
||||
def modf(x: float) -> tuple[float, float]:
|
||||
"""modf(x) -> Tuple[float, float]
|
||||
|
||||
Gets the fractional and integral parts of ``x``, both with the same sign
|
||||
@@ -280,7 +279,7 @@ def modf(x: float) -> Tuple[float, float]:
|
||||
"""
|
||||
|
||||
|
||||
def frexp(x: float) -> Tuple[float, int]:
|
||||
def frexp(x: float) -> tuple[float, int]:
|
||||
"""frexp(x) -> Tuple[float, float]
|
||||
|
||||
Decomposes a value ``x`` into a
|
||||
|
||||
@@ -13,10 +13,11 @@ All functions in this module should be used with positional arguments. Keyword
|
||||
arguments are not supported.
|
||||
"""
|
||||
|
||||
from typing import Any, Optional, Sequence, overload
|
||||
from collections.abc import Sequence
|
||||
from typing import Any, Optional, overload
|
||||
|
||||
|
||||
def seed(a: Optional[int] = None) -> None:
|
||||
def seed(a: int | None = None) -> None:
|
||||
"""
|
||||
seed(value=None)
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
This module provides functions to efficiently wait for events on multiple streams.
|
||||
"""
|
||||
|
||||
from typing import IO, Iterator, List, Tuple, overload
|
||||
from collections.abc import Iterator
|
||||
from typing import IO, List, Tuple, overload
|
||||
|
||||
POLLIN: int
|
||||
"""
|
||||
@@ -78,12 +79,12 @@ class Poll:
|
||||
"""
|
||||
|
||||
@overload
|
||||
def poll(self) -> List[Tuple[IO, int]]: ...
|
||||
def poll(self) -> list[tuple[IO, int]]: ...
|
||||
|
||||
@overload
|
||||
def poll(self, timeout: int) -> List[Tuple[IO, int]]: ...
|
||||
def poll(self, timeout: int) -> list[tuple[IO, int]]: ...
|
||||
|
||||
def poll(self, timeout: int = -1, /) -> List[Tuple[IO, int]]:
|
||||
def poll(self, timeout: int = -1, /) -> list[tuple[IO, int]]:
|
||||
"""
|
||||
poll(timeout=-1) -> List[Tuple[FileIO, int]]
|
||||
|
||||
@@ -103,15 +104,15 @@ class Poll:
|
||||
"""
|
||||
|
||||
@overload
|
||||
def ipoll(self) -> Iterator[Tuple[IO, int]]: ...
|
||||
def ipoll(self) -> Iterator[tuple[IO, int]]: ...
|
||||
|
||||
@overload
|
||||
def ipoll(self, timeout: int) -> Iterator[Tuple[IO, int]]: ...
|
||||
def ipoll(self, timeout: int) -> Iterator[tuple[IO, int]]: ...
|
||||
|
||||
@overload
|
||||
def ipoll(self, timeout: int, flags: int) -> Iterator[Tuple[IO, int]]: ...
|
||||
def ipoll(self, timeout: int, flags: int) -> Iterator[tuple[IO, int]]: ...
|
||||
|
||||
def ipoll(self, timeout: int = -1, flags: int = 0, /) -> Iterator[Tuple[IO, int]]:
|
||||
def ipoll(self, timeout: int = -1, flags: int = 0, /) -> Iterator[tuple[IO, int]]:
|
||||
"""
|
||||
ipoll(timeout=-1, flags=1) -> Iterator[Tuple[FileIO, int]]
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ This module provides functions to convert between Python values and C-like
|
||||
data structs.
|
||||
"""
|
||||
|
||||
from typing import Union, Tuple
|
||||
from typing import Tuple, Union
|
||||
|
||||
|
||||
def calcsize(format: str) -> int:
|
||||
@@ -53,7 +53,7 @@ def pack_into(format: str, buffer: bytearray, offset: int, *values) -> bytes:
|
||||
"""
|
||||
|
||||
|
||||
def unpack(format: str, data: Union[bytes, bytearray]) -> Tuple:
|
||||
def unpack(format: str, data: bytes | bytearray) -> tuple:
|
||||
"""
|
||||
unpack(format, data) -> Tuple
|
||||
|
||||
@@ -68,7 +68,7 @@ def unpack(format: str, data: Union[bytes, bytearray]) -> Tuple:
|
||||
"""
|
||||
|
||||
|
||||
def unpack_from(format: str, data: Union[bytes, bytearray], offset: int) -> Tuple:
|
||||
def unpack_from(format: str, data: bytes | bytearray, offset: int) -> tuple:
|
||||
"""
|
||||
unpack_from(format, data, offset) -> Tuple
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ stderr: _FileIO = _FileIO()
|
||||
Alias for :data:`stdout`.
|
||||
"""
|
||||
|
||||
implementation: Tuple[str, Tuple[int, int, int], str, int] = (
|
||||
implementation: tuple[str, tuple[int, int, int], str, int] = (
|
||||
"micropython",
|
||||
(1, 19, 1),
|
||||
"NAME Hub with PROCESSOR",
|
||||
@@ -49,5 +49,5 @@ Python compatibility version, Pybricks version, and build date.
|
||||
See format and example below.
|
||||
"""
|
||||
|
||||
version_info: Tuple[int, int, int] = (3, 4, 0)
|
||||
version_info: tuple[int, int, int] = (3, 4, 0)
|
||||
"""Python compatibility version. See format and example below."""
|
||||
|
||||
Reference in New Issue
Block a user