3333from random import randint
3434
3535try :
36- from typing import List , Tuple , Union
36+ from typing import List , Optional , Tuple , Union
3737except ImportError :
3838 pass
3939
@@ -172,11 +172,11 @@ def __init__(
172172 self ,
173173 * ,
174174 broker : str ,
175- port : Union [int , None ] = None ,
176- username : Union [str , None ] = None ,
177- password : Union [str , None ] = None ,
178- client_id : Union [str , None ] = None ,
179- is_ssl : Union [bool , None ] = None ,
175+ port : Optional [int ] = None ,
176+ username : Optional [str ] = None ,
177+ password : Optional [str ] = None ,
178+ client_id : Optional [str ] = None ,
179+ is_ssl : Optional [bool ] = None ,
180180 keep_alive : int = 60 ,
181181 recv_timeout : int = 10 ,
182182 socket_pool = None ,
@@ -366,8 +366,8 @@ def mqtt_msg(self, msg_size: int) -> None:
366366
367367 def will_set (
368368 self ,
369- topic : Union [str , None ] = None ,
370- payload : Union [int , float , str , None ] = None ,
369+ topic : Optional [str ] = None ,
370+ payload : Optional [int , float , str ] = None ,
371371 qos : int = 0 ,
372372 retain : bool = False ,
373373 ) -> None :
@@ -445,7 +445,7 @@ def _handle_on_message(self, client, topic: str, message: str):
445445 if not matched and self .on_message : # regular on_message
446446 self .on_message (client , topic , message )
447447
448- def username_pw_set (self , username : str , password : Union [str , None ] = None ) -> None :
448+ def username_pw_set (self , username : str , password : Optional [str ] = None ) -> None :
449449 """Set client's username and an optional password.
450450
451451 :param str username: Username to use with your MQTT broker.
@@ -461,9 +461,9 @@ def username_pw_set(self, username: str, password: Union[str, None] = None) -> N
461461 def connect (
462462 self ,
463463 clean_session : bool = True ,
464- host : Union [str , None ] = None ,
465- port : Union [int , None ] = None ,
466- keep_alive : Union [int , None ] = None ,
464+ host : Optional [str ] = None ,
465+ port : Optional [int ] = None ,
466+ keep_alive : Optional [int ] = None ,
467467 ) -> int :
468468 """Initiates connection with the MQTT Broker. Will perform exponential back-off
469469 on connect failures.
@@ -523,9 +523,9 @@ def connect(
523523 def _connect (
524524 self ,
525525 clean_session : bool = True ,
526- host : Union [str , None ] = None ,
527- port : Union [int , None ] = None ,
528- keep_alive : Union [int , None ] = None ,
526+ host : Optional [str ] = None ,
527+ port : Optional [int ] = None ,
528+ keep_alive : Optional [int ] = None ,
529529 ) -> int :
530530 """Initiates connection with the MQTT Broker.
531531
@@ -953,7 +953,7 @@ def reconnect(self, resub_topics: bool = True) -> int:
953953
954954 return ret
955955
956- def loop (self , timeout : float = 0 ) -> Union [list [int ], None ]:
956+ def loop (self , timeout : float = 0 ) -> Optional [list [int ]]:
957957 # pylint: disable = too-many-return-statements
958958 """Non-blocking message loop. Use this method to
959959 check incoming subscription messages.
@@ -993,7 +993,7 @@ def loop(self, timeout: float = 0) -> Union[list[int], None]:
993993
994994 return rcs if rcs else None
995995
996- def _wait_for_msg (self , timeout : float = 0.1 ) -> Union [int , None ]:
996+ def _wait_for_msg (self , timeout : float = 0.1 ) -> Optional [int ]:
997997 # pylint: disable = too-many-return-statements
998998
999999 """Reads and processes network events.
0 commit comments