Skip to content

Commit 09db380

Browse files
authored
Apply ruff formatting to mdtests (#22935)
- Updated the `prek` hook to replace `blacken-docs` with ruff - Added some formatting directives to preserve obvious intentional formatting choices - Made some choice edits to content for better readability with new format - Formatted md tests and updated snapshots
1 parent c29a837 commit 09db380

65 files changed

Lines changed: 1321 additions & 1351 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,23 @@ repos:
115115
)$
116116
priority: 1
117117

118-
# Priority 2: blacken-docs runs after markdownlint-fix (both modify markdown).
119-
- repo: https://github.com/adamchainz/blacken-docs
120-
rev: 1.20.0
118+
# Priority 2: ruffen-docs runs after markdownlint-fix (both modify markdown).
119+
- repo: https://github.com/astral-sh/ruff-pre-commit
120+
rev: v0.15.1
121121
hooks:
122-
- id: blacken-docs
123-
language: python # means renovate will also update `additional_dependencies`
124-
args: ["--pyi", "--line-length", "130"]
125-
files: '^crates/.*/resources/mdtest/.*\.md'
126-
exclude: |
127-
(?x)^(
128-
.*?invalid(_.+)*_syntax\.md
129-
)$
130-
additional_dependencies:
131-
- black==26.1.0
122+
- id: ruff-format
123+
name: mdtest format
124+
args:
125+
[
126+
"--preview",
127+
"--line-length",
128+
"130",
129+
"--extension",
130+
"py:pyi,python:pyi",
131+
]
132+
types_or: [markdown]
133+
files: '^crates/.*/resources/mdtest/.*\.md$'
134+
pass_filenames: true
132135
priority: 2
133136

134137
# `actionlint` hook, for verifying correct syntax in GitHub Actions workflows.

crates/ty_python_semantic/resources/mdtest/annotations/deferred.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
```pyi
88
def get_foo() -> Foo: ...
9+
910
class Foo: ...
1011
```
1112

@@ -256,7 +257,6 @@ Forward references in class keyword arguments are allowed in stub files.
256257

257258
```pyi
258259
class Foo(metaclass=SomeMeta): ...
259-
260260
class SomeMeta(type): ...
261261
```
262262

crates/ty_python_semantic/resources/mdtest/annotations/self.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ bound at `C.f`.
860860
from typing import Self
861861
from ty_extensions import generic_context
862862

863-
class C[T]():
863+
class C[T](): # fmt:skip
864864
def f(self: Self):
865865
def b(x: Self):
866866
reveal_type(x) # revealed: Self@f

crates/ty_python_semantic/resources/mdtest/annotations/string.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def f1(
8787
h: """int""",
8888
# error: [byte-string-type-annotation] "Type expressions cannot use bytes literal"
8989
i: "b'int'",
90-
):
90+
): # fmt:skip
9191
reveal_type(a) # revealed: Unknown
9292
reveal_type(b) # revealed: Unknown
9393
reveal_type(c) # revealed: Unknown
@@ -104,7 +104,7 @@ def f1(
104104
```py
105105
from typing import Literal
106106

107-
def f(v: Literal["a", r"b", b"c", "d" "e", "\N{LATIN SMALL LETTER F}", "\x67", """h"""]):
107+
def f(v: Literal["a", r"b", b"c", "d" "e", "\N{LATIN SMALL LETTER F}", "\x67", """h"""]): # fmt:skip
108108
reveal_type(v) # revealed: Literal["a", "b", "de", "f", "g", "h", b"c"]
109109
```
110110

crates/ty_python_semantic/resources/mdtest/assignment/annotations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ reveal_type(x) # revealed: Foo
399399

400400
```pyi
401401
x: int = 1
402-
reveal_type(x) # revealed: Literal[1]
402+
reveal_type(x) # revealed: Literal[1]
403403
```
404404

405405
## Annotations influence generic call inference

crates/ty_python_semantic/resources/mdtest/assignment/augmented.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def _(flag: bool):
6060
if flag:
6161
def __iadd__(self, other: int) -> str:
6262
return "Hello, world!"
63+
6364
else:
6465
def __iadd__(self, other: int) -> int:
6566
return 42

crates/ty_python_semantic/resources/mdtest/call/abstract_method.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ class Foo(ABC):
225225
@classmethod
226226
@abstractmethod
227227
def classmethod(cls) -> int: ...
228-
229228
@staticmethod
230229
@abstractmethod
231230
def staticmethod() -> int: ...

crates/ty_python_semantic/resources/mdtest/call/constructor.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def _(flag: bool) -> None:
114114
class Foo:
115115
if flag:
116116
def __new__(cls, x: int): ...
117+
117118
else:
118119
def __new__(cls, x: int, y: int = 1): ...
119120

@@ -320,6 +321,7 @@ def _(flag: bool) -> None:
320321
class Foo:
321322
if flag:
322323
def __init__(self, x: int): ...
324+
323325
else:
324326
def __init__(self, x: int, y: int = 1): ...
325327

crates/ty_python_semantic/resources/mdtest/call/dunder.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def _(flag: bool):
220220
if flag:
221221
def __getitem__(self, key: int) -> str:
222222
return str(key)
223+
223224
else:
224225
def __getitem__(self, key: int) -> bytes:
225226
return bytes()

crates/ty_python_semantic/resources/mdtest/call/overloads.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ class SomeEnum(Enum):
428428
B = 2
429429
C = 3
430430

431-
432431
class A: ...
433432
class B: ...
434433
class C: ...
@@ -1494,19 +1493,16 @@ class B: ...
14941493
def f1(x: int) -> A: ...
14951494
@overload
14961495
def f1(x: Any, y: Any) -> A: ...
1497-
14981496
@overload
14991497
def f2(x: int) -> A: ...
15001498
@overload
15011499
def f2(x: Any, y: Any) -> B: ...
1502-
15031500
@overload
15041501
def f3(x: int) -> A: ...
15051502
@overload
15061503
def f3(x: Any, y: Any) -> A: ...
15071504
@overload
15081505
def f3(x: Any, y: Any, *, z: str) -> B: ...
1509-
15101506
@overload
15111507
def f4(x: int) -> A: ...
15121508
@overload
@@ -1550,14 +1546,12 @@ def f1(x1: T1, x2: T2, /) -> tuple[T1, T2]: ...
15501546
def f1(x1: T1, x2: T2, x3: T3, /) -> tuple[T1, T2, T3]: ...
15511547
@overload
15521548
def f1(*args: Any) -> tuple[Any, ...]: ...
1553-
15541549
@overload
15551550
def f2(x1: T1) -> tuple[T1]: ...
15561551
@overload
15571552
def f2(x1: T1, x2: T2) -> tuple[T1, T2]: ...
15581553
@overload
15591554
def f2(*args: Any, **kwargs: Any) -> tuple[Any, ...]: ...
1560-
15611555
@overload
15621556
def f3(x: T1) -> tuple[T1]: ...
15631557
@overload

0 commit comments

Comments
 (0)