-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
as designedNot a bug, working as intendedNot a bug, working as intended
Description
Describe the bug
Pyright does not report errors, when declaring the enum within the same file where it is being used. When importing the same enum from a different file, pyright reports an error.
To Reproduce
bar.py
from enum import Enum
from typing import Literal
# similar to https://github.com/python/typeshed/pull/7127/files
class _NoDefault(Enum):
no_default = "NO_DEFAULT"
no_default = _NoDefault.no_default # Sentinel indicating the default value.
NoDefault = Literal[_NoDefault.no_default]
def test(x: NoDefault = no_default):
...
pyright reports no errors for bar.py
foo.py
import bar
reveal_type(bar.NoDefault)
reveal_type(bar.no_default)
def test(x: bar.NoDefault = bar.no_default):
...
pyright reports:
3:13 - information: Type of "bar.NoDefault" is "Type[Literal[_NoDefault.no_default]]"
4:13 - information: Type of "bar.no_default" is "_NoDefault"
6:29 - error: Expression of type "_NoDefault" cannot be assigned to parameter of type "NoDefault"
Expected behavior
It seems that pyright has troubles inferring bar.no_default
, it should be bar._NoDefault.no_default
and not bar._NoDefault
.
Metadata
Metadata
Assignees
Labels
as designedNot a bug, working as intendedNot a bug, working as intended