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

S(0)==False->True (should be False) #26519

Open
NamDuong2 opened this issue Apr 19, 2024 · 5 comments
Open

S(0)==False->True (should be False) #26519

NamDuong2 opened this issue Apr 19, 2024 · 5 comments
Labels

Comments

@NamDuong2
Copy link

def __eq__(self, other):

@smichr smichr changed the title I don't understand why S(0)==False is True, the statement if not isinstanceof(other, Number), in this case other is False, so statement will return False, why result is True here? S(0)==False->True (should be False) Apr 19, 2024
@smichr smichr added the core label Apr 19, 2024
@smichr
Copy link
Member

smichr commented Apr 19, 2024

If I am interpreting correctly, the code you cite should return False, so this must not be the code that is generating the True.

@NamDuong2
Copy link
Author

If I am interpreting correctly, the code you cite should return False, so this must not be the code that is generating the True.
But according to the source code, it said return True while it should be return False.
def eq(self, other):
try:
other = _sympify(other)
except SympifyError:
return NotImplemented
if not isinstance(other, Number):
# S(0) == S.false is False
# S(0) == False is True
return False

@asmeurer
Copy link
Member

This probably could be changed. I don't know if it would break anything. The reason it's like that is because the Python bool False really is equal to 0.

@NamDuong2
Copy link
Author

This probably could be changed. I don't know if it would break anything. The reason it's like that is because the Python bool False really is equal to 0.

I understand what you mean but my point is there seem to be a conflict in the code itself. Because if you call isintance(False, Number) will return False.

@asmeurer
Copy link
Member

I see. The problem is that Integer also defines __eq__, which is what gets used. We should clarify the desired behavior here and update the comments in the code.

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

No branches or pull requests

3 participants