Unsuported operands reported for type union operator despite future import
NeilGirdhar opened this issue · comments
Neil Girdhar commented
On Python 3.9:
from __future__ import annotations
def f(x: None | str) -> None:
pass
gives
File "/home/neil/src/flax/a.py", line 2, in <module>: unsupported operand type(s) for |: 'None: None' and 'str: Type[str]' [unsupported-operands]
No attribute '__or__' on 'None: None' or '__ror__' on 'str: Type[str]'
Neil Girdhar commented
Python 3.9 is end-of-life in 1.5 years.
Cristian Garcia commented
This works on Python 3.9.18
, I think CI tests on the latests 3.9.x
version too.
Neil Girdhar commented
Hmm, that's not what I'm seeing?
❯ pyenv global 3.9.18
❯ pipgi pytype
pytype==2024.4.11
❯ cat a.py
from __future__ import annotations
def f(x: None | str) -> None:
pass
❯ pytype a.py
Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] check a
FAILED: /home/neil/src/.pytype/pyi/a.pyi
/home/neil/.pyenv/versions/3.9.18/bin/python3.9 -m pytype.main --imports_info /home/neil/src/.pytype/imports/a.imports --module-name a --platform linux -V 3.9 -o /home/neil/src/.pytype/pyi/a.pyi --analyze-annotated --nofail --quick /home/neil/src/a.py
File "/home/neil/src/a.py", line 2, in <module>: unsupported operand type(s) for |: 'None: None' and 'str: Type[str]' [unsupported-operands]
No attribute '__or__' on 'None: None' or '__ror__' on 'str: Type[str]'
For more details, see https://google.github.io/pytype/errors.html#unsupported-operands
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'