Skip to content

Commit

Permalink
fix(core): Typing in config + utils (#692)
Browse files Browse the repository at this point in the history
Supports:
#305
Related : #691 

```bash
poetry run mypy --config-file pyproject.toml core/testcontainers/core/config.py core/testcontainers/core/utils.py
Success: no issues found in 2 source files
```
  • Loading branch information
Tranquility2 authored Sep 8, 2024
1 parent 66726b6 commit 794a22e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions core/testcontainers/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def read_tc_properties() -> dict[str, str]:
tc_files = [item for item in [TC_GLOBAL] if exists(item)]
if not tc_files:
return {}
settings = {}
settings: dict[str, str] = {}

for file in tc_files:
with open(file) as contents:
Expand Down Expand Up @@ -60,14 +60,14 @@ class TestcontainersConfiguration:
"""

@property
def docker_auth_config(self):
def docker_auth_config(self) -> Optional[str]:
config = self._docker_auth_config
if config and "DOCKER_AUTH_CONFIG" in _WARNINGS:
warning(_WARNINGS.pop("DOCKER_AUTH_CONFIG"))
return config

@docker_auth_config.setter
def docker_auth_config(self, value: str):
def docker_auth_config(self, value: str) -> None:
if "DOCKER_AUTH_CONFIG" in _WARNINGS:
warning(_WARNINGS.pop("DOCKER_AUTH_CONFIG"))
self._docker_auth_config = value
Expand All @@ -76,7 +76,7 @@ def tc_properties_get_tc_host(self) -> Union[str, None]:
return self.tc_properties.get("tc.host")

@property
def timeout(self):
def timeout(self) -> int:
return self.max_tries * self.sleep_time


Expand Down
9 changes: 6 additions & 3 deletions core/testcontainers/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import platform
import subprocess
import sys
from typing import Any, Optional

LINUX = "linux"
MAC = "mac"
Expand All @@ -18,14 +19,15 @@ def setup_logger(name: str) -> logging.Logger:
return logger


def os_name() -> str:
def os_name() -> Optional[str]:
pl = sys.platform
if pl == "linux" or pl == "linux2":
return LINUX
elif pl == "darwin":
return MAC
elif pl == "win32":
return WIN
return None


def is_mac() -> bool:
Expand Down Expand Up @@ -53,7 +55,7 @@ def inside_container() -> bool:
return os.path.exists("/.dockerenv")


def default_gateway_ip() -> str:
def default_gateway_ip() -> Optional[str]:
"""
Returns gateway IP address of the host that testcontainer process is
running on
Expand All @@ -66,11 +68,12 @@ def default_gateway_ip() -> str:
ip_address = process.communicate()[0]
if ip_address and process.returncode == 0:
return ip_address.decode("utf-8").strip().strip("\n")
return None
except subprocess.SubprocessError:
return None


def raise_for_deprecated_parameter(kwargs: dict, name: str, replacement: str) -> dict:
def raise_for_deprecated_parameter(kwargs: dict[Any, Any], name: str, replacement: str) -> dict[Any, Any]:
"""
Raise an error if a dictionary of keyword arguments contains a key and suggest the replacement.
"""
Expand Down

0 comments on commit 794a22e

Please sign in to comment.