-
Notifications
You must be signed in to change notification settings - Fork 281
Description
Describe the Bug
When running pyrefly check on this file: https://github.com/psalvaggio/scientific_pydantic/blob/main/tests/numpy/test_dtype.py#L22
I expect line 22 to be OK, but it actually gives:
[Pyrefly] Argument `Literal['>i4']` is not assignable to parameter `dtype` with type `dtype[Any]` in function `DefaultModel.__init__`
Background:
This is a library I am working on that has a number of pydantic adapters for scientific types. The one I linked here is for numpy.dtype, but the issue is similar on a number of other ones.
The field is annotated like:
dtype: ty.Annotated[np.dtype, DTypeAdapter()]where DTypeAdapter() make a custom schema for the np.dtype. This particular schema is a plain validator that takes Any and either converts to a dtype or raises an exception, resulting in a validation error.
I would expect pyrefly to take Any for dtype in the model constructor, but it instead is constraining to np.dtype.
I think if there is a custom type in an Annotated field that implements __get_pydantic_core_schema__, then pyrefly should probably be fairly lax on the constraints for the corresponding keyword argument.
Happy to discuss or provide more details.
Sandbox Link
(Only applicable for extension issues) IDE Information
No response