Skip to content

Commit

Permalink
style: format code with Ruff Formatter
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in dbc8cc2 according to the output
from Ruff Formatter.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Oct 26, 2023
1 parent c6d5ecc commit 2225481
Show file tree
Hide file tree
Showing 40 changed files with 46 additions and 69 deletions.
2 changes: 1 addition & 1 deletion examples/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def divide_all(divides: List[Tuple[float, float]]) -> None:
(0, 1000000),
(3.1427, 2),
(888, 0),
(2 ** 32, 2 ** 16),
(2**32, 2**16),
]

divide_all(DIVIDES)
1 change: 0 additions & 1 deletion examples/top_lite_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def generate_process(pid: int) -> Process:


def create_process_table(height: int) -> Table:

processes = sorted(
[generate_process(pid) for pid in range(height)],
key=lambda p: p.cpu_percent,
Expand Down
1 change: 0 additions & 1 deletion rich/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def iter_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:


if __name__ == "__main__": # pragma: no cover

console = Console(
file=io.StringIO(),
force_terminal=True,
Expand Down
1 change: 0 additions & 1 deletion rich/_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def ratio_distribute(

@dataclass
class E:

size: Optional[int] = None
ratio: int = 1
minimum_size: int = 1
Expand Down
2 changes: 0 additions & 2 deletions rich/_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ class WindowsConsoleFeatures:
windll = None
raise ImportError("Not windows")
except (AttributeError, ImportError, ValueError):

# Fallback if we can't load the Windows DLL
def get_windows_console_features() -> WindowsConsoleFeatures:
features = WindowsConsoleFeatures()
return features


else:

STDOUT = -11
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
_GetConsoleMode = windll.kernel32.GetConsoleMode
Expand Down
1 change: 0 additions & 1 deletion rich/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def __repr__(self) -> str:
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:

width = min(
self.width if self.width is not None else options.max_width,
options.max_width,
Expand Down
1 change: 0 additions & 1 deletion rich/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ def get_bottom(self, widths: Iterable[int]) -> str:


if __name__ == "__main__": # pragma: no cover

from rich.columns import Columns
from rich.panel import Panel

Expand Down
12 changes: 9 additions & 3 deletions rich/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,16 @@ def chop_cells(text: str, max_size: int, position: int = 0) -> List[str]:


if __name__ == "__main__": # pragma: no cover

print(get_character_cell_size("😽"))
for line in chop_cells("""这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。""", 8):
for line in chop_cells(
"""这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。""", 8
):
print(line)
for n in range(80, 1, -1):
print(set_cell_size("""这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。""", n) + "|")
print(
set_cell_size(
"""这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。""", n
)
+ "|"
)
print("x" * n)
1 change: 0 additions & 1 deletion rich/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ def blend_rgb(


if __name__ == "__main__": # pragma: no cover

from .console import Console
from .table import Table
from .text import Text
Expand Down
4 changes: 2 additions & 2 deletions rich/filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _to_str(
return "{:,} bytes".format(size)

for i, suffix in enumerate(suffixes, 2): # noqa: B007
unit = base ** i
unit = base**i
if size < unit:
break
return "{:,.{precision}f}{separator}{}".format(
Expand All @@ -44,7 +44,7 @@ def _to_str(
def pick_unit_and_suffix(size: int, suffixes: List[str], base: int) -> Tuple[int, str]:
"""Pick a suffix and base for the given size."""
for i, suffix in enumerate(suffixes):
unit = base ** i
unit = base**i
if size < unit * base:
break
return unit, suffix
Expand Down
1 change: 0 additions & 1 deletion rich/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __rich__(self) -> Text:


if __name__ == "__main__":

import argparse
import sys

Expand Down
3 changes: 1 addition & 2 deletions rich/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ def tree(self) -> "Tree":
from rich.tree import Tree

def summary(layout: "Layout") -> Table:

icon = layout.splitter.get_tree_icon()

table = Table.grid(padding=(0, 1, 0, 0))
Expand Down Expand Up @@ -404,7 +403,7 @@ def __rich_console__(
self._render_map = render_map
layout_lines: List[List[Segment]] = [[] for _ in range(height)]
_islice = islice
for (region, lines) in render_map.values():
for region, lines in render_map.values():
_x, y, _layout_width, layout_height = region
for row, line in zip(
_islice(layout_lines, y, y + layout_height), lines
Expand Down
2 changes: 1 addition & 1 deletion rich/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def process_renderables(
table.add_column("Destination Currency")
table.add_column("Exchange Rate")

for ((source, dest), exchange_rate) in exchange_rate_dict.items():
for (source, dest), exchange_rate in exchange_rate_dict.items():
table.add_row(
source,
dest,
Expand Down
5 changes: 2 additions & 3 deletions rich/live_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def position_cursor(self) -> Control:
(ControlType.ERASE_IN_LINE, 2),
)
* (height - 1)
)
),
)
return Control()

Expand All @@ -75,14 +75,13 @@ def restore_cursor(self) -> Control:
_, height = self._shape
return Control(
ControlType.CARRIAGE_RETURN,
*((ControlType.CURSOR_UP, 1), (ControlType.ERASE_IN_LINE, 2)) * height
*((ControlType.CURSOR_UP, 1), (ControlType.ERASE_IN_LINE, 2)) * height,
)
return Control()

def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:

renderable = self.renderable
_Segment = Segment
style = console.get_style(self.style)
Expand Down
2 changes: 0 additions & 2 deletions rich/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class MarkdownElement:

new_line: ClassVar[bool] = True

@classmethod
Expand Down Expand Up @@ -530,7 +529,6 @@ def __rich_console__(


if __name__ == "__main__": # pragma: no cover

import argparse
import sys

Expand Down
1 change: 0 additions & 1 deletion rich/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ def pop_style(style_name: str) -> Tuple[int, Tag]:


if __name__ == "__main__": # pragma: no cover

MARKUP = [
"[red]Hello World[/red]",
"[magenta]Hello [b]World[/b]",
Expand Down
6 changes: 3 additions & 3 deletions rich/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,9 @@ def iter_rich_args(rich_args: Any) -> Iterable[Union[Any, Tuple[str, Any]]]:
last=root,
)

def iter_attrs() -> Iterable[
Tuple[str, Any, Optional[Callable[[Any], str]]]
]:
def iter_attrs() -> (
Iterable[Tuple[str, Any, Optional[Callable[[Any], str]]]]
):
"""Iterate over attr fields and values."""
for attr in attr_fields:
if attr.repr:
Expand Down
2 changes: 0 additions & 2 deletions rich/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,6 @@ def remove_task(self, task_id: TaskID) -> None:


if __name__ == "__main__": # pragma: no coverage

import random
import time

Expand Down Expand Up @@ -1021,7 +1020,6 @@ def remove_task(self, task_id: TaskID) -> None:
console=console,
transient=True,
) as progress:

task1 = progress.add_task("[red]Downloading", total=1000)
task2 = progress.add_task("[green]Processing", total=1000)
task3 = progress.add_task("[yellow]Thinking", total=1000, start=False)
Expand Down
1 change: 0 additions & 1 deletion rich/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def _render_pulse(
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:

width = min(self.width or options.max_width, options.max_width)
ascii = options.legacy_windows or options.ascii_only
if self.pulse:
Expand Down
1 change: 0 additions & 1 deletion rich/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ def process_response(self, value: str) -> bool:


if __name__ == "__main__": # pragma: no cover

from rich import print

if Confirm.ask("Run [i]prompt[/i] tests?", default=True):
Expand Down
2 changes: 0 additions & 2 deletions rich/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def is_control(self) -> bool:
@classmethod
@lru_cache(1024 * 16)
def _split_cells(cls, segment: "Segment", cut: int) -> Tuple["Segment", "Segment"]: # type: ignore

text, style, control = segment
_Segment = Segment
if cut >= segment.cell_length:
Expand Down Expand Up @@ -586,7 +585,6 @@ def __rich_console__(


if __name__ == "__main__":

if __name__ == "__main__": # pragma: no cover
from rich.console import Console
from rich.syntax import Syntax
Expand Down
1 change: 0 additions & 1 deletion rich/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def __exit__(


if __name__ == "__main__": # pragma: no cover

from time import sleep

from .console import Console
Expand Down
18 changes: 15 additions & 3 deletions rich/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,22 @@ def pick_first(cls, *values: Optional[StyleType]) -> StyleType:
def __rich_repr__(self) -> Result:
yield "color", self.color, None
yield "bgcolor", self.bgcolor, None
yield "bold", self.bold, None,
yield "dim", self.dim, None,
yield (
"bold",
self.bold,
None,
)
yield (
"dim",
self.dim,
None,
)
yield "italic", self.italic, None
yield "underline", self.underline, None,
yield (
"underline",
self.underline,
None,
)
yield "blink", self.blink, None
yield "blink2", self.blink2, None
yield "reverse", self.reverse, None
Expand Down
2 changes: 0 additions & 2 deletions rich/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ def __rich_measure__(
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:

transparent_background = self._get_base_style().transparent_background
code_width = (
(
Expand Down Expand Up @@ -612,7 +611,6 @@ def __rich_console__(


if __name__ == "__main__": # pragma: no cover

import argparse
import sys

Expand Down
4 changes: 1 addition & 3 deletions rich/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def __init__(
caption_justify: "JustifyMethod" = "center",
highlight: bool = False,
) -> None:

self.columns: List[Column] = []
self.rows: List[Row] = []
self.title = title
Expand Down Expand Up @@ -427,7 +426,6 @@ def add_cell(column: Column, renderable: "RenderableType") -> None:
def __rich_console__(
self, console: "Console", options: "ConsoleOptions"
) -> "RenderResult":

if not self.columns:
yield Segment("\n")
return
Expand Down Expand Up @@ -637,7 +635,7 @@ def get_padding(first_row: bool, last_row: bool) -> Tuple[int, int, int, int]:
for first, last, (style, renderable) in loop_first_last(raw_cells):
yield _Cell(style, _Padding(renderable, get_padding(first, last)))
else:
for (style, renderable) in raw_cells:
for style, renderable in raw_cells:
yield _Cell(style, renderable)

def _get_padding_width(self, column_index: int) -> int:
Expand Down
6 changes: 3 additions & 3 deletions rich/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,14 @@ def render_locals(frame: Frame) -> Iterable[ConsoleRenderable]:


if __name__ == "__main__": # pragma: no cover

from .console import Console

console = Console()
import sys

def bar(a: Any) -> None: # 这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑
def bar(
a: Any
) -> None: # 这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑
one = 1
print(one / a)

Expand All @@ -615,7 +616,6 @@ def foo(a: Any) -> None:
bar(a)

def error() -> None:

try:
try:
foo(0)
Expand Down
2 changes: 0 additions & 2 deletions rich/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def add(
def __rich_console__(
self, console: "Console", options: "ConsoleOptions"
) -> "RenderResult":

stack: List[Iterator[Tuple[bool, Tree]]] = []
pop = stack.pop
push = stack.append
Expand Down Expand Up @@ -187,7 +186,6 @@ def __rich_measure__(


if __name__ == "__main__": # pragma: no cover

from rich.console import Group
from rich.markdown import Markdown
from rich.panel import Panel
Expand Down
1 change: 0 additions & 1 deletion tests/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def test_bad_align_legal():

# Legal
Align("foo", "left")
Align("foo", "center")
Expand Down
1 change: 0 additions & 1 deletion tests/test_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def test_get_ansi_codes() -> None:


def test_downgrade() -> None:

assert Color.parse("color(9)").downgrade(0) == Color(
"color(9)", ColorType.STANDARD, 9, None
)
Expand Down
Loading

0 comments on commit 2225481

Please sign in to comment.