Skip to content
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

subprocess.Popen not generic before 3.9 #4948

Closed
scop opened this issue Jan 18, 2021 · 3 comments
Closed

subprocess.Popen not generic before 3.9 #4948

scop opened this issue Jan 18, 2021 · 3 comments

Comments

@scop
Copy link
Contributor

scop commented Jan 18, 2021

$ 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?

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jan 18, 2021

Use from __future__ import annotations

@scop
Copy link
Contributor Author

scop commented Jan 18, 2021

Oh, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants