Skip to content

remove calls to __instancecheck__ on ModelValidator #497

Open
@samuelcolvin

Description

@samuelcolvin

As of #492 ModelValidator is checking if the input is an instance of BaseModel before doing anything else.

Because BaseModel is an abc, the isinstance rust call is eventually calling the python __instancecheck__ method on BaseModel's metatype.

isinstance checks have significant performance problems, see pydantic/pydantic#3829 and python/cpython#92810.

We should look at removing this check by implementing a faster isinstance check but just looking at the type, and the type's tp_base (or maybe tb_bases) - this would effectively lead to a fast_isinstance method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions