From 458b36f6cba9a49e1274e09c732f5cacb93b13de Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sun, 1 Sep 2024 12:04:45 -0400 Subject: [PATCH] fix(annotable): remove unfinished `__coerce__` implementation and add tests (#24) --- koerce/annots.py | 3 --- koerce/tests/test_annots.py | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/koerce/annots.py b/koerce/annots.py index deb301e..ae973c0 100644 --- a/koerce/annots.py +++ b/koerce/annots.py @@ -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__) diff --git a/koerce/tests/test_annots.py b/koerce/tests/test_annots.py index b2f7902..61f3df0 100644 --- a/koerce/tests/test_annots.py +++ b/koerce/tests/test_annots.py @@ -7,6 +7,7 @@ from dataclasses import dataclass from typing import ( Annotated, + Any, Callable, Generic, Mapping, @@ -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