File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 3636
3737sys .path .insert (0 , str (Path (__file__ ).parent .parent ))
3838
39+ from tool ._ruff import ruff_format
3940from tool .promotion import _typename as dtype_label
4041from tool .ufunc import _all_types as ufunc_signatures
4142
@@ -249,13 +250,7 @@ def _array_expr(
249250
250251 expr2 = _array_expr_single (* (dts [1 ] for dts in dtypess ), ndim = ndim , npt = npt )
251252
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 } ]"
259254
260255
261256def __group_types (* types : str ) -> tuple [dict [str , list [str ]], list [str ]]:
@@ -472,11 +467,7 @@ def build(self) -> str:
472467
473468 lines .append (line )
474469
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 ))
480471
481472 @final
482473 def _read (self , / ) -> str | None :
You can’t perform that action at this time.
0 commit comments