microsoft / pyright

Static Type Checker for Python
Other
13.48k stars 1.48k forks source link

"Alternative syntax for unions requires Python 3.10 or newer" error when `__future__.annotations` is imported and pyright type checking is disabled #6157

Closed DetachHead closed 1 year ago

DetachHead commented 1 year ago

Describe the bug i'm using an alternate type checker (basedmypy) that supports additional features such as tuple literal types, which is why i have pylance type checking disabled. however it seems that some errors such as this one are still displayed regardless of that setting

IMO these kinds of errors should not appear when pyright type checking is disabled. see https://github.com/microsoft/pyright/issues/5451#issuecomment-1631861106:

i believe there are many more errors that could be moved as well (i assume https://github.com/microsoft/pylance-release/issues/2982 was the same issue). imo only errors that prevent any further analysis of the file (eg. syntax errors) should be displayed when type checking is disabled. i'll raise separate issues as i encounter them

not only for the purpose of using non-standard type checkers, there are other situations where i've had code that normal mypy was happy with but pyright wasn't

Code or Screenshots

from __future__ import annotations

foo: (int | str, int | str) = (1, 1)

image

VS Code extension or command-line pylance v2023.10.21

erictraut commented 1 year ago

You are using a type annotation syntax that is not allowed by the current typing standard. If you want to work with the typing community to standardize new syntax forms, you're welcome to do so. Pyright is a standards-based type checker and follows the rules and conventions established by the Python static typing community. If you want to use pyright, you'll need to stick to the current typing standard. I've made some small accommodations for you in the past, but I really don't have patience to make additional accommodations, especially when you've shown no willingness to work with the typing community and have continued to pursue your own path.

The proper way to annotate this type using the current typing standard is tuple[int | str, int | str].