mypy fails to recognize functions as generators when `sys.platform` is used in conditions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report using the gen.py example and run mypy on Linux, then compare the result with macOS behavior. Trace how the checker handles sys.platform conditions and generator functions; done means the example no longer reports a missing return statement on Linux without regressing the macOS result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100