ruff
4ab610a5 - [ty] Preserve Self in `__new__` calls (#27003)

Commit
74 days ago
[ty] Preserve Self in `__new__` calls (#27003) ## Summary Prior to this change, calling an inherited `__new__` implementation could lose `Self` and return `Unknown`. This caused us to miss invalid attribute access and broke chains of custom `__new__` implementations: ```py from typing import Self class Foo: ... class Bar(Foo): def __new__(cls) -> Self: return Foo.__new__(cls) class Baz(Bar): def __new__(cls) -> Self: result = Bar.__new__(cls) # Previously: Unknown result.nonexistent() # Previously: no diagnostic return result ``` This gives every unannotated `__new__` receiver an implicit `type[Self]`, matching the constructor typing specification and preserving `Self` through inherited calls. It also preserves existing generic constructor calls where the synthetic `cls` receiver would otherwise be specialized and checked twice. The regression coverage includes overloaded callbacks, signature-preserving and callable-protocol decorators, `Concatenate`, and aliased receiver types; the intentionally odd nested and `Concatenate` inference results remain documented as pre-existing limitations. Closes https://github.com/astral-sh/ty/issues/3965. --------- Co-authored-by: Carl Meyer <carl@astral.sh>
Author
Parents
Loading