Skip to content

Commit

Permalink
fix(annotable): remove unfinished __coerce__ implementation and add…
Browse files Browse the repository at this point in the history
… tests (#24)
  • Loading branch information
cpcloud authored Sep 1, 2024
1 parent bab9396 commit 458b36f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
3 changes: 0 additions & 3 deletions koerce/annots.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,9 +829,6 @@ def __repr__(self) -> str:
argstring = ", ".join(args)
return f"{self.__class__.__name__}({argstring})"

def __coerce__(self, obj, **kwargs):
return self.__class__(**obj)

@property
def __args__(self) -> tuple[Any, ...]:
return tuple(getattr(self, name) for name in self.__argnames__)
25 changes: 25 additions & 0 deletions koerce/tests/test_annots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dataclasses import dataclass
from typing import (
Annotated,
Any,
Callable,
Generic,
Mapping,
Expand Down Expand Up @@ -1980,3 +1981,27 @@ def called_with(self):
assert mi.b == "2"
assert mi.c == 3.3
assert mi.called_with == called_with


def test_any():
class MyClass(Annotable):
foo: Any

assert MyClass(1).foo == 1


class Bar(Annotable):
x: int


def test_nested():
class Foo(Annotable):
bar: Bar

assert Foo(Bar(1)).bar.x == 1

class Quux(Annotable):
bar: Bar = Bar(2)

assert Quux().bar.x == 2
assert Quux(Bar(3)).bar.x == 3

0 comments on commit 458b36f

Please sign in to comment.