[red-knot] mdtest suite: formatting and cleanup (#13806)

Minor cleanup and consistent formatting of the Markdown-based tests.

- Removed lots of unnecessary `a`, `b`, `c`, … variables.
- Moved test assertions (`# revealed:` comments) closer to the tested
object.
- Always separate `# revealed` and `# error` comments from the code by
two spaces, according to the discussion
[here](https://github.com/astral-sh/ruff/pull/13746/files#r1799385758).
This trades readability for consistency in some cases.
- Fixed some headings
This commit is contained in:
David Peter
2024-10-18 11:07:53 +02:00
committed by GitHub
parent f80528fbf2
commit c2f7c39987
44 changed files with 289 additions and 468 deletions

View File

@@ -14,8 +14,7 @@ class Identity:
def __class_getitem__(cls, item: int) -> str:
return item
a = Identity[0]
reveal_type(a) # revealed: str
reveal_type(Identity[0]) # revealed: str
```
## Class getitem union
@@ -31,8 +30,7 @@ class Identity:
def __class_getitem__(cls, item: int) -> int:
return item
a = Identity[0]
reveal_type(a) # revealed: str | int
reveal_type(Identity[0]) # revealed: str | int
```
## Class getitem with class union
@@ -53,9 +51,8 @@ if flag:
else:
a = Identity2
b = a[0]
reveal_type(a) # revealed: Literal[Identity1, Identity2]
reveal_type(b) # revealed: str | int
reveal_type(a) # revealed: Literal[Identity1, Identity2]
reveal_type(a[0]) # revealed: str | int
```
## Class getitem with unbound method union
@@ -70,8 +67,8 @@ if flag:
else:
class Identity: pass
a = Identity[42] # error: [call-non-callable] "Method `__class_getitem__` of type `Literal[__class_getitem__] | Unbound` is not callable on object of type `Literal[Identity, Identity]`"
reveal_type(a) # revealed: str | Unknown
a = Identity[42] # error: [call-non-callable] "Method `__class_getitem__` of type `Literal[__class_getitem__] | Unbound` is not callable on object of type `Literal[Identity, Identity]`"
reveal_type(a) # revealed: str | Unknown
```
## TODO: Class getitem non-class union
@@ -86,7 +83,7 @@ if flag:
else:
Identity = 1
a = Identity[42] # error: "Cannot subscript object of type `Literal[Identity] | Literal[1]` with no `__getitem__` method"
a = Identity[42] # error: "Cannot subscript object of type `Literal[Identity] | Literal[1]` with no `__getitem__` method"
# TODO: should _probably_ emit `str | Unknown`
reveal_type(a) # revealed: Unknown
reveal_type(a) # revealed: Unknown
```