Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions python/qemu/ot/dm/dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from io import SEEK_END
from logging import getLogger
from time import sleep, time as now
from typing import Any, BinaryIO, Optional
from typing import Any, BinaryIO, Optional, Union

from .regs import CSRS, GPRS
from ..bitfield import BitField
Expand Down Expand Up @@ -277,7 +277,7 @@ def resume(self, hart: int = 0) -> None:
self._log.error('Status %s', status)
raise TimeoutError(f'Cannot resume hart {self._hart}')

def read_csr(self, reg: [str | int]) -> int:
def read_csr(self, reg: Union[str, int]) -> int:
"""Read the value of a CSR."""
ireg = self._get_register_index(reg)
btf = self.BITFIELDS['COMMAND']
Expand All @@ -292,7 +292,7 @@ def read_csr(self, reg: [str | int]) -> int:
self._log.info('read %s = %08x', reg, value)
return value

def write_csr(self, reg: [str | int], value: int) -> None:
def write_csr(self, reg: Union[str, int], value: int) -> None:
"""Write a value to a CSR."""
ireg = self._get_register_index(reg)
btf = self.BITFIELDS['COMMAND']
Expand Down Expand Up @@ -497,7 +497,7 @@ def _read_reg(self, reg: str) -> int:
self._log.debug('read 0x%08x', value)
return value

def _get_register_index(self, reg: [str | int]) -> int:
def _get_register_index(self, reg: Union[str, int]) -> int:
if isinstance(reg, str):
# Not supported: FPR, Vector, etc.
ireg = CSRS.get(reg.lower())
Expand Down
6 changes: 3 additions & 3 deletions python/qemu/ot/dm/otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from enum import IntEnum
from logging import getLogger
from time import sleep, time as now
from typing import Optional
from typing import Optional, Union

from .dm import DebugModule
from ..bitfield import BitField
Expand Down Expand Up @@ -166,7 +166,7 @@ def is_wide_granule(cls, partition: OtpPartition, offset: int) -> bool:
return partition.secret or (partition.digest_offset == offset & ~0b111)

def read_partition_item(self, partname: str, itemname: str) \
-> [int | bytes]:
-> Union[int, bytes]:
pname = partname.upper()
try:
part = self._partitions[pname]
Expand Down Expand Up @@ -205,7 +205,7 @@ def read_partition_item(self, partname: str, itemname: str) \
return bytes(buffer)

def write_partition_item(self, partname: str, itemname: str,
value: [int | bytes | bytearray | str]) -> None:
value: Union[int, bytes, bytearray, str]) -> None:
pname = partname.upper()
try:
part = self._partitions[pname]
Expand Down
8 changes: 4 additions & 4 deletions python/qemu/ot/lc_ctrl/lcdmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from binascii import Error as BinasciiError, hexlify, unhexlify
from logging import getLogger
from struct import pack as spack, unpack as sunpack
from typing import NamedTuple
from typing import NamedTuple, Union

from . import LifeCycleError
from ..dtm import DebugTransportModule
Expand Down Expand Up @@ -183,7 +183,7 @@ def transition_token(self) -> bytes:
return token

@transition_token.setter
def transition_token(self, token: [bytes | bytearray | str | None]) -> None:
def transition_token(self, token: Union[bytes, bytearray, str, None]) -> None:
"""Define the transition token as a 16-byte token.

:param token: if None, use an empty zeroed token,
Expand Down Expand Up @@ -216,7 +216,7 @@ def transition_target(self) -> tuple[str, int]:
return starget, target

@transition_target.setter
def transition_target(self, target: [str | int]) -> None:
def transition_target(self, target: Union[str, int]) -> None:
"""Define the transition token as a 16-byte token."""
if isinstance(target, str):
itarget = self._encode_state(target)
Expand All @@ -240,7 +240,7 @@ def otp_vendor_test_status(self) -> int:
return self._read_reg('otp_vendor_test_status')

@property
def lc_state(self) -> [str | int]:
def lc_state(self) -> Union[str, int]:
"""Report the current state."""
istate = self._read_reg('lc_state')
tix = self._check_state(istate)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR: am I misunderstanding or should this type not be Tuple[str, int]?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the original annotation was wrong. Good catch!

Expand Down
6 changes: 3 additions & 3 deletions python/qemu/ot/otp/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from binascii import hexlify, unhexlify, Error as hexerror
from io import BytesIO
from logging import getLogger
from typing import BinaryIO, Optional, TextIO
from typing import BinaryIO, Optional, TextIO, Union

from .lifecycle import OtpLifecycle

Expand All @@ -23,7 +23,7 @@
class OtpPartitionDecoder:
"""Custom partition value decoder."""

def decode(self, category: str, seq: str) -> Optional[str | int]:
def decode(self, category: str, seq: str) -> Optional[Union[str, int]]:
"""Decode a value (if possible)."""
raise NotImplementedError('abstract base class')

Expand Down Expand Up @@ -206,7 +206,7 @@ class OtpLifecycleExtension(OtpLifecycle, OtpPartitionDecoder):
"""Decoder for Lifecyle bytes sequences.
"""

def decode(self, category: str, seq: str) -> Optional[str | int]:
def decode(self, category: str, seq: str) -> Optional[Union[str, int]]:
try:
iseq = hexlify(bytes(reversed(unhexlify(seq)))).decode()
except (ValueError, TypeError, hexerror) as exc:
Expand Down
4 changes: 2 additions & 2 deletions python/qemu/ot/spi/spi_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SHUT_RDWR, timeout as LegacyTimeoutError)
from struct import calcsize as scalc, pack as spack
from time import sleep, time as now
from typing import Optional
from typing import Optional, Union


class SpiDevice:
Expand Down Expand Up @@ -102,7 +102,7 @@ def quit(self) -> None:
self._socket = None

def transmit(self, cmd: Optional[int] = None,
in_payload: Optional[bytes | bytearray | int] = None,
in_payload: Optional[Union[bytes, bytearray, int]] = None,
out_len: int = 0, release: bool = True) -> bytes:
"""SPI data transfer.

Expand Down
4 changes: 2 additions & 2 deletions python/qemu/ot/util/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def format(self, record):
formatter = logging.Formatter(log_fmt, *self._formatter_args)
return formatter.format(record)

def add_logger_colors(self, logname: str, color: Union[int | str]) -> None:
def add_logger_colors(self, logname: str, color: Union[int, str]) -> None:
"""Assign a color to the message of a specific logger."""
if not self._use_ansi:
return
Expand Down Expand Up @@ -190,7 +190,7 @@ def override_xcolors(cls, codes: Sequence[int]) -> None:
cls.XCOLORS = xcolors


def configure_loggers(level: int, *lognames: list[Union[str | int | Color]],
def configure_loggers(level: int, *lognames: list[Union[str, int, Color]],
**kwargs) -> list[logging.Logger]:
"""Configure loggers.

Expand Down
4 changes: 2 additions & 2 deletions python/qemu/ot/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

from io import BytesIO
from sys import stdout
from typing import Any, Iterable, Optional, TextIO
from typing import Any, Iterable, Optional, TextIO, Union
import re

try:
# only available from Python 3.12+
from collections.abc import Buffer
except ImportError:
Buffer = [bytes | bytearray | memoryview]
Buffer = Union[bytes, bytearray, memoryview]


class classproperty(property):
Expand Down
4 changes: 2 additions & 2 deletions scripts/opentitan/flashgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
join as joinpath, normpath)
from struct import calcsize as scalc, pack as spack, unpack as sunpack
from traceback import format_exc
from typing import Any, BinaryIO, NamedTuple, Optional
from typing import Any, BinaryIO, NamedTuple, Optional, Union
import re
import sys

Expand Down Expand Up @@ -216,7 +216,7 @@ def info_part_size(cls) -> int:
return sum(cls.INFOS) * cls.BYTES_PER_PAGE

def read_boot_info(self) -> dict[BootLocation,
dict[str, [int | bytes]]]:
dict[str, Union[int, bytes]]]:
size = self._boot_header_size
fmt = ''.join(self.BOOT_HEADER_FORMAT.values())
boot_entries = {}
Expand Down
4 changes: 2 additions & 2 deletions scripts/opentitan/gdbreplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
timeout as LegacyTimeoutError)
from string import ascii_uppercase
from traceback import format_exc
from typing import BinaryIO, Optional, TextIO
from typing import BinaryIO, Optional, TextIO, Union
import re
import sys

Expand Down Expand Up @@ -461,7 +461,7 @@ def _send(self, payload: str):
self._log.info('Reply: "%s"', payload)
self._send_bytes(payload.encode())

def _send_bytes(self, payload: [bytes | bytearray]):
def _send_bytes(self, payload: Union[bytes, bytearray]):
"""Send a reply to the remote GDB client.

:param payload: the byte sequence to send
Expand Down
Loading