Override __subclasscheck__ on ModelMetaclass to avoid memory leak and performance issues by Viicos · Pull Request #11116 · pydantic/pydantic (original) (raw)

We avoid relying on ABCMeta.__subclasscheck__ unless we're pretty sure. Note that this was wrongly addressed as __instancecheck__ was implemented instead of __subclasscheck__. However, it is not clear if implementing __instancecheck__ fixed existing issues as well, so it is left as is.

Also changed the checked attribute to __pydantic_decorators__, as this is one of the first attributes being set on the class, and it might be that we change the way __pydantic_validator__ is set in the future (e.g. when defer_build is set, and if we don't implement mock validators anymore).

Fixes #11100.

Change Summary

Checklist