Ignore MyPy “is not valid as a type” error

1.8k Views Asked by At

I'm maintaining a Python 3.3 library. I've updated MyPy, and now I'm getting the “is not valid as a type” error.

The offending code is in the enum package, which I've vendored. In mypi.ini, I ignore all errors from that package, but the errors technically occur where I'm using Enum as a superclass in my own code.

Is there some way to reassure MyPy that Enum really is a type? I'd rather not add ignores all over my code.

Example:

from .vendor.python.enum import Enum

class ExampleEnum(Enum):
    Hello = 1

MyPy produces the following error:

st3/sublime_lib/footest.py:3: error: Variable "sublime_lib.vendor.python.enum.Enum" is not valid as a type
st3/sublime_lib/footest.py:3: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
0

There are 0 best solutions below