-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Question
I was wondering what the best way to validate subclasses is?
Something along the sorts of
import pydantic
class MyClass:
pass
class MySubClass(MyClass):
pass
class MyOtherClass:
pass
class Foo(BaseModel):
a_class_not_an_object: Type[MyClass]where I would expect both
Foo(a_class_not_an_object=MyClass)
Foo(a_class_not_an_object=MySubClass)to work, but
Foo(a_class_not_an_object=MyOtherClass)to throw an error.
Is the way to go to implement a custom type or is there a way pydantic supports this out-of-the-box?
Have a good weekend :)