Skip to content

Commit e88d2c5

Browse files
committed
Add type annotations for mongodb.
1 parent b6807bd commit e88d2c5

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

mongodb/testcontainers/mongodb/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
1313
import os
14-
14+
from pymongo import MongoClient
1515
from testcontainers.core.generic import DbContainer
1616
from testcontainers.core.waiting_utils import wait_container_is_ready
1717

@@ -50,21 +50,18 @@ class MongoDbContainer(DbContainer):
5050
MONGO_INITDB_ROOT_PASSWORD = os.environ.get("MONGO_INITDB_ROOT_PASSWORD", "test")
5151
MONGO_DB = os.environ.get("MONGO_DB", "test")
5252

53-
def __init__(self,
54-
image: str = "mongo:latest",
55-
port_to_expose: int = 27017,
56-
**kwargs):
53+
def __init__(self, image: str = "mongo:latest", port_to_expose: int = 27017, **kwargs) -> None:
5754
super(MongoDbContainer, self).__init__(image=image, **kwargs)
5855
self.command = "mongo"
5956
self.port_to_expose = port_to_expose
6057
self.with_exposed_ports(self.port_to_expose)
6158

62-
def _configure(self):
59+
def _configure(self) -> None:
6360
self.with_env("MONGO_INITDB_ROOT_USERNAME", self.MONGO_INITDB_ROOT_USERNAME)
6461
self.with_env("MONGO_INITDB_ROOT_PASSWORD", self.MONGO_INITDB_ROOT_PASSWORD)
6562
self.with_env("MONGO_DB", self.MONGO_DB)
6663

67-
def get_connection_url(self):
64+
def get_connection_url(self) -> str:
6865
return self._create_connection_url(
6966
dialect='mongodb',
7067
username=self.MONGO_INITDB_ROOT_USERNAME,
@@ -73,9 +70,8 @@ def get_connection_url(self):
7370
)
7471

7572
@wait_container_is_ready()
76-
def _connect(self):
77-
from pymongo import MongoClient
73+
def _connect(self) -> MongoClient:
7874
return MongoClient(self.get_connection_url())
7975

80-
def get_connection_client(self):
76+
def get_connection_client(self) -> MongoClient:
8177
return self._connect()

0 commit comments

Comments
 (0)