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

Support for validate_call with generics #7796

Open
1 task done
Tracked by #7928
caniko opened this issue Oct 11, 2023 · 6 comments
Open
1 task done
Tracked by #7928

Support for validate_call with generics #7796

caniko opened this issue Oct 11, 2023 · 6 comments
Assignees
Milestone

Comments

@caniko
Copy link
Contributor

caniko commented Oct 11, 2023

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

validate_call should catch wrong types being passed to any function/method; however, it breaks when used with parametrized generic methods.

A similar issue occurs when generic functions have incorrect return type.

Example Code

from typing import TypeVar, Generic

from pydantic import BaseModel, validate_call

T = TypeVar("T")


class MyGModel(BaseModel, Generic[T]):
    @validate_call
    def my_generic_method(self, arg: T) -> None:
        return


# Should fail because 1 is not str
MyGModel[str]().my_generic_method(1)


@validate_call(validate_return=True)
def my_func(arg: T) -> T:
    return 1


# Should fail because "5" is str, but 1 is int
my_func("5")

Python, Pydantic & OS Version

pydantic version: 2.4.2
        pydantic-core version: 2.10.1
          pydantic-core build: profile=release pgo=true
                 install path: /home/can/.cache/pypoetry/virtualenvs/chainspect-uudSkfMt-py3.11/lib/python3.11/site-packages/pydantic
               python version: 3.11.4 (main, Jun 19 2023, 07:09:29) [GCC 13.1.1 20230429]
                     platform: Linux-6.5.6-zen2-1-zen-x86_64-with-glibc2.38
             related packages: mypy-1.5.1 typing_extensions-4.8.0
@caniko caniko added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Oct 11, 2023
@caniko caniko changed the title @validate_call doesn't catch wrong type being passed to parametrized generic method @validate_call doesn't catch wrong type being passed to parametrized generic method; generic functions also have the same issue Oct 11, 2023
@sydney-runkle sydney-runkle self-assigned this Oct 11, 2023
@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Oct 11, 2023
@sydney-runkle
Copy link
Member

@caniko,

Thanks for reporting this. It does seem to be a bug 🐛.

@sydney-runkle
Copy link
Member

Going to move this to a feature-request instead - though I think it's one that should be relatively high on our list 😄.

@sydney-runkle sydney-runkle added feature request and removed bug V2 Bug related to Pydantic V2 labels Oct 16, 2023
@sydney-runkle sydney-runkle changed the title @validate_call doesn't catch wrong type being passed to parametrized generic method; generic functions also have the same issue Support validate_call with Generics Oct 25, 2023
@sydney-runkle sydney-runkle changed the title Support validate_call with Generics Support for validate_call with generics Oct 25, 2023
@AmailP
Copy link

AmailP commented Feb 7, 2024

Hi @sydney-runkle, since the #7928 has been closed, would it make sense to add this issue to a milestone, since it seems to be your new approach to issues?

@sydney-runkle
Copy link
Member

@AmailP,

This isn't a super high priority issue at the moment, so I don't think we'll add it to the 2.7 milestone. If there's more community support, or if someone wants to take this on, we can certainly move up the timeline!

@sydney-runkle
Copy link
Member

A good example of this lack of support: #9536

@sydney-runkle
Copy link
Member

I'm going to add this to v2.9 - this is something I'd like to work on, though it will take a back seat compared to performance concerns in the 2.9 sprint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants