Skip to content
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

Wrong repr? #42

Open
Kludex opened this issue Jun 1, 2022 · 2 comments
Open

Wrong repr? #42

Kludex opened this issue Jun 1, 2022 · 2 comments

Comments

@Kludex
Copy link

Kludex commented Jun 1, 2022

I have a items array, and then the problem is that _id is different, but the repr of price is not 79. Should this be supported?

E         -  'items': [{'_id': '5f3dbd00fa942fcc2d1053bc',
E         +  'items': [{'_id': ObjectId('629778b83406c5b07c9b0eb7'),
E         -             'price': IsPositiveInt(),
E         +             'price': 79,
@samuelcolvin
Copy link
Owner

humm, can you show a full example of the errror, I'm not quite sure if this is expected.

I assume you've seen this bit of the docs?

@alexmojaki
Copy link
Contributor

Simple reproduction:

from dirty_equals import IsPositive

x = [1, IsPositive()]
print(x == [1, 2])
print(x)

x = [3, IsPositive()]
print(x == [1, 2])
print(x)

Output:

True
[1, 2]
False
[3, IsPositive()]

In the second case, == short-circuits the list comparison after seeing 3 != 1 so IsPositive.__eq__ never gets called. That seems mosty likely to be the problem in this issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants