You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
fromtypingimportCallablefrompydantic.mainimportBaseModelimportthincfromthinc.apiimportConfig, registryclassResource(BaseModel):
url: strthinc.registry.create("resources")
@thinc.registry.resources("Resource.v1")defmake_resource(
resource: Resource,
) ->str:
returnresource.url# this fails since resource is a dict and not Resourceconfig=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'objecthasnoattribute'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'm not sure whether this is intended behavior or not. In the following example I'd expect
make_resource
function to receive aResource
.But the current
registry.resolve
simply validates that adict
would be able to be parsed toResource
but is not actually resolved to aResource
, i.e. the type inmake_resource
is adict
in the example above so I end up with the following errorNow 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
The text was updated successfully, but these errors were encountered: