Skip to content

Commit 2cdf3dd

Browse files
Fix: Linting issues and hash function for ContextScope.
1 parent 5617936 commit 2cdf3dd

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ ignore = [
8282
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
8383
"COM812", # flake8-commas "Trailing comma missing"
8484
"ISC001", # flake8-implicit-str-concat
85+
"PT028", # Test function has default argument
8586
]
8687
isort.lines-after-imports = 2
8788
isort.no-lines-before = ["standard-library", "local-folder"]

tests/providers/test_context_resources.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,3 +1107,9 @@ def test_fetch_context_item_by_type() -> None:
11071107
def test_fetch_context_item_raises() -> None:
11081108
with pytest.raises(KeyError):
11091109
fetch_context_item("s", raise_on_not_found=True)
1110+
1111+
1112+
def test_context_scope_hash() -> None:
1113+
assert ContextScope("TEST") == ContextScope("TEST")
1114+
assert hash(ContextScope("YES")) != hash(ContextScope("NO"))
1115+
assert hash(ContextScope("HMM")) == hash(ContextScope("HMM"))

tests/test_multiple_containers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def test_overwriting_container_warns(recwarn: None) -> None: # noqa:ARG00
4040
class _A(BaseContainer):
4141
pass
4242

43-
with pytest.warns(UserWarning):
43+
with pytest.warns(UserWarning, match="Overwriting container '_A'"):
4444

4545
class _A(BaseContainer): # type: ignore[no-redef]
4646
pass
@@ -53,7 +53,7 @@ async def test_overwriting_container_with_alias_warns(recwarn: None) -> None: #
5353
class _A(BaseContainer):
5454
alias = "a"
5555

56-
with pytest.warns(UserWarning):
56+
with pytest.warns(UserWarning, match="Overwriting container 'a'"):
5757

5858
class _A(BaseContainer): # type: ignore[no-redef]
5959
alias = "a"

that_depends/providers/context_resources.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def __eq__(self, other: object) -> bool:
6060
return self.name == other.name
6161
return False
6262

63+
@override
64+
def __hash__(self) -> int:
65+
return hash(self.name)
66+
6367
@override
6468
def __repr__(self) -> str:
6569
return f"{self.name!r}"
@@ -491,11 +495,11 @@ def _resolve_initial_conditions(self) -> None:
491495
else:
492496
self._initial_context = self._global_context or {}
493497
if self._reset_resource_context:
494-
from that_depends.meta import BaseContainerMeta
498+
from that_depends.meta import BaseContainerMeta # noqa: PLC0415
495499

496500
self._add_providers_from_containers(BaseContainerMeta.get_instances().values(), self._scope)
497501
for item in self._context_items:
498-
from that_depends.container import BaseContainer
502+
from that_depends.container import BaseContainer # noqa: PLC0415
499503

500504
if isinstance(item, type) and issubclass(item, BaseContainer):
501505
self._add_providers_from_containers([item], self._scope)

0 commit comments

Comments
 (0)