33
33
from random import randint
34
34
35
35
try :
36
- from typing import List , Tuple , Union
36
+ from typing import List , Optional , Tuple , Union
37
37
except ImportError :
38
38
pass
39
39
@@ -172,11 +172,11 @@ def __init__(
172
172
self ,
173
173
* ,
174
174
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 ,
180
180
keep_alive : int = 60 ,
181
181
recv_timeout : int = 10 ,
182
182
socket_pool = None ,
@@ -366,8 +366,8 @@ def mqtt_msg(self, msg_size: int) -> None:
366
366
367
367
def will_set (
368
368
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 ,
371
371
qos : int = 0 ,
372
372
retain : bool = False ,
373
373
) -> None :
@@ -445,7 +445,7 @@ def _handle_on_message(self, client, topic: str, message: str):
445
445
if not matched and self .on_message : # regular on_message
446
446
self .on_message (client , topic , message )
447
447
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 :
449
449
"""Set client's username and an optional password.
450
450
451
451
: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
461
461
def connect (
462
462
self ,
463
463
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 ,
467
467
) -> int :
468
468
"""Initiates connection with the MQTT Broker. Will perform exponential back-off
469
469
on connect failures.
@@ -523,9 +523,9 @@ def connect(
523
523
def _connect (
524
524
self ,
525
525
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 ,
529
529
) -> int :
530
530
"""Initiates connection with the MQTT Broker.
531
531
@@ -953,7 +953,7 @@ def reconnect(self, resub_topics: bool = True) -> int:
953
953
954
954
return ret
955
955
956
- def loop (self , timeout : float = 0 ) -> Union [list [int ], None ]:
956
+ def loop (self , timeout : float = 0 ) -> Optional [list [int ]]:
957
957
# pylint: disable = too-many-return-statements
958
958
"""Non-blocking message loop. Use this method to
959
959
check incoming subscription messages.
@@ -993,7 +993,7 @@ def loop(self, timeout: float = 0) -> Union[list[int], None]:
993
993
994
994
return rcs if rcs else None
995
995
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 ]:
997
997
# pylint: disable = too-many-return-statements
998
998
999
999
"""Reads and processes network events.
0 commit comments