4343 HAVE_IPADDRESS = True
4444except ImportError :
4545 HAVE_IPADDRESS = False
46-
4746from contextlib import contextmanager
4847from functools import wraps
4948from test .version import Version
50- from typing import Callable , Dict , Generator , no_type_check
49+ from typing import Any , Callable , Dict , Generator , no_type_check
5150from unittest import SkipTest
5251from urllib .parse import quote_plus
5352
@@ -331,7 +330,9 @@ def hello(self):
331330
332331 def _connect (self , host , port , ** kwargs ):
333332 kwargs .update (self .default_client_options )
334- client = pymongo .MongoClient (host , port , serverSelectionTimeoutMS = 5000 , ** kwargs )
333+ client : MongoClient = pymongo .MongoClient (
334+ host , port , serverSelectionTimeoutMS = 5000 , ** kwargs
335+ )
335336 try :
336337 try :
337338 client .admin .command (HelloCompat .LEGACY_CMD ) # Can we connect?
@@ -356,7 +357,7 @@ def _init_client(self):
356357 if self .client is not None :
357358 # Return early when connected to dataLake as mongohoused does not
358359 # support the getCmdLineOpts command and is tested without TLS.
359- build_info = self .client .admin .command ("buildInfo" )
360+ build_info : Any = self .client .admin .command ("buildInfo" )
360361 if "dataLake" in build_info :
361362 self .is_data_lake = True
362363 self .auth_enabled = True
@@ -521,14 +522,16 @@ def has_secondaries(self):
521522 @property
522523 def storage_engine (self ):
523524 try :
524- return self .server_status .get ("storageEngine" , {}).get ("name" )
525+ return self .server_status .get ("storageEngine" , {}).get ( # type:ignore[union-attr]
526+ "name"
527+ )
525528 except AttributeError :
526529 # Raised if self.server_status is None.
527530 return None
528531
529532 def _check_user_provided (self ):
530533 """Return True if db_user/db_password is already an admin user."""
531- client = pymongo .MongoClient (
534+ client : MongoClient = pymongo .MongoClient (
532535 host ,
533536 port ,
534537 username = db_user ,
@@ -694,7 +697,7 @@ def supports_secondary_read_pref(self):
694697 if self .has_secondaries :
695698 return True
696699 if self .is_mongos :
697- shard = self .client .config .shards .find_one ()["host" ]
700+ shard = self .client .config .shards .find_one ()["host" ] # type:ignore[index]
698701 num_members = shard .count ("," ) + 1
699702 return num_members > 1
700703 return False
@@ -1015,12 +1018,12 @@ def fork(
10151018 """
10161019
10171020 def _print_threads (* args : object ) -> None :
1018- if _print_threads .called :
1021+ if _print_threads .called : # type:ignore[attr-defined]
10191022 return
1020- _print_threads .called = True
1023+ _print_threads .called = True # type:ignore[attr-defined]
10211024 print_thread_tracebacks ()
10221025
1023- _print_threads .called = False
1026+ _print_threads .called = False # type:ignore[attr-defined]
10241027
10251028 def _target () -> None :
10261029 signal .signal (signal .SIGUSR1 , _print_threads )
0 commit comments