-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request