Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mypy is not looking inside Python's any() #6024

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
alkamid opened this issue Dec 7, 2018 · 1 comment
Closed

mypy is not looking inside Python's any() #6024

alkamid opened this issue Dec 7, 2018 · 1 comment

Comments

@alkamid
Copy link

alkamid commented Dec 7, 2018

(mypy-0.641, Python 3.6.7)

from typing import Optional

def test_1(inp1: Optional[int] = None, inp2: Optional[int] = None) -> None:
    if any(attribute is None for attribute in (inp1, inp2)):
        pass
    else:
        if inp1 <= 0:
            print('<=0')

I am expecting type checking for the above function to work the same as for the one below:

def test_2(inp1: Optional[int] = None, inp2: Optional[int] = None) -> None:
    if inp1 is None or inp2 is None:
        pass
    else:
        if inp1 <= 0:
            print('<=0')

i.e. in the else block, the None case should be excluded and inp1 type should be inferred as int. Instead, mypy says (only for test_1()):

mypytest.py:7: error: Unsupported operand types for >= ("int" and "None")
mypytest.py:7: note: Left operand is of type "Optional[int]"

Is this something which should be easily fixed, or am I overlooking some edge cases?

@ilevkivskyi
Copy link
Member

This is similar to #2980, and probably also low priority, since this form is not used often.

Also #4573 is related.

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

3 participants