Skip to content

Commit

Permalink
Merge pull request #84 from altescy/fix-placehodler-validation
Browse files Browse the repository at this point in the history
Fix placeholder type validation
  • Loading branch information
altescy authored Nov 26, 2024
2 parents 0b9e5f8 + d432b27 commit 31cedb0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion colt/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def type_hint(self) -> T:
return self._annotation

def match_type_hint(self, annotation: Any) -> bool:
return issubtype(annotation, self._annotation)
return issubtype(self._annotation, annotation)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "colt"
version = "0.14.2"
version = "0.14.3"
description = "A configuration utility for Python object."
authors = ["altescy <[email protected]>"]
license = "MIT License"
Expand Down
17 changes: 16 additions & 1 deletion tests/test_placeholder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dataclasses
from typing import Set
from typing import Any, Set, Union

import pytest

Expand Down Expand Up @@ -43,3 +43,18 @@ def __init__(self, value) -> None: # type: ignore[no-untyped-def]
self.value = value

colt.dry_run({"foo": Placeholder(Foo)}, Foo)


@pytest.mark.parametrize(
"placeholder, annotation, expected",
[
(int, int, True),
(int, str, False),
(int, Union[int, str], True),
(int, Union[str, float], False),
],
)
def test_placeholder_match_type_hint(
placeholder: Any, annotation: Any, expected: bool
) -> None:
assert Placeholder(placeholder).match_type_hint(annotation) == expected
2 changes: 1 addition & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version() -> None:
assert colt.__version__ == "0.14.2"
assert colt.__version__ == "0.14.3"

0 comments on commit 31cedb0

Please sign in to comment.