Skip to content

subprocess.Popen not generic before 3.9 #4948

@scop

Description

@scop
$ python --version
Python 3.8.0
$ mypy --version
mypy 0.790
$ cat t.py 
from subprocess import Popen, PIPE

def foo(popen: Popen) -> None:
    pass

foo(Popen(["ls"], stdout=PIPE))
$ mypy --strict --python-version 3.8 t.py 
t.py:3: error: Missing type parameters for generic type "Popen"
Found 1 error in 1 file (checked 1 source file)
$ sed -i -e 's/popen: Popen/popen: Popen[bytes]/' t.py
$ mypy --strict --python-version 3.8 t.py 
Success: no issues found in 1 source file
$ python3.8 t.py
Traceback (most recent call last):
  File "t.py", line 3, in <module>
    def foo(popen: Popen[bytes]) -> None:
TypeError: 'type' object is not subscriptable

Following mypy's (run with python 3.8, in python version 3.8 mode) advise and adding type parameter for it makes the result actually not run with python 3.8 any more (with 3.9 it would be fine). I see Popen is marked generic in typeshed for all 3.x versions, and suppose that's the root cause for the issue; shouldn't it be marked as such only for >= 3.9?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions