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

Skip signature check for functions in the standard library, or give users control over whether the check is performed #7072

Closed
3 of 13 tasks
danhje opened this issue Aug 10, 2023 · 2 comments · Fixed by #7101
Assignees
Labels
feature request unconfirmed Bug not yet confirmed as valid/applicable

Comments

@danhje
Copy link

danhje commented Aug 10, 2023

Initial Checks

  • I have searched Google & GitHub for similar requests and couldn't find anything
  • I have read and followed the docs and still think this feature is missing

Description

This fails:

from datetime import datetime

from pydantic import AfterValidator, TypeAdapter
from typing_extensions import Annotated

ISOTimestamp = Annotated[datetime, AfterValidator(datetime.isoformat)]
print(TypeAdapter(ISOTimestamp).validate_python(1651576501.0))
# ValueError: no signature found for builtin <method 'isoformat' of 'datetime.datetime' objects>

A simple workaround is to call datetime.isoformat from a lambda, but that's a bit ugly.

inspect_validator excludes builtins from the inspection that fails, but does not exclude methods like datetime.timestamp from the inspection. I think it should. Or give the user control over whether the inspection takes place.

Affected Components

Selected Assignee: @adriangb

@pydantic-hooky pydantic-hooky bot added the unconfirmed Bug not yet confirmed as valid/applicable label Aug 10, 2023
@adriangb
Copy link
Member

I agree that it'd be nice if this just worked, but it's going to be hard to special case everything.
Maybe if we can't get the signature we can assume one, e.g. a single argument that is the input value?

@dmontagu I'm curious what you think

@danhje
Copy link
Author

danhje commented Aug 11, 2023

Yeah, I think that's reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
2 participants