1313import abc
1414import struct
1515from enum import IntEnum
16- from typing import Any , NamedTuple , Union , overload
16+ from typing import Any , NamedTuple , overload
1717
1818from pybricksdev .ble .lwp3 .bytecodes import (
1919 MAX_NAME_SIZE ,
@@ -1211,7 +1211,7 @@ def __repr__(self) -> str:
12111211
12121212
12131213class PortValueMessage (AbstractMessage ):
1214- def __init__ (self , port : PortID , fmt : str , * values : Union [ int , float ] ) -> None :
1214+ def __init__ (self , port : PortID , fmt : str , * values : int | float ) -> None :
12151215 super ().__init__ (4 + struct .calcsize (fmt ), MessageKind .PORT_VALUE )
12161216
12171217 self ._data [3 ] = port
@@ -1221,7 +1221,7 @@ def __init__(self, port: PortID, fmt: str, *values: Union[int, float]) -> None:
12211221 def port (self ) -> PortID :
12221222 return PortID (self ._data [3 ])
12231223
1224- def unpack (self , fmt : str ) -> tuple [Union [ int , float ] , ...]:
1224+ def unpack (self , fmt : str ) -> tuple [int | float , ...]:
12251225 return struct .unpack_from (fmt , self ._data , 4 )
12261226
12271227 def __repr__ (self ) -> str :
@@ -1232,7 +1232,7 @@ def __repr__(self) -> str:
12321232
12331233class PortValueComboMessage (AbstractMessage ):
12341234 def __init__ (
1235- self , port : PortID , modes : list [int ], fmt : str , * values : Union [ int , float ]
1235+ self , port : PortID , modes : list [int ], fmt : str , * values : int | float
12361236 ) -> None :
12371237 super ().__init__ (6 + struct .calcsize (fmt ), MessageKind .PORT_VALUE_COMBO )
12381238
@@ -1253,7 +1253,7 @@ def modes(self) -> list[int]:
12531253 (flags ,) = struct .unpack_from ("<H" , self ._data , 4 )
12541254 return [m for m in range (16 ) if flags & (1 << m )]
12551255
1256- def unpack (self , fmt : str ) -> tuple [Union [ int , float ] , ...]:
1256+ def unpack (self , fmt : str ) -> tuple [int | float , ...]:
12571257 return struct .unpack_from (fmt , self ._data , 6 )
12581258
12591259 def __repr__ (self ) -> str :
@@ -1450,7 +1450,7 @@ def __init__(
14501450 end : EndInfo ,
14511451 mode : int ,
14521452 fmt : str ,
1453- * values : Union [ int , float ] ,
1453+ * values : int | float ,
14541454 ) -> None :
14551455 super ().__init__ (
14561456 7 + struct .calcsize (fmt ),
@@ -1467,7 +1467,7 @@ def __init__(
14671467 def mode (self ) -> int :
14681468 return self ._data [6 ]
14691469
1470- def unpack (self , fmt : str ) -> tuple [Union [ int , float ] , ...]:
1470+ def unpack (self , fmt : str ) -> tuple [int | float , ...]:
14711471 return struct .unpack_from (fmt , self ._data , 7 )
14721472
14731473 def __repr__ (self ) -> str :
@@ -1577,7 +1577,7 @@ class _Lookup(NamedTuple):
15771577 index : int
15781578 """The index of the bytecode that determines the type."""
15791579
1580- value : Union [ dict [IntEnum , type [AbstractMessage ]], dict [IntEnum , "_Lookup" ] ]
1580+ value : dict [IntEnum , type [AbstractMessage ]] | dict [IntEnum , "_Lookup" ]
15811581 """
15821582 A dictionary mapping a bytecode to the cooresponding Python type if the type can be determined or
15831583 a dictionary mapping a bytecode to another lookup if more discrimination is required.
0 commit comments