-
Notifications
You must be signed in to change notification settings - Fork 181
Closed
Description
In MyPy, to actually type an ellipsis, say for implementing __getitem__, you use the following weird construction (using Python 3.6 syntax, since that's what I'm actually using):
from typing import Union
def f(x: Union[int, "ellipsis"]) -> None:
pass
f(1)
f(...)This passes MyPy --strict. However, pyflakes (flake8 error code F821) is being too clever, can reports that ellipsis is an undefined. This should be a special case - it is a defined name when used in a string / string annotation. Personally, I think there should be a real base class for ellipsis in typing or something, but there isn't as far as I know (which is why the weird workaround above works).
PS: Same issue in string annotation mode, mypy --strict tmp.py --python-version 3.7 passes and pyflakes tmp.py fails:
from __future__ import annotations
def f(x: int | ellipsis) -> None:
pass
f(1)
f(...)Metadata
Metadata
Assignees
Labels
No labels