Define __instancecheck__
on constrained-type metaclasses, to support isinstance()
semantics
#2508
Zac-HD
started this conversation in
Feature Request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hypothesis has a test that for all types that have a registered strategy, the generated examples are instances of that type. However, this is not true for Pydantic's custom types... yet. For example:
The trick is to define the
__instancecheck__
magic method, which can be used to customise the behaviour ofisinstance()
- in this case, by treating standard int, float, str, etc. instances as instances of the constrained types if they happen to match the constraints.Beta Was this translation helpful? Give feedback.
All reactions