mirror of https://github.com/astral-sh/ruff
clean up mdtest
This commit is contained in:
parent
eaba8bc61e
commit
6ddf729864
|
|
@ -10,54 +10,42 @@ The `# ↓ hover:` syntax lets us assert the type at a specific column position.
|
||||||
indicates the column where we want to check the type.
|
indicates the column where we want to check the type.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def test_basic_types() -> None:
|
def test_basic_types(parameter: int) -> None:
|
||||||
# Test basic literals
|
|
||||||
number = 10
|
|
||||||
# ↓ hover: Literal[10]
|
|
||||||
number
|
|
||||||
|
|
||||||
text = "hello"
|
|
||||||
# ↓ hover: Literal["hello"]
|
|
||||||
text
|
|
||||||
|
|
||||||
# Test variables with type annotations
|
|
||||||
annotated: int = 42
|
|
||||||
# ↓ hover: int
|
# ↓ hover: int
|
||||||
annotated
|
parameter
|
||||||
|
|
||||||
|
# ↓ hover: Literal[10]
|
||||||
|
number = 10
|
||||||
|
|
||||||
|
# ↓ hover: Literal["hello"]
|
||||||
|
text = "hello"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Hover on different expression types
|
## Hovering on different expression types
|
||||||
|
|
||||||
### Literals
|
### Literals
|
||||||
|
|
||||||
```py
|
```py
|
||||||
# Integer literal (standalone expression statement)
|
|
||||||
# ↓ hover: Literal[42]
|
# ↓ hover: Literal[42]
|
||||||
value1 = 42
|
int_value = 42
|
||||||
|
|
||||||
# String literal
|
|
||||||
# ↓ hover: Literal["test"]
|
# ↓ hover: Literal["test"]
|
||||||
value2 = "test"
|
string_value = "test"
|
||||||
|
|
||||||
# Boolean literal
|
|
||||||
# ↓ hover: Literal[True]
|
# ↓ hover: Literal[True]
|
||||||
value3 = True
|
bool_value = True
|
||||||
```
|
```
|
||||||
|
|
||||||
### Names and attributes
|
### Names and attributes
|
||||||
|
|
||||||
```py
|
```py
|
||||||
class MyClass:
|
class MyClass:
|
||||||
value: int = 10
|
value: int
|
||||||
|
|
||||||
def test_attributes() -> None:
|
def test_attributes(instance: MyClass) -> None:
|
||||||
instance = MyClass()
|
|
||||||
|
|
||||||
# Hover on simple name
|
|
||||||
# ↓ hover: MyClass
|
# ↓ hover: MyClass
|
||||||
instance
|
instance
|
||||||
|
|
||||||
# Hover on attribute access
|
|
||||||
# ↓ hover: int
|
# ↓ hover: int
|
||||||
instance.value
|
instance.value
|
||||||
```
|
```
|
||||||
|
|
@ -65,32 +53,18 @@ def test_attributes() -> None:
|
||||||
### Function definitions
|
### Function definitions
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def get_number() -> int:
|
def f(x: int) -> None: ...
|
||||||
return 42
|
|
||||||
|
|
||||||
# Hover on a function name shows its type
|
# ↓ hover: def f(x: int) -> None
|
||||||
# ↓ hover: def get_number() -> int
|
result = f
|
||||||
result = get_number
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Binary operations
|
### Binary operations
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def test_binary_ops() -> None:
|
# ↓ hover: Literal[10]
|
||||||
first = 10
|
# ↓ hover: Literal[20]
|
||||||
second = 20
|
result = 10 + 20
|
||||||
|
|
||||||
# Hover on left operand
|
|
||||||
# ↓ hover: Literal[10]
|
|
||||||
first + second
|
|
||||||
|
|
||||||
# Hover on right operand
|
|
||||||
# ↓ hover: Literal[20]
|
|
||||||
first + second
|
|
||||||
|
|
||||||
# Hover on the entire binary expression
|
|
||||||
# ↓ hover: Literal[30]
|
|
||||||
first + second
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Comprehensions
|
### Comprehensions
|
||||||
|
|
@ -103,43 +77,40 @@ result = [x for x in range(5)]
|
||||||
|
|
||||||
## Edge cases
|
## Edge cases
|
||||||
|
|
||||||
### Hover near start of expression
|
### Multiple hovers on the same line
|
||||||
|
|
||||||
```py
|
|
||||||
# The down arrow must point to a character within the expression
|
|
||||||
# ↓ hover: Literal[1]
|
|
||||||
value = 1 + 2
|
|
||||||
```
|
|
||||||
|
|
||||||
### Hover with unicode characters
|
|
||||||
|
|
||||||
```py
|
|
||||||
def test_unicode() -> None:
|
|
||||||
# Variable name with unicode
|
|
||||||
café = "coffee"
|
|
||||||
# ↓ hover: Literal["coffee"]
|
|
||||||
café
|
|
||||||
|
|
||||||
# String literal with unicode
|
|
||||||
# ↓ hover: Literal["hello 世界"]
|
|
||||||
result = "hello 世界"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Multiple hovers on the same line
|
|
||||||
|
|
||||||
We can have multiple hover assertions for different positions on the same line:
|
We can have multiple hover assertions for different positions on the same line:
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def multiple_hovers() -> None:
|
# ↓ hover: Literal[1]
|
||||||
# Multiple hovers on literals in one expression
|
# ↓ hover: Literal[2]
|
||||||
# ↓ hover: Literal[1]
|
# ↓ hover: Literal[3]
|
||||||
# ↓ hover: Literal[2]
|
total = 1 + 2 + 3
|
||||||
# ↓ hover: Literal[3]
|
|
||||||
total = 1 + 2 + 3
|
|
||||||
|
|
||||||
# Multiple hovers in function call arguments
|
# ↓ hover: Literal[5]
|
||||||
# ↓ hover: Literal[5]
|
# ↓ hover: Literal[3]
|
||||||
# ↓ hover: Literal[3]
|
result = max(5, 3)
|
||||||
result = max(5, 3)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Hovering works on every character in expression
|
||||||
|
|
||||||
|
```py
|
||||||
|
def _(param: bool) -> None:
|
||||||
|
# ↓ hover: bool
|
||||||
|
# ↓ hover: bool
|
||||||
|
# ↓ hover: bool
|
||||||
|
# ↓ hover: bool
|
||||||
|
# ↓ hover: bool
|
||||||
|
result = param
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hovering with unicode characters
|
||||||
|
|
||||||
|
```py
|
||||||
|
def _(café: str) -> None:
|
||||||
|
# ↓ hover: str
|
||||||
|
# ↓ hover: str
|
||||||
|
# ↓ hover: str
|
||||||
|
# ↓ hover: str
|
||||||
|
result = café
|
||||||
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue