-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
pyright infers a property as Never after the property is referenced in an empty loop and the property is returning a Generic
Code or Screenshots
from typing import Generic, TypeVar, reveal_type
T = TypeVar("T", str, int)
class Index(Generic[T]):
def __init__(self, thelist: list[T]):
self.thelist = thelist
def __contains__(self, item: T) -> bool:
return item in self.thelist
class DataFrame:
@property
def columns(self) -> Index[str]: ...
@columns.setter
def columns(self, cols: list[str]) -> None: ...
df = DataFrame()
df.columns = ["a", "b", "c"]
reveal_type(df.columns) # Expected: Index[str]
for _ in ():
if "abc" in df.columns:
raise ValueError("not there")
reveal_type(df.columns) # Expected: Index[str] gets Neverpyright reports:
tstgennever.py
tstgennever.py:23:13 - information: Type of "df.columns" is "Index[str]"
tstgennever.py:29:13 - information: Type of "df.columns" is "Never"
Note that if the property is not a generic (i.e., just a list), it works fine. If the loop does not have the raise it works fine as well.
VS Code extension or command-line
python 3.11.14
pyrright 1.1.407 on command line with default settings
cmp0xff
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working