Skip to content

Registered functions with pydantic BaseModel arguments are returned as dict #58

@NixBiks

Description

@NixBiks

I'm not sure whether this is intended behavior or not. In the following example I'd expect make_resource function to receive a Resource.

from typing import Callable
from pydantic.main import BaseModel
import thinc

from thinc.api import Config, registry


class Resource(BaseModel):

    url: str


thinc.registry.create("resources")


@thinc.registry.resources("Resource.v1")
def make_resource(
    resource: Resource,
) -> str:
    return resource.url  # this fails since resource is a dict and not Resource


config = Config().from_str(
    """
[test]
@resources = "Resource.v1"

[test.resource]
url = "https://thinc.ai/docs/usage-config"
"""
)
resolved = registry.resolve(config)

But the current registry.resolve simply validates that a dict would be able to be parsed to Resource but is not actually resolved to a Resource, i.e. the type in make_resource is a dict in the example above so I end up with the following error

AttributeError: 'dict' object has no attribute 'url'

Now obviously the validation should pass but I think the dict should be casted into the given BaseModel as well so the typings in the registered functions can be trusted.

I imagine this is related to #57 and #59

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions