pytype
pytype copied to clipboard
`__future__.annotations` not triggering support for union-pipes (PEP 604)
This code runs in Py 3.8+:
from __future__ import annotations
def foo(opt: str | None): ...
But fails type-checking with pytype -V 3.8 (or 3.9), (No attribute '__or__' on 'str: Type[str]' or '__ror__' on 'None: None')
@Solumin pointed out:
PEP 604 (the
|PEP) explicitly says PEP 563 (the__future__ annotationsPEP) is sufficient for supporting PEP 604: https://peps.python.org/pep-0604/#change-only-pep-484-type-hints-to-accept-the-syntax-type1-type2
I think the decision was that "we probably should fix that", so here's a bug.