Skip to content

Commit 557bc44

Browse files
committed
Add type annotations for postgres.
1 parent bb63fea commit 557bc44

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

postgres/testcontainers/postgres/__init__.py

Lines changed: 11 additions & 16 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 typing import Optional
1515
from testcontainers.core.generic import DbContainer
1616

1717

@@ -39,13 +39,9 @@ class PostgresContainer(DbContainer):
3939
POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD", "test")
4040
POSTGRES_DB = os.environ.get("POSTGRES_DB", "test")
4141

42-
def __init__(self,
43-
image="postgres:latest",
44-
port=5432, user=None,
45-
password=None,
46-
dbname=None,
47-
driver="psycopg2",
48-
**kwargs):
42+
def __init__(self, image: str = "postgres:latest", port: int = 5432, user: Optional[str] = None,
43+
password: Optional[str] = None, dbname: Optional[str] = None,
44+
driver: str = "psycopg2", **kwargs) -> None:
4945
super(PostgresContainer, self).__init__(image=image, **kwargs)
5046
self.POSTGRES_USER = user or self.POSTGRES_USER
5147
self.POSTGRES_PASSWORD = password or self.POSTGRES_PASSWORD
@@ -55,15 +51,14 @@ def __init__(self,
5551

5652
self.with_exposed_ports(self.port_to_expose)
5753

58-
def _configure(self):
54+
def _configure(self) -> None:
5955
self.with_env("POSTGRES_USER", self.POSTGRES_USER)
6056
self.with_env("POSTGRES_PASSWORD", self.POSTGRES_PASSWORD)
6157
self.with_env("POSTGRES_DB", self.POSTGRES_DB)
6258

63-
def get_connection_url(self, host=None):
64-
return super()._create_connection_url(dialect="postgresql+{}".format(self.driver),
65-
username=self.POSTGRES_USER,
66-
password=self.POSTGRES_PASSWORD,
67-
db_name=self.POSTGRES_DB,
68-
host=host,
69-
port=self.port_to_expose)
59+
def get_connection_url(self, host=None) -> str:
60+
return super()._create_connection_url(
61+
dialect="postgresql+{}".format(self.driver), username=self.POSTGRES_USER,
62+
password=self.POSTGRES_PASSWORD, db_name=self.POSTGRES_DB, host=host,
63+
port=self.port_to_expose,
64+
)

0 commit comments

Comments
 (0)