@@ -56,8 +56,6 @@ Person(20, "Eve")
5656
5757## Signature of ` __init__ `
5858
59- TODO: All of the following tests are missing the ` self ` argument in the ` __init__ ` signature.
60-
6159Declarations in the class body are used to generate the signature of the ` __init__ ` method. If the
6260attributes are not just declarations, but also bindings, the type inferred from bindings is used as
6361the default value.
@@ -71,7 +69,7 @@ class D:
7169 y: str = " default"
7270 z: int | None = 1 + 2
7371
74- reveal_type(D.__init__ ) # revealed: (x: int, y: str = Literal["default"], z: int | None = Literal[3]) -> None
72+ reveal_type(D.__init__ ) # revealed: (self: D, x: int, y: str = Literal["default"], z: int | None = Literal[3]) -> None
7573```
7674
7775This also works if the declaration and binding are split:
@@ -82,7 +80,7 @@ class D:
8280 x: int | None
8381 x = None
8482
85- reveal_type(D.__init__ ) # revealed: (x: int | None = None) -> None
83+ reveal_type(D.__init__ ) # revealed: (self: D, x: int | None = None) -> None
8684```
8785
8886Non-fully static types are handled correctly:
@@ -96,7 +94,7 @@ class C:
9694 y: int | Any
9795 z: tuple[int , Any]
9896
99- reveal_type(C.__init__ ) # revealed: (x: Any, y: int | Any, z: tuple[int, Any]) -> None
97+ reveal_type(C.__init__ ) # revealed: (self: C, x: Any, y: int | Any, z: tuple[int, Any]) -> None
10098```
10199
102100Variables without annotations are ignored:
@@ -107,7 +105,7 @@ class D:
107105 x: int
108106 y = 1
109107
110- reveal_type(D.__init__ ) # revealed: (x: int) -> None
108+ reveal_type(D.__init__ ) # revealed: (self: D, x: int) -> None
111109```
112110
113111If attributes without default values are declared after attributes with default values, a
@@ -132,7 +130,7 @@ class D:
132130 y: ClassVar[str ] = " default"
133131 z: bool
134132
135- reveal_type(D.__init__ ) # revealed: (x: int, z: bool) -> None
133+ reveal_type(D.__init__ ) # revealed: (self: D, x: int, z: bool) -> None
136134
137135d = D(1 , True )
138136reveal_type(d.x) # revealed: int
@@ -150,7 +148,7 @@ class D:
150148 def y (self ) -> str :
151149 return " "
152150
153- reveal_type(D.__init__ ) # revealed: (x: int) -> None
151+ reveal_type(D.__init__ ) # revealed: (self: D, x: int) -> None
154152```
155153
156154And neither do nested class declarations:
@@ -163,7 +161,7 @@ class D:
163161 class Nested :
164162 y: str
165163
166- reveal_type(D.__init__ ) # revealed: (x: int) -> None
164+ reveal_type(D.__init__ ) # revealed: (self: D, x: int) -> None
167165```
168166
169167But if there is a variable annotation with a function or class literal type, the signature of
@@ -181,7 +179,7 @@ class D:
181179 class_literal: TypeOf[SomeClass]
182180 class_subtype_of: type[SomeClass]
183181
184- # revealed: (function_literal: def some_function() -> None, class_literal: <class 'SomeClass'>, class_subtype_of: type[SomeClass]) -> None
182+ # revealed: (self: D, function_literal: def some_function() -> None, class_literal: <class 'SomeClass'>, class_subtype_of: type[SomeClass]) -> None
185183reveal_type(D.__init__ )
186184```
187185
@@ -194,7 +192,7 @@ from typing import Callable
194192class D :
195193 c: Callable[[int ], str ]
196194
197- reveal_type(D.__init__ ) # revealed: (c: (int, /) -> str) -> None
195+ reveal_type(D.__init__ ) # revealed: (self: D, c: (int, /) -> str) -> None
198196```
199197
200198Implicit instance attributes do not affect the signature of ` __init__ ` :
@@ -209,7 +207,7 @@ class D:
209207
210208reveal_type(D(1 ).y) # revealed: str
211209
212- reveal_type(D.__init__ ) # revealed: (x: int) -> None
210+ reveal_type(D.__init__ ) # revealed: (self: D, x: int) -> None
213211```
214212
215213Annotating expressions does not lead to an entry in ` __annotations__ ` at runtime, and so it wouldn't
@@ -222,7 +220,7 @@ class D:
222220 (x): int = 1
223221
224222# TODO : should ideally not include a `x` parameter
225- reveal_type(D.__init__ ) # revealed: (x: int = Literal[1]) -> None
223+ reveal_type(D.__init__ ) # revealed: (self: D, x: int = Literal[1]) -> None
226224```
227225
228226## ` @dataclass ` calls with arguments
@@ -471,7 +469,7 @@ class C(Base):
471469 z: int = 10
472470 x: int = 15
473471
474- reveal_type(C.__init__ ) # revealed: (x: int = Literal[15], y: int = Literal[0], z: int = Literal[10]) -> None
472+ reveal_type(C.__init__ ) # revealed: (self: C, x: int = Literal[15], y: int = Literal[0], z: int = Literal[10]) -> None
475473```
476474
477475## Generic dataclasses
@@ -524,7 +522,7 @@ class UppercaseString:
524522class C :
525523 upper: UppercaseString = UppercaseString()
526524
527- reveal_type(C.__init__ ) # revealed: (upper: str = str) -> None
525+ reveal_type(C.__init__ ) # revealed: (self: C, upper: str = str) -> None
528526
529527c = C(" abc" )
530528reveal_type(c.upper) # revealed: str
@@ -570,7 +568,7 @@ class ConvertToLength:
570568class C :
571569 converter: ConvertToLength = ConvertToLength()
572570
573- reveal_type(C.__init__ ) # revealed: (converter: str = Literal[""]) -> None
571+ reveal_type(C.__init__ ) # revealed: (self: C, converter: str = Literal[""]) -> None
574572
575573c = C(" abc" )
576574reveal_type(c.converter) # revealed: int
@@ -609,7 +607,7 @@ class AcceptsStrAndInt:
609607class C :
610608 field: AcceptsStrAndInt = AcceptsStrAndInt()
611609
612- reveal_type(C.__init__ ) # revealed: (field: str | int = int) -> None
610+ reveal_type(C.__init__ ) # revealed: (self: C, field: str | int = int) -> None
613611```
614612
615613## ` dataclasses.field `
@@ -670,7 +668,7 @@ import dataclasses
670668class C :
671669 x: str
672670
673- reveal_type(C.__init__ ) # revealed: (x: str) -> None
671+ reveal_type(C.__init__ ) # revealed: (self: C, x: str) -> None
674672```
675673
676674### Dataclass with custom ` __init__ ` method
@@ -763,8 +761,7 @@ reveal_type(Person.__mro__) # revealed: tuple[<class 'Person'>, <class 'object'
763761The generated methods have the following signatures:
764762
765763``` py
766- # TODO : `self` is missing here
767- reveal_type(Person.__init__ ) # revealed: (name: str, age: int | None = None) -> None
764+ reveal_type(Person.__init__ ) # revealed: (self: Person, name: str, age: int | None = None) -> None
768765
769766reveal_type(Person.__repr__ ) # revealed: def __repr__(self) -> str
770767
0 commit comments