Skip to content

Arithmetic operations with None not detected without strict-optional #3121

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

Closed
pkch opened this issue Apr 3, 2017 · 4 comments
Closed

Arithmetic operations with None not detected without strict-optional #3121

pkch opened this issue Apr 3, 2017 · 4 comments

Comments

@pkch
Copy link
Contributor

pkch commented Apr 3, 2017

(Based on #3111)

Without --strict-optional, some invalid None opertations are undetected:

None + 1 # ok
None * 1 # ok
None / 1 # ok
None - 1 # ok

None + '' # error
None * '' # ok
None / '' # error
None - '' # error

With --strict-optional, all of them fail type check but with inconsistent error messages:

Unsupported operand types for + (None and "int")
Unsupported operand types for * (None and "int")
Unsupported operand types for / (None and "int")
Unsupported operand types for - (None and "int")
Unsupported left operand type for + (None)
Unsupported operand types for * (None and "str")
Unsupported left operand type for / (None)
Unsupported left operand type for - (None)
@ilevkivskyi
Copy link
Member

The plan is to make --strict-optional turned on by default, so that the first part does not need to be fixed. However, the error messages could be more homogeneous indeed.

@pkch
Copy link
Contributor Author

pkch commented Apr 4, 2017

Then I guess we should fix a few tests because everyone likes to put None + 1 as an example of what should fail (like in testTypeCheckNamedModule2, testMypyConditional, etc.). Or are we going to start running tests with --strict-optional in the next few days?

@ilevkivskyi
Copy link
Member

Or are we going to start running tests with --strict-optional in the next few days?

No, this is rather a long-term goal. However, there are dedicated tests for this flag: check-optional.test

@msullivan
Copy link
Collaborator

Strict optional is the default now, so I'm going to say this is "working as intended"

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

No branches or pull requests

4 participants