Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
NixBiks opened this issue Feb 18, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@NixBiks
Copy link

NixBiks commented Feb 18, 2021

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

@adrianeboyd adrianeboyd transferred this issue from explosion/thinc Dec 18, 2023
@svlandeg svlandeg added the enhancement New feature or request label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants