From e20879189f8c755d87715caa63d9aed26a254763 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 7 Jan 2022 15:13:54 +0100 Subject: [PATCH] style(core): remove old-style annotations (Set, Tuple, Union) --- core/src/apps/bitcoin/common.py | 3 +- core/src/apps/bitcoin/keychain.py | 22 ++++++------- core/src/apps/bitcoin/sign_tx/__init__.py | 18 +++++------ core/src/apps/cardano/auxiliary_data.py | 5 ++- core/src/apps/cardano/seed.py | 14 ++++----- core/src/apps/cardano/sign_tx.py | 4 +-- core/src/apps/common/cbor.py | 4 +-- core/src/apps/common/writers.py | 3 +- core/src/apps/ethereum/keychain.py | 21 ++++++------- core/src/apps/ethereum/layout.py | 4 +-- core/src/apps/ethereum/sign_tx.py | 6 ++-- core/src/apps/ethereum/sign_tx_eip1559.py | 6 ++-- .../management/recovery_device/recover.py | 3 +- core/src/apps/stellar/consts.py | 31 +++++++++---------- core/src/apps/tezos/sign_tx.py | 8 ++--- core/src/trezor/crypto/bech32.py | 6 ++-- core/src/trezor/crypto/rlp.py | 5 ++- core/src/trezor/crypto/slip39.py | 4 +-- core/src/trezor/ui/components/common/text.py | 4 +-- core/src/trezor/ui/components/tt/button.py | 4 +-- core/src/trezor/ui/components/tt/checklist.py | 4 +-- core/src/trezor/ui/layouts/common.py | 6 ++-- core/src/trezor/ui/layouts/t1.py | 4 +-- core/src/trezor/utils.py | 12 +++---- 24 files changed, 92 insertions(+), 109 deletions(-) diff --git a/core/src/apps/bitcoin/common.py b/core/src/apps/bitcoin/common.py index 472d7b782a..e6b8b86d00 100644 --- a/core/src/apps/bitcoin/common.py +++ b/core/src/apps/bitcoin/common.py @@ -9,7 +9,6 @@ from trezor.enums import InputScriptType, OutputScriptType from trezor.utils import HashWriter, ensure if TYPE_CHECKING: - from typing import Tuple from enum import IntEnum from apps.common.coininfo import CoinInfo from trezor.messages import TxInput @@ -128,7 +127,7 @@ def encode_bech32_address(prefix: str, witver: int, script: bytes) -> str: return address -def decode_bech32_address(prefix: str, address: str) -> Tuple[int, bytes]: +def decode_bech32_address(prefix: str, address: str) -> tuple[int, bytes]: witver, raw = bech32.decode(prefix, address) if witver not in _BECH32_WITVERS: raise wire.ProcessError("Invalid address witness program") diff --git a/core/src/apps/bitcoin/keychain.py b/core/src/apps/bitcoin/keychain.py index f2f90be2f4..6d9eb6ff66 100644 --- a/core/src/apps/bitcoin/keychain.py +++ b/core/src/apps/bitcoin/keychain.py @@ -13,7 +13,7 @@ from . import authorization from .common import BITCOIN_NAMES if TYPE_CHECKING: - from typing import Awaitable, Callable, Iterable, TypeVar, Union + from typing import Awaitable, Callable, Iterable, TypeVar from typing_extensions import Protocol from trezor.protobuf import MessageType @@ -32,16 +32,16 @@ if TYPE_CHECKING: from apps.common.keychain import Keychain, MsgOut, Handler from apps.common.paths import Bip32Path - BitcoinMessage = Union[ - AuthorizeCoinJoin, - GetAddress, - GetOwnershipId, - GetOwnershipProof, - GetPublicKey, - SignMessage, - SignTx, - VerifyMessage, - ] + BitcoinMessage = ( + AuthorizeCoinJoin + | GetAddress + | GetOwnershipId + | GetOwnershipProof + | GetPublicKey + | SignMessage + | SignTx + | VerifyMessage + ) class MsgWithAddressScriptType(Protocol): address_n: Bip32Path diff --git a/core/src/apps/bitcoin/sign_tx/__init__.py b/core/src/apps/bitcoin/sign_tx/__init__.py index b198cfcb8c..5a429f137e 100644 --- a/core/src/apps/bitcoin/sign_tx/__init__.py +++ b/core/src/apps/bitcoin/sign_tx/__init__.py @@ -12,7 +12,7 @@ if not utils.BITCOIN_ONLY: from . import bitcoinlike, decred, zcash if TYPE_CHECKING: - from typing import Protocol, Union + from typing import Protocol from trezor.messages import ( SignTx, @@ -29,14 +29,14 @@ if TYPE_CHECKING: from ..authorization import CoinJoinAuthorization - TxAckType = Union[ - TxAckInput, - TxAckOutput, - TxAckPrevMeta, - TxAckPrevInput, - TxAckPrevOutput, - TxAckPrevExtraData, - ] + TxAckType = ( + TxAckInput + | TxAckOutput + | TxAckPrevMeta + | TxAckPrevInput + | TxAckPrevOutput + | TxAckPrevExtraData + ) class SignerClass(Protocol): def __init__( # pylint: disable=super-init-not-called diff --git a/core/src/apps/cardano/auxiliary_data.py b/core/src/apps/cardano/auxiliary_data.py index e16b66bbee..0fac00f4b3 100644 --- a/core/src/apps/cardano/auxiliary_data.py +++ b/core/src/apps/cardano/auxiliary_data.py @@ -19,7 +19,6 @@ from .helpers.utils import derive_public_key from .layout import confirm_catalyst_registration, show_auxiliary_data_hash if TYPE_CHECKING: - from typing import Union from trezor import wire from trezor.messages import ( @@ -27,11 +26,11 @@ if TYPE_CHECKING: CardanoTxAuxiliaryData, ) - CatalystRegistrationPayload = dict[int, Union[bytes, int]] + CatalystRegistrationPayload = dict[int, bytes | int] SignedCatalystRegistrationPayload = tuple[CatalystRegistrationPayload, bytes] CatalystRegistrationSignature = dict[int, bytes] CatalystRegistration = dict[ - int, Union[CatalystRegistrationPayload, CatalystRegistrationSignature] + int, CatalystRegistrationPayload | CatalystRegistrationSignature ] from . import seed diff --git a/core/src/apps/cardano/seed.py b/core/src/apps/cardano/seed.py index f5b845ef62..852e67db22 100644 --- a/core/src/apps/cardano/seed.py +++ b/core/src/apps/cardano/seed.py @@ -11,7 +11,7 @@ from apps.common.seed import derive_and_store_roots, get_seed from .helpers import paths if TYPE_CHECKING: - from typing import Callable, Awaitable, TypeVar, Union + from typing import Callable, Awaitable, TypeVar from apps.common.paths import Bip32Path from apps.common.keychain import MsgOut, Handler @@ -23,12 +23,12 @@ if TYPE_CHECKING: CardanoSignTxInit, ) - CardanoMessages = Union[ - CardanoGetAddress, - CardanoGetPublicKey, - CardanoGetNativeScriptHash, - CardanoSignTxInit, - ] + CardanoMessages = ( + CardanoGetAddress + | CardanoGetPublicKey + | CardanoGetNativeScriptHash + | CardanoSignTxInit + ) MsgIn = TypeVar("MsgIn", bound=CardanoMessages) HandlerWithKeychain = Callable[[wire.Context, MsgIn, "Keychain"], Awaitable[MsgOut]] diff --git a/core/src/apps/cardano/sign_tx.py b/core/src/apps/cardano/sign_tx.py index b561e35a82..1c7445217f 100644 --- a/core/src/apps/cardano/sign_tx.py +++ b/core/src/apps/cardano/sign_tx.py @@ -107,10 +107,10 @@ from .layout import ( from .seed import is_byron_path, is_multisig_path, is_shelley_path if TYPE_CHECKING: - from typing import Any, Union + from typing import Any from apps.common.paths import PathSchema - CardanoTxResponseType = Union[CardanoTxItemAck, CardanoTxWitnessResponse] + CardanoTxResponseType = CardanoTxItemAck | CardanoTxWitnessResponse MINTING_POLICY_ID_LENGTH = 28 MAX_ASSET_NAME_LENGTH = 32 diff --git a/core/src/apps/common/cbor.py b/core/src/apps/common/cbor.py index 78d3d84c2e..81614f7f6c 100644 --- a/core/src/apps/common/cbor.py +++ b/core/src/apps/common/cbor.py @@ -11,12 +11,12 @@ from trezor import log, utils from . import readers if TYPE_CHECKING: - from typing import Any, Generic, Iterator, Tuple, TypeVar, Union + from typing import Any, Generic, Iterator, TypeVar K = TypeVar("K") V = TypeVar("V") Value = Any - CborSequence = Union[list[Value], Tuple[Value, ...]] + CborSequence = list[Value] | tuple[Value, ...] else: # typechecker cheat: Generic[K, V] will be `object` which is a valid parent type Generic = {(0, 0): object} diff --git a/core/src/apps/common/writers.py b/core/src/apps/common/writers.py index 309d934b19..b1984a58f3 100644 --- a/core/src/apps/common/writers.py +++ b/core/src/apps/common/writers.py @@ -3,7 +3,6 @@ from typing import TYPE_CHECKING from trezor.utils import ensure if TYPE_CHECKING: - from typing import Union from trezor.utils import Writer @@ -71,7 +70,7 @@ def write_uint64_be(w: Writer, n: int) -> int: return 8 -def write_bytes_unchecked(w: Writer, b: Union[bytes, memoryview]) -> int: +def write_bytes_unchecked(w: Writer, b: bytes | memoryview) -> int: w.extend(b) return len(b) diff --git a/core/src/apps/ethereum/keychain.py b/core/src/apps/ethereum/keychain.py index 137a81a6d5..6ae6601ff0 100644 --- a/core/src/apps/ethereum/keychain.py +++ b/core/src/apps/ethereum/keychain.py @@ -8,7 +8,7 @@ from apps.common.keychain import get_keychain from . import CURVE, networks if TYPE_CHECKING: - from typing import Callable, Iterable, TypeVar, Union + from typing import Callable, Iterable, TypeVar from trezor.messages import ( EthereumGetAddress, @@ -21,19 +21,16 @@ if TYPE_CHECKING: from apps.common.keychain import MsgOut, Handler, HandlerWithKeychain - EthereumMessages = Union[ - EthereumGetAddress, - EthereumGetPublicKey, - EthereumSignTx, - EthereumSignMessage, - EthereumSignTypedData, - ] + EthereumMessages = ( + EthereumGetAddress + | EthereumGetPublicKey + | EthereumSignTx + | EthereumSignMessage + | EthereumSignTypedData + ) MsgIn = TypeVar("MsgIn", bound=EthereumMessages) - EthereumSignTxAny = Union[ - EthereumSignTx, - EthereumSignTxEIP1559, - ] + EthereumSignTxAny = EthereumSignTx | EthereumSignTxEIP1559 MsgInChainId = TypeVar("MsgInChainId", bound=EthereumSignTxAny) diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index 6bcf80f148..3480c36ec8 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -19,7 +19,7 @@ from . import networks, tokens from .helpers import address_from_bytes, decode_typed_data, get_type_name if TYPE_CHECKING: - from typing import Awaitable, Iterable, Optional + from typing import Awaitable, Iterable from trezor.wire import Context @@ -185,7 +185,7 @@ async def confirm_typed_value( value: bytes, parent_objects: list[str], field: EthereumFieldType, - array_index: Optional[int] = None, + array_index: int | None = None, ) -> None: type_name = get_type_name(field) diff --git a/core/src/apps/ethereum/sign_tx.py b/core/src/apps/ethereum/sign_tx.py index af002920b1..f40a334849 100644 --- a/core/src/apps/ethereum/sign_tx.py +++ b/core/src/apps/ethereum/sign_tx.py @@ -20,8 +20,6 @@ from .layout import ( ) if TYPE_CHECKING: - from typing import Tuple - from apps.common.keychain import Keychain from .keychain import EthereumSignTxAny @@ -97,7 +95,7 @@ async def sign_tx( async def handle_erc20( ctx: wire.Context, msg: EthereumSignTxAny -) -> Tuple[tokens.TokenInfo | None, bytes, bytes, int]: +) -> tuple[tokens.TokenInfo | None, bytes, bytes, int]: token = None address_bytes = recipient = bytes_from_address(msg.to) value = int.from_bytes(msg.value, "big") @@ -124,7 +122,7 @@ def get_total_length(msg: EthereumSignTx, data_total: int) -> int: if msg.tx_type is not None: length += rlp.length(msg.tx_type) - fields: Tuple[rlp.RLPItem, ...] = ( + fields: tuple[rlp.RLPItem, ...] = ( msg.nonce, msg.gas_price, msg.gas_limit, diff --git a/core/src/apps/ethereum/sign_tx_eip1559.py b/core/src/apps/ethereum/sign_tx_eip1559.py index 71e4e84db9..060b768f7d 100644 --- a/core/src/apps/ethereum/sign_tx_eip1559.py +++ b/core/src/apps/ethereum/sign_tx_eip1559.py @@ -19,8 +19,6 @@ from .layout import ( from .sign_tx import check_common_fields, handle_erc20, send_request_chunk if TYPE_CHECKING: - from typing import Tuple - from trezor.messages import EthereumSignTxEIP1559 from apps.common.keychain import Keychain @@ -90,7 +88,7 @@ async def sign_tx_eip1559( rlp.write_header(sha, total_length, rlp.LIST_HEADER_BYTE) - fields: Tuple[rlp.RLPItem, ...] = ( + fields: tuple[rlp.RLPItem, ...] = ( msg.chain_id, msg.nonce, msg.max_priority_fee, @@ -124,7 +122,7 @@ async def sign_tx_eip1559( def get_total_length(msg: EthereumSignTxEIP1559, data_total: int) -> int: length = 0 - fields: Tuple[rlp.RLPItem, ...] = ( + fields: tuple[rlp.RLPItem, ...] = ( msg.nonce, msg.gas_limit, bytes_from_address(msg.to), diff --git a/core/src/apps/management/recovery_device/recover.py b/core/src/apps/management/recovery_device/recover.py index 22398b4592..e44b1b5357 100644 --- a/core/src/apps/management/recovery_device/recover.py +++ b/core/src/apps/management/recovery_device/recover.py @@ -9,7 +9,6 @@ from .. import backup_types if TYPE_CHECKING: from trezor.enums import BackupType - from typing import Union class RecoveryAborted(Exception): @@ -94,7 +93,7 @@ def process_slip39(words: str) -> tuple[bytes | None, slip39.Share]: if TYPE_CHECKING: - Slip39State = Union[tuple[int, BackupType], tuple[None, None]] + Slip39State = tuple[int, BackupType] | tuple[None, None] def load_slip39_state() -> Slip39State: diff --git a/core/src/apps/stellar/consts.py b/core/src/apps/stellar/consts.py index 786b864f56..89b5d279c1 100644 --- a/core/src/apps/stellar/consts.py +++ b/core/src/apps/stellar/consts.py @@ -4,7 +4,6 @@ from typing import TYPE_CHECKING from trezor.enums import MessageType if TYPE_CHECKING: - from typing import Union from trezor import protobuf from trezor.messages import ( @@ -23,21 +22,21 @@ if TYPE_CHECKING: StellarSetOptionsOp, ) - StellarMessageType = Union[ - StellarAccountMergeOp, - StellarAllowTrustOp, - StellarBumpSequenceOp, - StellarChangeTrustOp, - StellarCreateAccountOp, - StellarCreatePassiveSellOfferOp, - StellarManageDataOp, - StellarManageBuyOfferOp, - StellarManageSellOfferOp, - StellarPathPaymentStrictReceiveOp, - StellarPathPaymentStrictSendOp, - StellarPaymentOp, - StellarSetOptionsOp, - ] + StellarMessageType = ( + StellarAccountMergeOp + | StellarAllowTrustOp + | StellarBumpSequenceOp + | StellarChangeTrustOp + | StellarCreateAccountOp + | StellarCreatePassiveSellOfferOp + | StellarManageDataOp + | StellarManageBuyOfferOp + | StellarManageSellOfferOp + | StellarPathPaymentStrictReceiveOp + | StellarPathPaymentStrictSendOp + | StellarPaymentOp + | StellarSetOptionsOp + ) TX_TYPE = b"\x00\x00\x00\x02" diff --git a/core/src/apps/tezos/sign_tx.py b/core/src/apps/tezos/sign_tx.py index d7493b4fe0..aa39ff03bd 100644 --- a/core/src/apps/tezos/sign_tx.py +++ b/core/src/apps/tezos/sign_tx.py @@ -18,7 +18,6 @@ from apps.common.writers import ( from . import CURVE, PATTERNS, SLIP44_ID, helpers, layout if TYPE_CHECKING: - from typing import Union from apps.common.keychain import Keychain from trezor.wire import Context from trezor.messages import ( @@ -249,9 +248,10 @@ def _get_operation_bytes(w: Writer, msg: TezosSignTx) -> None: def _encode_common( w: Writer, - operation: Union[ - TezosDelegationOp, TezosOriginationOp, TezosTransactionOp, TezosRevealOp - ], + operation: TezosDelegationOp + | TezosOriginationOp + | TezosTransactionOp + | TezosRevealOp, str_operation: str, ) -> None: operation_tags = { diff --git a/core/src/trezor/crypto/bech32.py b/core/src/trezor/crypto/bech32.py index 35c1d198ab..f41e7cd921 100644 --- a/core/src/trezor/crypto/bech32.py +++ b/core/src/trezor/crypto/bech32.py @@ -24,15 +24,15 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: from enum import IntEnum - from typing import Sequence, Union, TypeVar + from typing import Sequence, TypeVar A = TypeVar("A") B = TypeVar("B") C = TypeVar("C") # usage: OptionalTuple[int, list[int]] is either (None, None) or (someint, somelist) # but not (None, somelist) - OptionalTuple2 = Union[tuple[None, None], tuple[A, B]] - OptionalTuple3 = Union[tuple[None, None, None], tuple[A, B, C]] + OptionalTuple2 = tuple[None, None] | tuple[A, B] + OptionalTuple3 = tuple[None, None, None] | tuple[A, B, C] else: IntEnum = object diff --git a/core/src/trezor/crypto/rlp.py b/core/src/trezor/crypto/rlp.py index 9f3d9c3856..1660ff459f 100644 --- a/core/src/trezor/crypto/rlp.py +++ b/core/src/trezor/crypto/rlp.py @@ -2,7 +2,6 @@ from micropython import const from typing import TYPE_CHECKING if TYPE_CHECKING: - from typing import Union from trezor.utils import Writer # The intention below is basically: @@ -13,8 +12,8 @@ if TYPE_CHECKING: # a generic `Sequence` (because we do isinstance checks for a list). We are however # only reading from the list and passing into things that consume a RLPItem. Hence # we have to enumerate single-type lists as well as the universal list[RLPItem]. - RLPList = Union[list[int], list[bytes], list["RLPItem"]] - RLPItem = Union[RLPList, bytes, int] + RLPList = list[int] | list[bytes] | list["RLPItem"] + RLPItem = RLPList | bytes | int STRING_HEADER_BYTE = const(0x80) diff --git a/core/src/trezor/crypto/slip39.py b/core/src/trezor/crypto/slip39.py index 257ca71698..f6faa106d1 100644 --- a/core/src/trezor/crypto/slip39.py +++ b/core/src/trezor/crypto/slip39.py @@ -38,9 +38,9 @@ from trezor.crypto import hmac, pbkdf2, random from trezor.errors import MnemonicError if TYPE_CHECKING: - from typing import Callable, Iterable, Tuple + from typing import Callable, Iterable - Indices = Tuple[int, ...] + Indices = tuple[int, ...] MnemonicGroups = dict[int, tuple[int, set[tuple[int, bytes]]]] diff --git a/core/src/trezor/ui/components/common/text.py b/core/src/trezor/ui/components/common/text.py index c32041ce38..033badf90e 100644 --- a/core/src/trezor/ui/components/common/text.py +++ b/core/src/trezor/ui/components/common/text.py @@ -17,9 +17,9 @@ LINE_WIDTH = ui.WIDTH - TEXT_MARGIN_LEFT LINE_WIDTH_PAGINATED = LINE_WIDTH - PAGINATION_MARGIN_RIGHT if TYPE_CHECKING: - from typing import Any, Sequence, Union + from typing import Any, Sequence - TextContent = Union[str, int] + TextContent = str | int # needs to be different from all colors and font ids BR = const(-256) diff --git a/core/src/trezor/ui/components/tt/button.py b/core/src/trezor/ui/components/tt/button.py index 3ae7b195db..c82f614c1a 100644 --- a/core/src/trezor/ui/components/tt/button.py +++ b/core/src/trezor/ui/components/tt/button.py @@ -5,9 +5,7 @@ from trezor import ui from trezor.ui import display, in_area if TYPE_CHECKING: - from typing import Union - - ButtonContent = Union[str, bytes] + ButtonContent = str | bytes ButtonStyleType = type["ButtonDefault"] ButtonStyleStateType = type["ButtonDefault.normal"] diff --git a/core/src/trezor/ui/components/tt/checklist.py b/core/src/trezor/ui/components/tt/checklist.py index dc82318fd3..de1a2167c3 100644 --- a/core/src/trezor/ui/components/tt/checklist.py +++ b/core/src/trezor/ui/components/tt/checklist.py @@ -6,9 +6,9 @@ from trezor import res, ui from ...constants import TEXT_HEADER_HEIGHT, TEXT_LINE_HEIGHT if TYPE_CHECKING: - from typing import Iterable, Union + from typing import Iterable - ChecklistItem = Union[str, Iterable[str]] + ChecklistItem = str | Iterable[str] _CHECKLIST_MAX_LINES = const(5) _CHECKLIST_OFFSET_X = const(24) diff --git a/core/src/trezor/ui/layouts/common.py b/core/src/trezor/ui/layouts/common.py index 5e06f60d75..9afc819945 100644 --- a/core/src/trezor/ui/layouts/common.py +++ b/core/src/trezor/ui/layouts/common.py @@ -5,11 +5,11 @@ from trezor.enums import ButtonRequestType from trezor.messages import ButtonAck, ButtonRequest if TYPE_CHECKING: - from typing import Any, Awaitable, Optional, Tuple, Union + from typing import Any, Awaitable LayoutType = Awaitable[Any] - PropertyType = Tuple[Optional[str], Union[str, bytes, None]] - ExceptionType = Union[BaseException, type[BaseException]] + PropertyType = tuple[str | None, str | bytes | None] + ExceptionType = BaseException | type[BaseException] if __debug__: diff --git a/core/src/trezor/ui/layouts/t1.py b/core/src/trezor/ui/layouts/t1.py index d102a6b805..68bb2cae21 100644 --- a/core/src/trezor/ui/layouts/t1.py +++ b/core/src/trezor/ui/layouts/t1.py @@ -8,9 +8,9 @@ from trezorui2 import layout_new_confirm_action from .common import interact if TYPE_CHECKING: - from typing import NoReturn, Type, Union + from typing import NoReturn, Type - ExceptionType = Union[BaseException, Type[BaseException]] + ExceptionType = BaseException | Type[BaseException] async def confirm_action( diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index 0e9b08ecf9..df091bdde3 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -30,20 +30,18 @@ if TYPE_CHECKING: Any, Iterator, Protocol, - Union, TypeVar, Sequence, - Set, ) from trezor.protobuf import MessageType -def unimport_begin() -> Set[str]: +def unimport_begin() -> set[str]: return set(sys.modules) -def unimport_end(mods: Set[str], collect: bool = True) -> None: +def unimport_end(mods: set[str], collect: bool = True) -> None: # static check that the size of sys.modules never grows above value of # MICROPY_LOADED_MODULES_DICT_SIZE, so that the sys.modules dict is never # reallocated at run-time @@ -72,7 +70,7 @@ def unimport_end(mods: Set[str], collect: bool = True) -> None: class unimport: def __init__(self) -> None: - self.mods: Set[str] | None = None + self.mods: set[str] | None = None def __enter__(self) -> None: self.mods = unimport_begin() @@ -186,7 +184,7 @@ class HashWriter: if TYPE_CHECKING: - BufferType = Union[bytearray, memoryview] + BufferType = bytearray | memoryview class BufferWriter: @@ -222,7 +220,7 @@ class BufferWriter: class BufferReader: """Seekable and readable view into a buffer.""" - def __init__(self, buffer: Union[bytes, memoryview]) -> None: + def __init__(self, buffer: bytes | memoryview) -> None: if isinstance(buffer, memoryview): self.buffer = buffer else: