We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
isinstance(X, float)
bool
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
In the following example, adding an unrelated isinstance check causes the code to raise an error.
isinstance
To Reproduce
Code:
from typing import Union def get_type_name(value: Union[bool, str]) -> str: if value is True: return "Boolean" if value is False: return "Boolean" return "String"
Mypy output:
$ mypy --strict testcode.py Success: no issues found in 1 source file
Adding an isinstance(value, float) check:
isinstance(value, float)
from typing import Union def get_type_name(value: Union[bool, str]) -> str: if isinstance(value, float): # a completely unrelated check return "Number" if value is True: return "Boolean" if value is False: return "Boolean" return "String"
$ mypy --strict testcode.py testcode.py:5: error: Missing return statement testcode.py:9: error: Non-overlapping identity check (left operand type: "str", right operand type: "Literal[True]") testcode.py:11: error: Non-overlapping identity check (left operand type: "str", right operand type: "Literal[False]") Found 3 errors in 1 file (checked 1 source file)
Mypy says value is True and value is False are non overlapping checks, but it works:
value is True
value is False
$ python -i testcode.py >>> get_type_name(5.0) 'Number'
Your Environment
--strict
The text was updated successfully, but these errors were encountered:
This is probably because bool is a subclass of int (in reality) and int is a subclass of float (in the type system).
Sorry, something went wrong.
mypy could maybe have an option to pretend that bool isn't a subclass of int, in which case this is a duplicate of #8363
No branches or pull requests
In the following example, adding an unrelated
isinstance
check causes the code to raise an error.To Reproduce
Code:
Mypy output:
Adding an
isinstance(value, float)
check:Mypy output:
Mypy says
value is True
andvalue is False
are non overlapping checks, but it works:$ python -i testcode.py >>> get_type_name(5.0) 'Number'
Your Environment
--strict
The text was updated successfully, but these errors were encountered: