Skip to content

Commit 794a22e

Browse files
authored
fix(core): Typing in config + utils (#692)
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 ```
1 parent 66726b6 commit 794a22e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

core/testcontainers/core/config.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def read_tc_properties() -> dict[str, str]:
3030
tc_files = [item for item in [TC_GLOBAL] if exists(item)]
3131
if not tc_files:
3232
return {}
33-
settings = {}
33+
settings: dict[str, str] = {}
3434

3535
for file in tc_files:
3636
with open(file) as contents:
@@ -60,14 +60,14 @@ class TestcontainersConfiguration:
6060
"""
6161

6262
@property
63-
def docker_auth_config(self):
63+
def docker_auth_config(self) -> Optional[str]:
6464
config = self._docker_auth_config
6565
if config and "DOCKER_AUTH_CONFIG" in _WARNINGS:
6666
warning(_WARNINGS.pop("DOCKER_AUTH_CONFIG"))
6767
return config
6868

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

7878
@property
79-
def timeout(self):
79+
def timeout(self) -> int:
8080
return self.max_tries * self.sleep_time
8181

8282

core/testcontainers/core/utils.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import platform
44
import subprocess
55
import sys
6+
from typing import Any, Optional
67

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

2021

21-
def os_name() -> str:
22+
def os_name() -> Optional[str]:
2223
pl = sys.platform
2324
if pl == "linux" or pl == "linux2":
2425
return LINUX
2526
elif pl == "darwin":
2627
return MAC
2728
elif pl == "win32":
2829
return WIN
30+
return None
2931

3032

3133
def is_mac() -> bool:
@@ -53,7 +55,7 @@ def inside_container() -> bool:
5355
return os.path.exists("/.dockerenv")
5456

5557

56-
def default_gateway_ip() -> str:
58+
def default_gateway_ip() -> Optional[str]:
5759
"""
5860
Returns gateway IP address of the host that testcontainer process is
5961
running on
@@ -66,11 +68,12 @@ def default_gateway_ip() -> str:
6668
ip_address = process.communicate()[0]
6769
if ip_address and process.returncode == 0:
6870
return ip_address.decode("utf-8").strip().strip("\n")
71+
return None
6972
except subprocess.SubprocessError:
7073
return None
7174

7275

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

0 commit comments

Comments
 (0)