You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -321,8 +321,10 @@ a covariant generic, this is equivalent to using the upper bound of the type par
321
321
`object`):
322
322
323
323
```py
324
+
from typing import Self
325
+
324
326
class Covariant[T]:
325
-
defget(self) -> T:
327
+
defget(self: Self) -> T:
326
328
raiseNotImplementedError
327
329
328
330
def_(x: object):
@@ -335,11 +337,12 @@ Similarly, contravariant type parameters use their lower bound of `Never`:
335
337
336
338
```py
337
339
class Contravariant[T]:
338
-
defpush(self, x: T) -> None: ...
340
+
defpush(self: Self, x: T) -> None: ...
339
341
340
342
def_(x: object):
341
343
ifisinstance(x, Contravariant):
342
344
reveal_type(x) # revealed: Contravariant[Never]
345
+
# error: [invalid-argument-type] "Argument to bound method `push` is incorrect: Argument type `Contravariant[Never]` does not satisfy upper bound `Contravariant[T@Contravariant]` of type variable `Self`"
343
346
# error: [invalid-argument-type] "Argument to bound method `push` is incorrect: Expected `Never`, found `Literal[42]`"
344
347
x.push(42)
345
348
```
@@ -350,8 +353,8 @@ the type system, so we represent it with the internal `Top[]` special form.
0 commit comments