Skip to content

Commit

Permalink
Merge pull request #2341 from VWS-Python/immutable-types-more-2
Browse files Browse the repository at this point in the history
Change a few more `set` types to Iterable
  • Loading branch information
adamtheturtle committed Sep 28, 2024
2 parents 8306174 + e411acd commit 6c97c6f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
10 changes: 7 additions & 3 deletions ci/test_custom_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
"""

from pathlib import Path
from typing import TYPE_CHECKING

import pytest
import yaml
from beartype import beartype

if TYPE_CHECKING:
from collections.abc import Iterable


@beartype
def _ci_patterns(*, repository_root: Path) -> set[str]:
Expand All @@ -34,7 +38,7 @@ def _tests_from_pattern(
"""
# Clear the captured output.
capsys.readouterr()
tests: set[str] = set()
tests: Iterable[str] = set()
pytest.main(
args=[
"-q",
Expand All @@ -49,8 +53,8 @@ def _tests_from_pattern(
# We filter empty lines and lines which look like
# "9 tests collected in 0.01s".
if line and "collected in" not in line:
tests.add(line)
return tests
tests = {*tests, line}
return set(tests)


def test_ci_patterns_valid(request: pytest.FixtureRequest) -> None:
Expand Down
17 changes: 13 additions & 4 deletions src/mock_vws/_requests_mock_server/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import re
from contextlib import ContextDecorator
from typing import Literal, Self
from typing import TYPE_CHECKING, Literal, Self
from urllib.parse import urljoin, urlparse

from beartype import BeartypeConf, beartype
Expand All @@ -24,6 +24,9 @@
from .mock_web_query_api import MockVuforiaWebQueryAPI
from .mock_web_services_api import MockVuforiaWebServicesAPI

if TYPE_CHECKING:
from collections.abc import Iterable

_STRUCTURAL_SIMILARITY_MATCHER = StructuralSimilarityMatcher()
_BRISQUE_TRACKING_RATER = BrisqueTargetTrackingRater()

Expand Down Expand Up @@ -132,7 +135,7 @@ def __enter__(self) -> Self:
Returns:
``self``.
"""
compiled_url_patterns: set[re.Pattern[str]] = set()
compiled_url_patterns: Iterable[re.Pattern[str]] = set()

mock = RequestsMock(assert_all_requests_are_fired=False)
for vws_route in self._mock_vws_api.routes:
Expand All @@ -141,7 +144,10 @@ def __enter__(self) -> Self:
url=f"{vws_route.path_pattern}$",
)
compiled_url_pattern = re.compile(pattern=url_pattern)
compiled_url_patterns.add(compiled_url_pattern)
compiled_url_patterns = {
*compiled_url_patterns,
compiled_url_pattern,
}

for vws_http_method in vws_route.http_methods:
mock.add_callback(
Expand All @@ -157,7 +163,10 @@ def __enter__(self) -> Self:
url=f"{vwq_route.path_pattern}$",
)
compiled_url_pattern = re.compile(pattern=url_pattern)
compiled_url_patterns.add(compiled_url_pattern)
compiled_url_patterns = {
*compiled_url_patterns,
compiled_url_pattern,
}

for vwq_http_method in vwq_route.http_methods:
mock.add_callback(
Expand Down
4 changes: 2 additions & 2 deletions src/mock_vws/_requests_mock_server/mock_web_services_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import email.utils
import json
import uuid
from collections.abc import Callable
from collections.abc import Callable, Iterable
from http import HTTPMethod, HTTPStatus
from typing import Any
from zoneinfo import ZoneInfo
Expand Down Expand Up @@ -45,7 +45,7 @@
@beartype
def route(
path_pattern: str,
http_methods: set[HTTPMethod],
http_methods: Iterable[HTTPMethod],
) -> Callable[[Callable[..., _ResponseType]], Callable[..., _ResponseType]]:
"""
Register a decorated method so that it can be recognized as a route.
Expand Down
6 changes: 3 additions & 3 deletions tests/mock_vws/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import io
import uuid
from collections.abc import Iterator
from collections.abc import Iterable, Iterator
from http import HTTPStatus
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -76,13 +76,13 @@ def fixture_custom_bridge_network() -> Iterator[Network]:
yield network
finally:
network.reload()
images_to_remove: set[Image] = set()
images_to_remove: Iterable[Image] = set()
for container in network.containers:
network.disconnect(container=container)
container.stop()
container.remove(v=True, force=True)
assert container.image is not None
images_to_remove.add(container.image)
images_to_remove = {*images_to_remove, container.image}

# This does leave behind untagged images.
for image in images_to_remove:
Expand Down

0 comments on commit 6c97c6f

Please sign in to comment.