Comments (3)
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.
from dirty-equals.
That's changing in V2, also the __eq__
logic shouldn't affect the IsInstance()
check.
from dirty-equals.
That's changing in V2
Indeed, A() == IsInstance(A)
is True with pydantic V2.
also the
__eq__
logic shouldn't affect theIsInstance()
check.
Not sure what you mean here, but it makes sense that the old BaseModel.__eq__
prevented IsInstance
from working since it doesn't go through the usual NotImplemented
pattern. It evaluates self.dict() == other
which leads to IsInstance
checking if a dict
is an instance of a model class. So I think it's impossible to fix this for pydantic v1 without changes to pydantic v1 or some monkeypatching here.
from dirty-equals.
Related Issues (20)
- PyPy3.9 7.3.10 test regression: tests/test_inspection.py::test_has_attributes[-HasAttributes(a=1, b=2, spam=AnyThing)] HOT 3
- dirty isinstance HOT 5
- `IsFloat` should have an `exact` argument
- A way to ensure that all elements in a sequence match constraint HOT 2
- `IsDataclass` type HOT 4
- DeprecationWarning for datetime.utcfromtimestamp() in Python 3.12 HOT 2
- IsUrl seems to be broken with pydantic-2 HOT 7
- objects with multiline repr cause pytest to print a diff HOT 4
- Lacking a dirty way to count elements HOT 6
- 0.7.0 was not published to PyPI HOT 3
- `IsJson(*)` and `IsUUID(*)` reprs can't be evaluated HOT 2
- Makefile command for testing in local development HOT 1
- How to assert list of dict? HOT 2
- 0.7.0: pytest test suite not ready for `pydantic` 2.x HOT 1
- Enforce clearer usage of `IsList()` etc. with no arguments HOT 1
- test_is_datetime fails on alpine linux edge x86_64 HOT 3
- RFE: use `zoneinfo` instead of `pytz` HOT 3
- Weird import conflict with xarray and typing-extensions on Python 3.8 HOT 3
- Maintenance status of dirty_equals? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dirty-equals.