`typing-extensions`'s `sentinel` (all lowercase) is not recognized
PEP 661 was finalized an all-lowercase sentinel callable.
Because of that, typing_extensions added a lowercase element sentinel, along with the previously-defined Sentinel variant (for compatibility). (see https://github.com/python/typing_extensions/issues/742)
However, that lowercase sentinel element is not recognized by Pyright:
from typing_extensions import sentinel
MISSING = sentinel("MISSING")
def f(x: int | MISSING) -> int:
return 0 if x is MISSING else x
Running in a virtual environment on Python 3.12 using nodeenv-1.11.0 pyright-1.1.414 typing-extensions-4.16.0, running command-line pyright on that file prints the report below:
/xxx/sentinel_lowercase.py
/xxx/sentinel_lowercase.py:1:31 - error: "sentinel" is unknown import symbol (reportAttributeAccessIssue)
/xxx/sentinel_lowercase.py:5:16 - error: Variable not allowed in type expression (reportInvalidTypeForm)
Note that, as a workaround, replacing the first line with from typing_extensions import Sentinel as sentinel works.
I think this is already fixed on the main branch and we're just waiting on a new release of pyright.
Maintainers: could we get a new release?
2. I think this is already fixed on the main branch and we're just waiting on a new release of pyright. Maintainers: could we get a new release?
We're waiting till we release a stable version of Pylance again. There's nobody really using the 'main' bits of Pyright so we have been transferring the bits to Pylance in our prerelease bits to get some coverage there. Once we get enough coverage there, we'll release a new build of Pyright.
Yeah the bundled typeshed stubs on main use the lowercase form and assign Sentinel = sentinel. In #11896 I deleted the Python 3.15 test for sentinel and changed the existing version-agnostic test to use the sentinel form, so it would be preserved once that PR is merged.