[red-knot] Format mdtest Python snippets more concisely (#13905)
This commit is contained in:
@@ -28,7 +28,6 @@ reveal_type(y) # revealed: Unknown
|
||||
```py
|
||||
def int_instance() -> int: ...
|
||||
|
||||
|
||||
a = b"abcde"[int_instance()]
|
||||
# TODO: Support overloads... Should be `bytes`
|
||||
reveal_type(a) # revealed: @Todo
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
```py
|
||||
class NotSubscriptable: ...
|
||||
|
||||
|
||||
a = NotSubscriptable[0] # error: "Cannot subscript object of type `Literal[NotSubscriptable]` with no `__class_getitem__` method"
|
||||
```
|
||||
|
||||
@@ -16,7 +15,6 @@ class Identity:
|
||||
def __class_getitem__(cls, item: int) -> str:
|
||||
return item
|
||||
|
||||
|
||||
reveal_type(Identity[0]) # revealed: str
|
||||
```
|
||||
|
||||
@@ -25,19 +23,16 @@ reveal_type(Identity[0]) # revealed: str
|
||||
```py
|
||||
flag = True
|
||||
|
||||
|
||||
class UnionClassGetItem:
|
||||
if flag:
|
||||
|
||||
def __class_getitem__(cls, item: int) -> str:
|
||||
return item
|
||||
|
||||
else:
|
||||
|
||||
def __class_getitem__(cls, item: int) -> int:
|
||||
return item
|
||||
|
||||
|
||||
reveal_type(UnionClassGetItem[0]) # revealed: str | int
|
||||
```
|
||||
|
||||
@@ -46,17 +41,14 @@ reveal_type(UnionClassGetItem[0]) # revealed: str | int
|
||||
```py
|
||||
flag = True
|
||||
|
||||
|
||||
class A:
|
||||
def __class_getitem__(cls, item: int) -> str:
|
||||
return item
|
||||
|
||||
|
||||
class B:
|
||||
def __class_getitem__(cls, item: int) -> int:
|
||||
return item
|
||||
|
||||
|
||||
x = A if flag else B
|
||||
|
||||
reveal_type(x) # revealed: Literal[A, B]
|
||||
@@ -69,16 +61,13 @@ reveal_type(x[0]) # revealed: str | int
|
||||
flag = True
|
||||
|
||||
if flag:
|
||||
|
||||
class Spam:
|
||||
def __class_getitem__(self, x: int) -> str:
|
||||
return "foo"
|
||||
|
||||
else:
|
||||
|
||||
class Spam: ...
|
||||
|
||||
|
||||
# error: [call-non-callable] "Method `__class_getitem__` of type `Literal[__class_getitem__] | Unbound` is not callable on object of type `Literal[Spam, Spam]`"
|
||||
# revealed: str | Unknown
|
||||
reveal_type(Spam[42])
|
||||
@@ -90,7 +79,6 @@ reveal_type(Spam[42])
|
||||
flag = True
|
||||
|
||||
if flag:
|
||||
|
||||
class Eggs:
|
||||
def __class_getitem__(self, x: int) -> str:
|
||||
return "foo"
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
```py
|
||||
class NotSubscriptable: ...
|
||||
|
||||
|
||||
a = NotSubscriptable()[0] # error: "Cannot subscript object of type `NotSubscriptable` with no `__getitem__` method"
|
||||
```
|
||||
|
||||
@@ -15,7 +14,6 @@ a = NotSubscriptable()[0] # error: "Cannot subscript object of type `NotSubscri
|
||||
class NotSubscriptable:
|
||||
__getitem__ = None
|
||||
|
||||
|
||||
a = NotSubscriptable()[0] # error: "Method `__getitem__` of type `None` is not callable on object of type `NotSubscriptable`"
|
||||
```
|
||||
|
||||
@@ -26,7 +24,6 @@ class Identity:
|
||||
def __getitem__(self, index: int) -> int:
|
||||
return index
|
||||
|
||||
|
||||
reveal_type(Identity()[0]) # revealed: int
|
||||
```
|
||||
|
||||
@@ -35,18 +32,15 @@ reveal_type(Identity()[0]) # revealed: int
|
||||
```py
|
||||
flag = True
|
||||
|
||||
|
||||
class Identity:
|
||||
if flag:
|
||||
|
||||
def __getitem__(self, index: int) -> int:
|
||||
return index
|
||||
|
||||
else:
|
||||
|
||||
def __getitem__(self, index: int) -> str:
|
||||
return str(index)
|
||||
|
||||
|
||||
reveal_type(Identity()[0]) # revealed: int | str
|
||||
```
|
||||
|
||||
@@ -25,7 +25,6 @@ reveal_type(b) # revealed: Unknown
|
||||
```py
|
||||
def int_instance() -> int: ...
|
||||
|
||||
|
||||
a = "abcde"[int_instance()]
|
||||
# TODO: Support overloads... Should be `str`
|
||||
reveal_type(a) # revealed: @Todo
|
||||
|
||||
Reference in New Issue
Block a user