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

Direction of comparison operator in error message does not depend on direction in code #17460

Open
jevandezande opened this issue Jul 1, 2024 · 0 comments
Labels
bug mypy got something wrong priority-2-low

Comments

@jevandezande
Copy link

Bug Report

When encountering an error due to using a comparison operator with None as one of the arguments, Mypy adjusts the direction of < and > operators in its messages based on the types involved so that it always reports None as the second type (e.g. Unsupported operand types for {comparisson operator direction} ("int" and "None")). This becomes increasingly confusing when both variables in the comparison could potentially be a large number of types.

To reproduce

For the following code

1 < None
1 > None
None < 1
None > 1

Expected Behavior

file.py:1: error: Unsupported operand types for < ("int" and "None")  [operator]
file.py:2: error: Unsupported operand types for > ("int" and "None")  [operator]
file.py:3: error: Unsupported operand types for < ("None" and "int")  [operator]
file.py:4: error: Unsupported operand types for > ("None" and "int")  [operator]

Actual Behavior

file.py:1: error: Unsupported operand types for < ("int" and "None")  [operator]
file.py:2: error: Unsupported operand types for > ("int" and "None")  [operator]
file.py:3: error: Unsupported operand types for > ("int" and "None")  [operator]
file.py:4: error: Unsupported operand types for < ("int" and "None")  [operator]

Your Environment

  • Mypy version used: 1.10
  • Python version used: 3.12
@jevandezande jevandezande added the bug mypy got something wrong label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low
Projects
None yet
Development

No branches or pull requests

2 participants