-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#22584Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
The cls parameter of __new__ should be inferred as type[Self]. ty says it's Unknown
from typing import reveal_type
class C:
def __new__(cls):
reveal_type(cls)
return super().__new__(cls)- pyright:
Type of "cls" is "type[Self@C]" - ty:
Revealed type: Unknown (revealed-type) [Ln 6, Col 21] - mypy:
main.py:5: note: Revealed type is "type[__main__.C]"
My actual use case is code like this:
from typing import Self
class C:
def __new__(cls: type[Self], x: object) -> Self:
if type(x) is cls:
return x
return super().__new__(cls)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working