Skip to content

mypy unhappy with from io import StringIO #385

@acdimalev

Description

@acdimalev

The simple statement from io import StringIO results in an error when running mypy checks.

$ coconut error.coco -s
Compiling         error.coco ...
Compiled to       error.py .
$ coconut error.coco -s --mypy
Compiling         error.coco ...
Compiled to       error.py .
error.py:22: error: Incompatible import of "StringIO" (imported name has type "Type[StringIO]", local name has type "T
ype[StringIO[Any]]")
$ cat error.coco
from io import StringIO

I did some investigation on this front. It looks like mypy is not terribly fond of imports in conditional blocks.

$ cat mypy-test-1.py
if False:
    from StringIO import StringIO
else:
    from io import StringIO
$ mypy --py2 mypy-test-1.py
mypy-test-1.py:4: error: Incompatible import of "StringIO" (imported name has type "Type[StringIO]", local name has type "Type[StringIO[Any]]")
$ 
$ cat mypy-test-2.py
from io import StringIO
$ mypy --py2 mypy-test-2.py
$ 
$ cat mypy-test-3.py
from StringIO import StringIO
from io import StringIO
$ mypy --py2 mypy-test-3.py
mypy-test-3.py:2: error: Incompatible import of "StringIO" (imported name has type "Type[StringIO]", local name has type "Type[StringIO[Any]]")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions