File tree Expand file tree Collapse file tree 6 files changed +11
-9
lines changed
crates/ty_python_semantic/resources/mdtest Expand file tree Collapse file tree 6 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -200,8 +200,7 @@ class Bar(Generic[T]):
200200class Baz (Bar[Self]): ...
201201
202202class MyMetaclass (type ):
203+ # TODO : reject the Self usage. because self cannot be used within a metaclass.
203204 def __new__ (cls ) -> Self:
204- # TODO : reject the Self usage and don't emit a return type diagnostic.
205- # error: [invalid-return-type]
206205 return super ().__new__ (cls )
207206```
Original file line number Diff line number Diff line change @@ -26,9 +26,7 @@ class C:
2626c_instance = C(1 )
2727
2828reveal_type(c_instance.inferred_from_value) # revealed: Unknown | Literal[1, "a"]
29-
30- # TODO : Same here. This should be `Unknown | Literal[1, "a"]`
31- reveal_type(c_instance.inferred_from_other_attribute) # revealed: Unknown
29+ reveal_type(c_instance.inferred_from_other_attribute) # revealed: Unknown | Literal[1, "a"]
3230
3331# There is no special handling of attributes that are (directly) assigned to a declared parameter,
3432# which means we union with `Unknown` here, since the attribute itself is not declared. This is
@@ -184,8 +182,7 @@ c_instance = C(1)
184182
185183reveal_type(c_instance.inferred_from_value) # revealed: Unknown | Literal[1, "a"]
186184
187- # TODO : Should be `Unknown | Literal[1, "a"]`
188- reveal_type(c_instance.inferred_from_other_attribute) # revealed: Unknown
185+ reveal_type(c_instance.inferred_from_other_attribute) # revealed: Unknown | Literal[1, "a"]
189186
190187reveal_type(c_instance.inferred_from_param) # revealed: Unknown | int | None
191188
Original file line number Diff line number Diff line change @@ -204,7 +204,8 @@ class C:
204204 return str (key)
205205
206206 def f (self ):
207- # TODO : This should emit an `invalid-assignment` diagnostic once we understand the type of `self`
207+ # TODO : Give a type assinament error instead of a shadowing error
208+ # error: [invalid-assignment] "Implicit shadowing of function `__getitem__`"
208209 self .__getitem__ = None
209210
210211# This is still fine, and simply calls the `__getitem__` method on the class
Original file line number Diff line number Diff line change @@ -278,6 +278,8 @@ class A[T]:
278278
279279class B[T](A[T]):
280280 def f (self , b : T) -> T:
281+ # TODO : handle typevars in super
282+ # error: [invalid-super-argument] "`Self` is not an instance or subclass of `<class 'B'>` in `super(<class 'B'>, Self)` call"
281283 return super ().f(b)
282284```
283285
Original file line number Diff line number Diff line change @@ -170,6 +170,8 @@ def f1(flag: bool):
170170 attr = DataDescriptor()
171171
172172 def f (self ):
173+ # TODO : Here we treat attr as if it's a data descriptor. But it should fallback to instance attribute.
174+ # error: [invalid-assignment] "Invalid assignment to data descriptor attribute `attr` on type `Self` with custom `__set__` method"
173175 self .attr = " normal"
174176
175177 reveal_type(C1().attr) # revealed: Unknown | Literal["data", "normal"]
Original file line number Diff line number Diff line change @@ -696,7 +696,8 @@ class Foo(Protocol):
696696 self .b: int = 128 # TODO : should emit diagnostic
697697
698698 def non_init_method (self ) -> None :
699- self .y = 64 # fine
699+ # TODO : should be fine
700+ self .y = 64 # error: [invalid-assignment] "Object of type `Literal[64]` is not assignable to attribute `y` of type `str`"
700701 self .c = 72 # TODO : should emit diagnostic
701702
702703# Note: the list of members does not include `a`, `b` or `c`,
You can’t perform that action at this time.
0 commit comments