Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsuported operands reported for type union operator despite future import #1619

Open
NeilGirdhar opened this issue Apr 23, 2024 · 3 comments

Comments

@NeilGirdhar
Copy link

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]'
@NeilGirdhar
Copy link
Author

Python 3.9 is end-of-life in 1.5 years.

@cgarciae
Copy link

This works on Python 3.9.18, I think CI tests on the latests 3.9.x version too.

@NeilGirdhar
Copy link
Author

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants