Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add test for annotated #88

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/test_colt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dataclasses
import sys
from enum import Enum
from typing import (
Any,
Expand All @@ -24,6 +25,11 @@

import colt

if sys.version_info >= (3, 9):
from typing import Annotated
else:
from typing_extensions import Annotated


@colt.register("foo")
class Foo:
Expand Down Expand Up @@ -511,3 +517,19 @@ def __init__(self, model: BaseModel[T, U], params: U, data: T) -> None:
assert isinstance(executor.model, MyModel)
assert isinstance(executor.params, MyModel.Params)
assert isinstance(executor.data, Item)


def test_build_with_annotated() -> None:
class Foo:
def __init__(self, x: str) -> None:
self.x = x

class Bar:
def __init__(self, foo: Annotated[Foo, "test"]) -> None:
self.foo = foo

config = {"foo": {"x": "hello"}}
obj = colt.build(config, Bar)

assert isinstance(obj.foo, Foo)
assert obj.foo.x == "hello"
Loading