1313import abc
1414import struct
1515from enum import IntEnum
16- from typing import Any , Dict , List , NamedTuple , Tuple , Type , Union , overload
16+ from typing import Any , NamedTuple , Union , overload
1717
1818from pybricksdev .ble .lwp3 .bytecodes import (
1919 MAX_NAME_SIZE ,
@@ -861,7 +861,7 @@ def __repr__(self) -> str:
861861
862862
863863class PortFormatSetupComboMessage (AbstractPortFormatSetupComboMessage ):
864- def __init__ (self , port : PortID , modes_and_datasets : List [ Tuple [int , int ]]) -> None :
864+ def __init__ (self , port : PortID , modes_and_datasets : list [ tuple [int , int ]]) -> None :
865865 super ().__init__ (
866866 5 + len (modes_and_datasets ), port , PortInfoFormatSetupCommand .SET
867867 )
@@ -870,7 +870,7 @@ def __init__(self, port: PortID, modes_and_datasets: List[Tuple[int, int]]) -> N
870870 self ._data [i ] = ((mode & 0xF ) << 4 ) | (dataset & 0xF )
871871
872872 @property
873- def modes_and_datasets (self ) -> List [ Tuple [int , int ]]:
873+ def modes_and_datasets (self ) -> list [ tuple [int , int ]]:
874874 return [(x >> 4 , x & 0xF ) for x in self ._data [5 :]]
875875
876876 def __repr__ (self ) -> str :
@@ -923,8 +923,8 @@ def __init__(
923923 port : PortID ,
924924 capabilities : ModeCapabilities ,
925925 num_modes : int ,
926- input_modes : List [int ],
927- output_modes : List [int ],
926+ input_modes : list [int ],
927+ output_modes : list [int ],
928928 ) -> None :
929929 super ().__init__ (11 , port , InfoKind .MODE_INFO )
930930
@@ -955,12 +955,12 @@ def num_modes(self) -> int:
955955 return self ._data [6 ]
956956
957957 @property
958- def input_modes (self ) -> List [int ]:
958+ def input_modes (self ) -> list [int ]:
959959 (flags ,) = struct .unpack_from ("<H" , self ._data , 7 )
960960 return [n for n in range (16 ) if flags & (1 << n )]
961961
962962 @property
963- def output_modes (self ) -> List [int ]:
963+ def output_modes (self ) -> list [int ]:
964964 (flags ,) = struct .unpack_from ("<H" , self ._data , 9 )
965965 return [n for n in range (16 ) if flags & (1 << n )]
966966
@@ -972,7 +972,7 @@ class PortInfoCombosMessage(AbstractPortInfoMessage):
972972 def __init__ (
973973 self ,
974974 port : PortID ,
975- combos : List [ List [int ]],
975+ combos : list [ list [int ]],
976976 ) -> None :
977977 super ().__init__ (5 + len (combos ) * 2 , port , InfoKind .COMBOS )
978978
@@ -988,7 +988,7 @@ def __init__(
988988 struct .pack_into (f"<{ len (flags )} H" , self ._data , 5 , * flags )
989989
990990 @property
991- def combos (self ) -> List [ List [int ]]:
991+ def combos (self ) -> list [ list [int ]]:
992992 count = (len (self ._data ) - 5 ) // 2
993993 return [
994994 [m for m in range (16 ) if flags & (1 << m )]
@@ -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 [Union [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 : Union [int , float ]
12361236 ) -> None :
12371237 super ().__init__ (6 + struct .calcsize (fmt ), MessageKind .PORT_VALUE_COMBO )
12381238
@@ -1249,11 +1249,11 @@ def port(self) -> PortID:
12491249 return PortID (self ._data [3 ])
12501250
12511251 @property
1252- def modes (self ) -> List [int ]:
1252+ 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 [Union [int , float ], ...]:
12571257 return struct .unpack_from (fmt , self ._data , 6 )
12581258
12591259 def __repr__ (self ) -> str :
@@ -1294,7 +1294,7 @@ def __init__(
12941294 port : PortID ,
12951295 combo : int ,
12961296 multi_update : bool ,
1297- modes_and_datasets : List [int ],
1297+ modes_and_datasets : list [int ],
12981298 ) -> None :
12991299 super ().__init__ (7 , MessageKind .PORT_INPUT_FMT_COMBO )
13001300
@@ -1321,7 +1321,7 @@ def multi_update(self) -> bool:
13211321 return bool (self ._data [4 ] & 0x80 )
13221322
13231323 @property
1324- def modes_and_datasets (self ) -> List [int ]:
1324+ def modes_and_datasets (self ) -> list [int ]:
13251325 (flags ,) = struct .unpack_from ("<H" , self ._data , 5 )
13261326 return [m for m in range (16 ) if flags & (1 << m )]
13271327
@@ -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 [Union [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 : Union [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