@@ -742,16 +742,16 @@ def __init__(
742
742
** kwargs ,
743
743
}
744
744
745
+ if host is None :
746
+ host = self .HOST
747
+ if isinstance (host , str ):
748
+ host = [host ]
749
+ if port is None :
750
+ port = self .PORT
751
+ if not isinstance (port , int ):
752
+ raise TypeError (f"port must be an instance of int, not { type (port )} " )
745
753
self ._host = host
746
754
self ._port = port
747
- if self ._host is None :
748
- self ._host = self .HOST
749
- if isinstance (self ._host , str ):
750
- self ._host = [self ._host ]
751
- if self ._port is None :
752
- self ._port = self .PORT
753
- if not isinstance (self ._port , int ):
754
- raise TypeError (f"port must be an instance of int, not { type (port )} " )
755
755
756
756
# _pool_class, _monitor_class, and _condition_class are for deep
757
757
# customization of PyMongo, e.g. Motor.
@@ -762,7 +762,7 @@ def __init__(
762
762
# Parse options passed as kwargs.
763
763
keyword_opts = common ._CaseInsensitiveDictionary (kwargs )
764
764
keyword_opts ["document_class" ] = doc_class
765
- self ._resolve_uri_info = {"keyword_opts" : keyword_opts }
765
+ self ._resolve_uri_info : dict [ str , Any ] = {"keyword_opts" : keyword_opts }
766
766
767
767
seeds = set ()
768
768
username = None
@@ -824,6 +824,8 @@ def __init__(
824
824
opts = self ._normalize_and_validate_options (opts , seeds )
825
825
826
826
# Username and password passed as kwargs override user info in URI.
827
+ username = opts .get ("username" , username )
828
+ password = opts .get ("password" , password )
827
829
self ._options = options = ClientOptions (username , password , dbase , opts , _IS_SYNC )
828
830
829
831
self ._default_database_name = dbase
@@ -887,15 +889,7 @@ def __init__(
887
889
# This will be used later if we fork.
888
890
AsyncMongoClient ._clients [self ._topology ._topology_id ] = self
889
891
890
- def _normalize_and_validate_options (self , opts , seeds ):
891
- # Handle security-option conflicts in combined options.
892
- opts = _handle_security_options (opts )
893
- # Normalize combined options.
894
- opts = _normalize_options (opts )
895
- _check_options (seeds , opts )
896
- return opts
897
-
898
- def _resolve_uri (self ):
892
+ def _resolve_uri (self ) -> None :
899
893
keyword_opts = self ._resolve_uri_info ["keyword_opts" ]
900
894
seeds = set ()
901
895
opts = common ._CaseInsensitiveDictionary ()
@@ -953,7 +947,7 @@ def _resolve_uri(self):
953
947
srv_service_name = opts .get ("srvServiceName" , common .SRV_SERVICE_NAME )
954
948
955
949
srv_max_hosts = srv_max_hosts or opts .get ("srvmaxhosts" )
956
- opts = self ._normalize_and_validate_opts (opts , seeds )
950
+ opts = self ._normalize_and_validate_options (opts , seeds )
957
951
958
952
# Username and password passed as kwargs override user info in URI.
959
953
username = opts .get ("username" , self ._resolve_uri_info ["username" ])
@@ -991,15 +985,21 @@ def _resolve_uri(self):
991
985
992
986
self ._topology = Topology (self ._topology_settings )
993
987
994
- def _normalize_and_validate_opts (self , opts , seeds ):
988
+ def _normalize_and_validate_options (
989
+ self , opts : common ._CaseInsensitiveDictionary , seeds : set [tuple [str , int | None ]]
990
+ ) -> common ._CaseInsensitiveDictionary :
995
991
# Handle security-option conflicts in combined options.
996
992
opts = _handle_security_options (opts )
997
993
# Normalize combined options.
998
994
opts = _normalize_options (opts )
999
995
_check_options (seeds , opts )
1000
996
return opts
1001
997
1002
- def _validate_kwargs_and_update_opts (self , keyword_opts , opts ):
998
+ def _validate_kwargs_and_update_opts (
999
+ self ,
1000
+ keyword_opts : common ._CaseInsensitiveDictionary ,
1001
+ opts : common ._CaseInsensitiveDictionary ,
1002
+ ) -> common ._CaseInsensitiveDictionary :
1003
1003
# Handle deprecated options in kwarg options.
1004
1004
keyword_opts = _handle_option_deprecations (keyword_opts )
1005
1005
# Validate kwarg options.
0 commit comments