1010from copy import deepcopy
1111from random import randint
1212from threading import Event , Lock
13- from typing import Any , Callable , Collection , Dict , Iterator , List , \
14- NamedTuple , Optional , Set , Tuple , Type , TYPE_CHECKING , Union
13+ from typing import Any , Callable , cast , Collection , Dict , Iterator , \
14+ List , NamedTuple , Optional , Set , Tuple , Type , TYPE_CHECKING , Union
1515from urllib .parse import parse_qsl , urlparse , urlunparse
1616
1717import dateutil .parser
@@ -219,7 +219,7 @@ def conn_url(self) -> Optional[str]:
219219
220220 return None
221221
222- def conn_kwargs (self , auth : Union [Any , Dict [ str , Any ], None ] = None ) -> Dict [str , Any ]:
222+ def conn_kwargs (self , auth : Optional [Any ] = None ) -> Dict [str , Any ]:
223223 """Give keyword arguments used for PostgreSQL connection settings.
224224
225225 :param auth: Authentication properties - can be defined as anything supported by the ``psycopg2`` or
@@ -255,7 +255,7 @@ def conn_kwargs(self, auth: Union[Any, Dict[str, Any], None] = None) -> Dict[str
255255
256256 # apply any remaining authentication parameters
257257 if auth and isinstance (auth , dict ):
258- ret .update ({k : v for k , v in auth .items () if v is not None })
258+ ret .update ({k : v for k , v in cast ( Dict [ str , Any ], auth ) .items () if v is not None })
259259 if 'username' in auth :
260260 ret ['user' ] = ret .pop ('username' )
261261 return ret
@@ -949,28 +949,28 @@ def get_clone_member(self, exclude_name: str) -> Union[Member, Leader, None]:
949949 return candidates [randint (0 , len (candidates ) - 1 )] if candidates else self .leader
950950
951951 @staticmethod
952- def is_physical_slot (value : Union [ Any , Dict [ str , Any ]] ) -> bool :
952+ def is_physical_slot (value : Any ) -> bool :
953953 """Check whether provided configuration is for permanent physical replication slot.
954954
955955 :param value: configuration of the permanent replication slot.
956956
957957 :returns: ``True`` if *value* is a physical replication slot, otherwise ``False``.
958958 """
959959 return not value \
960- or (isinstance (value , dict ) and not Cluster .is_logical_slot (value )
961- and value .get ('type' , 'physical' ) == 'physical' )
960+ or (isinstance (value , dict ) and not Cluster .is_logical_slot (cast ( Dict [ str , Any ], value ) )
961+ and cast ( Dict [ str , Any ], value ) .get ('type' , 'physical' ) == 'physical' )
962962
963963 @staticmethod
964- def is_logical_slot (value : Union [ Any , Dict [ str , Any ]] ) -> bool :
964+ def is_logical_slot (value : Any ) -> bool :
965965 """Check whether provided configuration is for permanent logical replication slot.
966966
967967 :param value: configuration of the permanent replication slot.
968968
969969 :returns: ``True`` if *value* is a logical replication slot, otherwise ``False``.
970970 """
971971 return isinstance (value , dict ) \
972- and value .get ('type' , 'logical' ) == 'logical' \
973- and bool (value .get ('database' ) and value .get ('plugin' ))
972+ and cast ( Dict [ str , Any ], value ) .get ('type' , 'logical' ) == 'logical' \
973+ and bool (cast ( Dict [ str , Any ], value ) .get ('database' ) and cast ( Dict [ str , Any ], value ) .get ('plugin' ))
974974
975975 @property
976976 def __permanent_slots (self ) -> Dict [str , Union [Dict [str , Any ], Any ]]:
@@ -992,7 +992,7 @@ def __permanent_slots(self) -> Dict[str, Union[Dict[str, Any], Any]]:
992992 value ['lsn' ] = lsn
993993 else :
994994 # Don't let anyone set 'lsn' in the global configuration :)
995- value .pop ('lsn' , None )
995+ value .pop ('lsn' , None ) # pyright: ignore [reportUnknownMemberType]
996996 return ret
997997
998998 @property
@@ -1066,8 +1066,9 @@ def _merge_permanent_slots(self, slots: Dict[str, Dict[str, Any]], permanent_slo
10661066 logger .error ("Slot name may only contain lower case letters, numbers, and the underscore chars" )
10671067 continue
10681068
1069- value = deepcopy (value ) if value else {'type' : 'physical' }
1070- if isinstance (value , dict ):
1069+ tmp = deepcopy (value ) if value else {'type' : 'physical' }
1070+ if isinstance (tmp , dict ):
1071+ value = cast (Dict [str , Any ], tmp )
10711072 if 'type' not in value :
10721073 value ['type' ] = 'logical' if value .get ('database' ) and value .get ('plugin' ) else 'physical'
10731074
0 commit comments