8000 mypy fails to recognize functions as generators when `sys.platform` is used in conditions · Issue #5678 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

mypy fails to recognize functions as generators when sys.platform is used in conditions #5678

@marcinsulikowski

Description

@marcinsulikowski

mypy seems to be too thorough when interpreting if sys.platform == ... conditions. Consider the following file:

import sys
from typing import Generator

def f() -> Generator[int, None, None]:
    if sys.platform == "darwin":
        yield 1

I'm trying to run mypy for this file on Linux using mypy gen.py

Expected behavior:
mypy test passes for this file on Linux

Actual behavior:
I get this on Linux:

$ mypy gen.py 
gen.py:4: error: Missing return statement

At the same time, mypy on macOS does not complain. I think that this is related to #698

Platform information:

$ uname -sr; mypy --version; python --version
Linux 4.15.0-34-generic
mypy 0.630
Python 2.7.15rc1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0