diff --git a/koerce/annots.py b/koerce/annots.py index ae973c0..13ad749 100644 --- a/koerce/annots.py +++ b/koerce/annots.py @@ -666,7 +666,7 @@ def __new__( slots: list[str] = list(dct.pop("__slots__", [])) module: str | None = dct.pop("__module__", None) qualname: str = dct.pop("__qualname__", clsname) - annotations: dict[str, Any] = dct.pop("__annotations__", {}) + annotations: dict[str, Any] = dct.get("__annotations__", {}) if module is None: self_qualname = None else: diff --git a/koerce/tests/test_annots.py b/koerce/tests/test_annots.py index 61f3df0..6c60ada 100644 --- a/koerce/tests/test_annots.py +++ b/koerce/tests/test_annots.py @@ -1118,6 +1118,14 @@ class Between(BetweenSimple): # assert obj.copy(lower=8) == obj2 +def test_annotable_keeps_annotations_classvar(): + class MyClass(Annotable): + a: int + b: str + + assert MyClass.__annotations__ == {"a": "int", "b": "str"} + + def test_annotable_with_bound_typevars_properly_coerce_values(): v = MyValue(1.1, 2.2, 3.3) assert isinstance(v.integer, MyInt) diff --git a/koerce/tests/test_utils.py b/koerce/tests/test_utils.py index a2499e6..66612ef 100644 --- a/koerce/tests/test_utils.py +++ b/koerce/tests/test_utils.py @@ -128,7 +128,7 @@ def test_get_type_boundvars() -> None: def test_get_type_boundvars_unable_to_deduce() -> None: - msg = "Unable to deduce corresponding type attributes..." + msg = "Unable to deduce corresponding attributes..." with pytest.raises(ValueError, match=msg): get_type_boundvars(MyDict[int, str]) diff --git a/koerce/utils.py b/koerce/utils.py index b8f8224..af5a488 100644 --- a/koerce/utils.py +++ b/koerce/utils.py @@ -165,7 +165,9 @@ def get_type_boundvars(typ: Any) -> dict[TypeVar, tuple[str, type]]: if params: raise ValueError( - f"Unable to deduce corresponding type attributes for the following type variables: {params}" + f"Unable to deduce corresponding attributes for type parameters of {typ}.\n" + f"Missing attributes with typehints for the following type variables: {params}.\n" + f"Available type hints: {hints}" ) return result