-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
IsInstance
does not work for Pydantic BaseModels
#61
Comments
Ah, I see now that pydantic does def __eq__(self, other: Any) -> bool:
if isinstance(other, BaseModel):
return self.dict() == other.dict()
else:
return self.dict() == other So it will do the dict equality check instead. So in the other order, it works: print(IsInstance(A) == A()) # True
print(IsInstance[A] == A()) # True I guess it can't really be changed, unless you were like the maintainer of pydantic or something (😉) and I'd doubt they would ever do that because It would break a lot of peoples code. Feel free to close the issue, I'll leave it up so you can decide if there should be something in the documentation about this. |
That's changing in V2, also the |
Indeed,
Not sure what you mean here, but it makes sense that the old |
It seems like
IsInstance
will never be equal to a pydantic model:Interestingly enough it works perfectly with
IsPartialDict
:Maybe it's also nice to document that
IsPartialDict
works with pydantic models without having to callmodel_instance.dict()
?Tested with dirty-equals version 0.50 and pydantic versions 1.9.0 and 1.10.7.
The text was updated successfully, but these errors were encountered: