Skip to content

Commit bb5f120

Browse files
committed
fix(core): Typing in generic + network
fix missing run
1 parent 8f1165d commit bb5f120

File tree

10 files changed

+239
-43
lines changed

10 files changed

+239
-43
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ coverage: ## Target to combine and report coverage.
3131
lint: ## Lint all files in the project, which we also run in pre-commit
3232
poetry run pre-commit run -a
3333

34+
mypy-core-report:
35+
poetry run mypy --config-file pyproject.toml core | poetry run python scripts/mypy_report.py
36+
3437
image: ## Make the docker image for dind tests
3538
poetry export -f requirements.txt -o build/requirements.txt
3639
docker build --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t ${IMAGE} .

core/testcontainers/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
13-
from typing import Optional
13+
from typing import Any, Optional
1414
from urllib.parse import quote
1515

1616
from testcontainers.core.container import DockerContainer
@@ -55,7 +55,7 @@ def _create_connection_url(
5555
host: Optional[str] = None,
5656
port: Optional[int] = None,
5757
dbname: Optional[str] = None,
58-
**kwargs,
58+
**kwargs: Any,
5959
) -> str:
6060
if raise_for_deprecated_parameter(kwargs, "db_name", "dbname"):
6161
raise ValueError(f"Unexpected arguments: {','.join(kwargs)}")

core/testcontainers/core/network.py

+6-4
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 uuid
14-
from typing import Optional
14+
from typing import Any, Optional
1515

1616
from testcontainers.core.docker_client import DockerClient
1717

@@ -21,12 +21,14 @@ class Network:
2121
Network context manager for programmatically connecting containers.
2222
"""
2323

24-
def __init__(self, docker_client_kw: Optional[dict] = None, docker_network_kw: Optional[dict] = None) -> None:
24+
def __init__(
25+
self, docker_client_kw: Optional[dict[str, Any]] = None, docker_network_kw: Optional[dict[str, Any]] = None
26+
):
2527
self.name = str(uuid.uuid4())
2628
self._docker = DockerClient(**(docker_client_kw or {}))
2729
self._docker_network_kw = docker_network_kw or {}
2830

29-
def connect(self, container_id: str, network_aliases: Optional[list] = None):
31+
def connect(self, container_id: str, network_aliases: Optional[list[str]] = None) -> None:
3032
self._network.connect(container_id, aliases=network_aliases)
3133

3234
def remove(self) -> None:
@@ -40,5 +42,5 @@ def create(self) -> "Network":
4042
def __enter__(self) -> "Network":
4143
return self.create()
4244

43-
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
45+
def __exit__(self, exc_type, exc_val, exc_tb) -> None: # type: ignore[no-untyped-def]
4446
self.remove()

core/tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from typing import Callable
3-
from testcontainers.core.container import DockerClient
3+
from testcontainers.core.docker_client import DockerClient
44

55

66
@pytest.fixture

core/tests/test_docker_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def test_docker_client_login():
3838
mock_parse_docker_auth_config = MagicMock(spec=parse_docker_auth_config)
3939
mock_utils = MagicMock()
4040
mock_utils.parse_docker_auth_config = mock_parse_docker_auth_config
41-
TestAuth = namedtuple("Auth", "value")
42-
mock_parse_docker_auth_config.return_value = [TestAuth("test")]
41+
Auth = namedtuple("Auth", "value")
42+
mock_parse_docker_auth_config.return_value = [Auth("test")]
4343

4444
with (
4545
mock.patch.object(c, "_docker_auth_config", "test"),

core/tests/test_labels.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from testcontainers.core.config import RYUK_IMAGE
1111

1212

13-
def assert_in_with_value(labels: dict, label: str, value: str, known_before_test_time: bool) -> None:
13+
def assert_in_with_value(labels: dict[str, str], label: str, value: str, known_before_test_time: bool):
1414
assert label in labels
1515
if known_before_test_time:
1616
assert labels[label] == value

core/tests/test_network.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ def test_network_has_labels():
9090
try:
9191
network.create()
9292
network = network._docker.client.networks.get(network_id=network.id)
93-
assert LABEL_SESSION_ID in network.attrs.get("Labels")
93+
assert LABEL_SESSION_ID in network.attrs.get("Labels") # type: ignore[attr-defined]
9494
finally:
9595
network.remove()

poetry.lock

+185-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ chroma = ["chromadb-client"]
166166
trino = ["trino"]
167167

168168
[tool.poetry.group.dev.dependencies]
169-
mypy = "1.7.1"
169+
mypy = "1.11.2"
170170
pre-commit = "^3.6"
171171
pytest = "7.4.3"
172172
pytest-cov = "4.1.0"
@@ -280,8 +280,9 @@ namespace_packages = true
280280
explicit_package_bases = true
281281
pretty = true
282282
show_error_codes = true
283+
warn_return_any = true
283284
strict = true
284-
fast_module_lookup = true
285+
# fast_module_lookup = true
285286
modules = ["testcontainers.core"]
286287
mypy_path = [
287288
"core",

scripts/mypy_report.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Description: This script reads the output of mypy and generates a summary of errors by file.
2+
3+
import re
4+
import sys
5+
6+
from rich.console import Console
7+
from rich.table import Table
8+
9+
# Regular expression to match file path and error count
10+
pattern = r"(.*\.py:\d+):\s+error: (.*)"
11+
12+
error_dict = {}
13+
14+
for line in sys.stdin:
15+
match = re.search(pattern, line)
16+
if match:
17+
# Extract file path and error message
18+
file_path, _ = match.group(1).split(":")
19+
error_message = match.group(2)
20+
21+
if file_path not in error_dict:
22+
error_dict[file_path] = 1
23+
else:
24+
error_dict[file_path] += 1
25+
26+
table = Table(title="Error Summary")
27+
table.add_column("File Path")
28+
table.add_column("Errors", justify="left")
29+
30+
for file_path, error_count in error_dict.items():
31+
table.add_row(file_path, str(error_count))
32+
33+
console = Console()
34+
console.print(table)
35+
console.print(f"[red]Found {sum(error_dict.values())} errors in {len(error_dict)} files.[/red]")

0 commit comments

Comments
 (0)