diff --git a/doc/common/extensions/awaitable.py b/doc/common/extensions/awaitable.py
index 2f54541..d668242 100644
--- a/doc/common/extensions/awaitable.py
+++ b/doc/common/extensions/awaitable.py
@@ -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
diff --git a/doc/common/extensions/blockimg.py b/doc/common/extensions/blockimg.py
index ab99e59..d1d0836 100644
--- a/doc/common/extensions/blockimg.py
+++ b/doc/common/extensions/blockimg.py
@@ -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"
diff --git a/doc/common/extensions/classlink.py b/doc/common/extensions/classlink.py
index 3d854a0..a66532b 100644
--- a/doc/common/extensions/classlink.py
+++ b/doc/common/extensions/classlink.py
@@ -12,7 +12,7 @@ class PybricksClasslinkDirective(Directive):
link = name if len(self.arguments) == 1 else self.arguments[1]
html = (
- ''.format(link.lower())
+ f''
+ ''
+ "- "
+ 'class '
diff --git a/doc/common/extensions/color.py b/doc/common/extensions/color.py
index d2e399b..50b2e11 100644
--- a/doc/common/extensions/color.py
+++ b/doc/common/extensions/color.py
@@ -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 = '
_
'.format(css)
+ html = f'_
'
# Return the node
node = nodes.raw("", html, format="html")
diff --git a/doc/common/extensions/requirements-static.py b/doc/common/extensions/requirements-static.py
index fbb7e4a..afcf14e 100644
--- a/doc/common/extensions/requirements-static.py
+++ b/doc/common/extensions/requirements-static.py
@@ -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"""
- """.format(compat_row)
+ """
# Return the node.
node = nodes.raw("", html, format="html")
diff --git a/doc/common/extensions/requirements.py b/doc/common/extensions/requirements.py
index a517bb6..f3691f6 100644
--- a/doc/common/extensions/requirements.py
+++ b/doc/common/extensions/requirements.py
@@ -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"
diff --git a/doc/main/conf.py b/doc/main/conf.py
index 0c30c80..74abf9b 100644
--- a/doc/main/conf.py
+++ b/doc/main/conf.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
#
# Pybricks documentation build configuration file
#
diff --git a/examples/ev3/bluetooth_pc/pybricks/bluetooth.py b/examples/ev3/bluetooth_pc/pybricks/bluetooth.py
index 61bfc9f..5a2f63b 100644
--- a/examples/ev3/bluetooth_pc/pybricks/bluetooth.py
+++ b/examples/ev3/bluetooth_pc/pybricks/bluetooth.py
@@ -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
diff --git a/examples/ev3/bluetooth_pc/pybricks/messaging.py b/examples/ev3/bluetooth_pc/pybricks/messaging.py
index 34d384b..a4267d9 100644
--- a/examples/ev3/bluetooth_pc/pybricks/messaging.py
+++ b/examples/ev3/bluetooth_pc/pybricks/messaging.py
@@ -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 = " 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")
diff --git a/examples/pup/sensor_infrared/basics.py b/examples/pup/sensor_infrared/basics.py
index 0b1bd3c..0c4ba67 100644
--- a/examples/pup/sensor_infrared/basics.py
+++ b/examples/pup/sensor_infrared/basics.py
@@ -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.
diff --git a/examples/pup/sensor_tilt/basics.py b/examples/pup/sensor_tilt/basics.py
index 6b1f6c7..58fab07 100644
--- a/examples/pup/sensor_tilt/basics.py
+++ b/examples/pup/sensor_tilt/basics.py
@@ -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.
diff --git a/examples/pup/sensor_ultrasonic/basics.py b/examples/pup/sensor_ultrasonic/basics.py
index 9dd4a9e..0c57200 100644
--- a/examples/pup/sensor_ultrasonic/basics.py
+++ b/examples/pup/sensor_ultrasonic/basics.py
@@ -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.
diff --git a/examples/pup/sensor_ultrasonic/math.py b/examples/pup/sensor_ultrasonic/math.py
index 1791077..baeacf3 100644
--- a/examples/pup/sensor_ultrasonic/math.py
+++ b/examples/pup/sensor_ultrasonic/math.py
@@ -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.
diff --git a/src/pybricks/hubs.py b/src/pybricks/hubs.py
index ff83c19..a1db81e 100644
--- a/src/pybricks/hubs.py
+++ b/src/pybricks/hubs.py
@@ -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:
diff --git a/src/pybricks/messaging.py b/src/pybricks/messaging.py
index ff70fde..ea717ba 100644
--- a/src/pybricks/messaging.py
+++ b/src/pybricks/messaging.py
@@ -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)
diff --git a/src/pybricks/parameters.py b/src/pybricks/parameters.py
index 25d4930..9048230 100644
--- a/src/pybricks/parameters.py
+++ b/src/pybricks/parameters.py
@@ -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)
diff --git a/src/pybricks/pupdevices.py b/src/pybricks/pupdevices.py
index c7f7ab3..00f17a5 100644
--- a/src/pybricks/pupdevices.py
+++ b/src/pybricks/pupdevices.py
@@ -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:
diff --git a/src/pybricks/tools.py b/src/pybricks/tools.py
index acdd41e..4f5f1c1 100644
--- a/src/pybricks/tools.py
+++ b/src/pybricks/tools.py
@@ -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."""
diff --git a/src/ubuiltins/__init__.py b/src/ubuiltins/__init__.py
index 0c85e3b..be66f54 100644
--- a/src/ubuiltins/__init__.py
+++ b/src/ubuiltins/__init__.py
@@ -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.
"""
diff --git a/src/uerrno/__init__.py b/src/uerrno/__init__.py
index 2b6f122..e9d7172 100644
--- a/src/uerrno/__init__.py
+++ b/src/uerrno/__init__.py
@@ -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.
"""
diff --git a/src/uio/__init__.py b/src/uio/__init__.py
index 04298e8..0460299 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 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)
diff --git a/src/ujson/__init__.py b/src/ujson/__init__.py
index 659044a..e69cb2f 100644
--- a/src/ujson/__init__.py
+++ b/src/ujson/__init__.py
@@ -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=(", ", ": "))
diff --git a/src/umath/__init__.py b/src/umath/__init__.py
index 7bddfea..64de4c3 100644
--- a/src/umath/__init__.py
+++ b/src/umath/__init__.py
@@ -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
diff --git a/src/urandom/__init__.py b/src/urandom/__init__.py
index f7cff03..cfb081e 100644
--- a/src/urandom/__init__.py
+++ b/src/urandom/__init__.py
@@ -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)
diff --git a/src/uselect/__init__.py b/src/uselect/__init__.py
index 1f6200b..fdf5dca 100644
--- a/src/uselect/__init__.py
+++ b/src/uselect/__init__.py
@@ -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]]
diff --git a/src/ustruct/__init__.py b/src/ustruct/__init__.py
index 23b15c1..3c1078f 100644
--- a/src/ustruct/__init__.py
+++ b/src/ustruct/__init__.py
@@ -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
diff --git a/src/usys/__init__.py b/src/usys/__init__.py
index f8b8b81..3856c0a 100644
--- a/src/usys/__init__.py
+++ b/src/usys/__init__.py
@@ -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."""