File tree Expand file tree Collapse file tree 2 files changed +23
-12
lines changed Expand file tree Collapse file tree 2 files changed +23
-12
lines changed Original file line number Diff line number Diff line change
1
+ import subprocess
2
+ from pathlib import Path
3
+
4
+ # see https://github.com/astral-sh/ruff/pull/18224
5
+ from ruff .__main__ import ( # type: ignore[import-untyped] # pyright: ignore[reportMissingTypeStubs]
6
+ find_ruff_bin , # noqa: PLC2701
7
+ )
8
+
9
+
10
+ def ruff_format (source : str ) -> str :
11
+ result = subprocess .run (
12
+ [find_ruff_bin (), "format" , "-" ],
13
+ input = source ,
14
+ text = True ,
15
+ capture_output = True ,
16
+ check = True ,
17
+ cwd = Path .cwd (),
18
+ )
19
+ result .check_returncode ()
20
+ return result .stdout
Original file line number Diff line number Diff line change 36
36
37
37
sys .path .insert (0 , str (Path (__file__ ).parent .parent ))
38
38
39
+ from tool ._ruff import ruff_format
39
40
from tool .promotion import _typename as dtype_label
40
41
from tool .ufunc import _all_types as ufunc_signatures
41
42
@@ -249,13 +250,7 @@ def _array_expr(
249
250
250
251
expr2 = _array_expr_single (* (dts [1 ] for dts in dtypess ), ndim = ndim , npt = npt )
251
252
252
- expr = f"tuple[{ expr1 } , { expr2 } ]"
253
- if "\n " in expr or "|" in expr :
254
- expr1 = textwrap .indent (expr1 , TAB )
255
- expr2 = textwrap .indent (expr2 , TAB )
256
- expr = f"tuple[\n { expr1 } ,\n { expr2 } ,\n ]"
257
-
258
- return expr
253
+ return f"tuple[{ expr1 } , { expr2 } ]"
259
254
260
255
261
256
def __group_types (* types : str ) -> tuple [dict [str , list [str ]], list [str ]]:
@@ -472,11 +467,7 @@ def build(self) -> str:
472
467
473
468
lines .append (line )
474
469
475
- # ensure trailing newline
476
- if not n_empty :
477
- lines .append ("" )
478
-
479
- return BR .join (lines )
470
+ return ruff_format (BR .join (lines ))
480
471
481
472
@final
482
473
def _read (self , / ) -> str | None :
You can’t perform that action at this time.
0 commit comments