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
Allow serializers to ignore the info argument #5272
Conversation
def test_invalid_signature_bad_wrap_signature() -> None: | ||
with pytest.raises(TypeError, match='Invalid signature for wrap serializer'): | ||
|
||
class _(BaseModel): | ||
x: int | ||
|
||
# note that type checkers won't pick this one up | ||
# we could fix it but it would require some fiddling with the self argument in the | ||
# callable protocols | ||
@serializer('x', mode='wrap') | ||
def no_args(self, value: Any, info: Any) -> Any: # pragma: no cover | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we can't catch this at runtime or statically anymore because there's no way to distinguish it from (value, handler)
unless we want to (1) introspect types or (2) force some of these to be keyword arguments (but then we have to construct kwargs in rust).
please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise LGTM - though I haven't gone into complete detail.
please update.
pydantic/_internal/_decorators.py
Outdated
""" | ||
|
||
|
||
def make_generic_v2_field_serializer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think we need v2 in the name.
] | ||
|
||
|
||
_VALID_SERIALIZER_SIGNATURES = """\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find with this here for now, but it should end up in the docs.
pydantic/_internal/_decorators.py
Outdated
) | ||
func = cast(AnyCoreSerializer, serializer) | ||
return func | ||
assert mode == 'wrap' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line or else:
would make this easier to read.
Selected Reviewer: @samuelcolvin