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
PlainSerializer does not accept the built-in object str as its func argument. The parameter's type annotation includes Callable[[Any], Any], which str is an instance of. Wrapping str within a lambda expression or a def statement allows the code to work, but that shouldn't be necessary. The problem seems to specifically be with built-ins. The problem isn't classes because a custom class works fine, and the problem isn't restricted to built-in classes because hash() also doesn't work without wrapping.
I have included a stack trace of the thrown exception below:
Thanks for the report. This is definitely something we do want to support. Might be a pretty good first issue to pick up if someone is interested.
As shown in the traceback, the issue is that str doesn't have an __annotations__ attribute like almost all other functions that we use. Not sure exactly what workaround we should use for those stdlib callable types, though.
Initial Checks
Description
PlainSerializer
does not accept the built-in objectstr
as itsfunc
argument. The parameter's type annotation includesCallable[[Any], Any]
, whichstr
is an instance of. Wrappingstr
within alambda
expression or adef
statement allows the code to work, but that shouldn't be necessary. The problem seems to specifically be with built-ins. The problem isn't classes because a custom class works fine, and the problem isn't restricted to built-in classes becausehash()
also doesn't work without wrapping.I have included a stack trace of the thrown exception below:
Stack trace
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: