Skip to content
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

Merged
merged 4 commits into from Mar 25, 2023
Merged

Allow serializers to ignore the info argument #5272

merged 4 commits into from Mar 25, 2023

Conversation

adriangb
Copy link
Member

@adriangb adriangb commented Mar 24, 2023

Selected Reviewer: @samuelcolvin

Comment on lines -180 to -191
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
...
Copy link
Member Author

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).

@adriangb
Copy link
Member Author

please review

Copy link
Member

@samuelcolvin samuelcolvin left a 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.

"""


def make_generic_v2_field_serializer(
Copy link
Member

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 = """\
Copy link
Member

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.

)
func = cast(AnyCoreSerializer, serializer)
return func
assert mode == 'wrap'
Copy link
Member

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.

@adriangb adriangb enabled auto-merge (squash) March 25, 2023 00:09
@adriangb adriangb merged commit 473b18c into main Mar 25, 2023
37 checks passed
@adriangb adriangb deleted the ser-info branch March 25, 2023 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants