From 0177b0370024121a4914e242d5241b2d15b35fd0 Mon Sep 17 00:00:00 2001 From: Henry Mai <88569156+tanducmai@users.noreply.github.com> Date: Wed, 8 Nov 2023 04:27:21 +1030 Subject: [PATCH] Black formatting (#3035) * fix: minor black formatting * style: update CONTRIBUTORS.md * fix: more black formatting Default black with no arguments provided --------- Co-authored-by: Darren Burns --- CONTRIBUTORS.md | 1 + examples/dynamic_progress.py | 1 - examples/top_lite_simulator.py | 1 - rich/__main__.py | 1 - rich/_ratio.py | 1 - rich/_windows.py | 1 - rich/bar.py | 1 - rich/box.py | 1 - rich/cells.py | 1 - rich/color.py | 1 - rich/json.py | 1 - rich/layout.py | 3 +-- rich/live.py | 2 +- rich/live_render.py | 1 - rich/progress_bar.py | 1 - rich/prompt.py | 1 - rich/segment.py | 1 - rich/status.py | 1 - rich/table.py | 4 +--- rich/traceback.py | 3 --- rich/tree.py | 2 -- tests/test_align.py | 1 - tests/test_color.py | 1 - tests/test_file_proxy.py | 1 - tests/test_live.py | 1 - tests/test_progress.py | 4 ---- tests/test_stack.py | 1 - tests/test_status.py | 1 - tests/test_table.py | 1 - tests/test_traceback.py | 1 - tools/make_terminal_widths.py | 1 - 31 files changed, 4 insertions(+), 39 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ba8759eae..5e2d3c491 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -31,6 +31,7 @@ The following people have contributed to the development of Rich: - [Andrew Kettmann](https://github.com/akettmann) - [Martin Larralde](https://github.com/althonos) - [Hedy Li](https://github.com/hedythedev) +- [Henry Mai](https://github.com/tanducmai) - [Luka Mamukashvili](https://github.com/UltraStudioLTD) - [Alexander Mancevice](https://github.com/amancevice) - [Will McGugan](https://github.com/willmcgugan) diff --git a/examples/dynamic_progress.py b/examples/dynamic_progress.py index c38da2ebf..1165b4f60 100644 --- a/examples/dynamic_progress.py +++ b/examples/dynamic_progress.py @@ -89,7 +89,6 @@ def run_steps(name, step_times, app_steps_task_id): # which allows for running multiple different progress bars in parallel, # and dynamically showing/hiding them with Live(progress_group): - for idx, (name, step_times) in enumerate(apps): # update message on overall progress bar top_descr = "[bold #AAAAAA](%d out of %d apps installed)" % (idx, len(apps)) diff --git a/examples/top_lite_simulator.py b/examples/top_lite_simulator.py index 4fecaaa8b..147cbb0f9 100644 --- a/examples/top_lite_simulator.py +++ b/examples/top_lite_simulator.py @@ -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, diff --git a/rich/__main__.py b/rich/__main__.py index bc55aede0..8b55130ff 100644 --- a/rich/__main__.py +++ b/rich/__main__.py @@ -207,7 +207,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, diff --git a/rich/_ratio.py b/rich/_ratio.py index f7dbe9270..e12397af6 100644 --- a/rich/_ratio.py +++ b/rich/_ratio.py @@ -151,7 +151,6 @@ def ratio_distribute( @dataclass class E: - size: Optional[int] = None ratio: int = 1 minimum_size: int = 1 diff --git a/rich/_windows.py b/rich/_windows.py index 98c700863..e17c5c0fd 100644 --- a/rich/_windows.py +++ b/rich/_windows.py @@ -30,7 +30,6 @@ class WindowsConsoleFeatures: ) except (AttributeError, ImportError, ValueError): - # Fallback if we can't load the Windows DLL def get_windows_console_features() -> WindowsConsoleFeatures: features = WindowsConsoleFeatures() diff --git a/rich/bar.py b/rich/bar.py index ed86a552d..022284b57 100644 --- a/rich/bar.py +++ b/rich/bar.py @@ -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, diff --git a/rich/box.py b/rich/box.py index c26550028..968f15297 100644 --- a/rich/box.py +++ b/rich/box.py @@ -464,7 +464,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 diff --git a/rich/cells.py b/rich/cells.py index 9354f9e31..31d0c4cb0 100644 --- a/rich/cells.py +++ b/rich/cells.py @@ -145,7 +145,6 @@ 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): print(line) diff --git a/rich/color.py b/rich/color.py index dfe455937..4270a278d 100644 --- a/rich/color.py +++ b/rich/color.py @@ -592,7 +592,6 @@ def blend_rgb( if __name__ == "__main__": # pragma: no cover - from .console import Console from .table import Table from .text import Text diff --git a/rich/json.py b/rich/json.py index 24dc5e609..f048902df 100644 --- a/rich/json.py +++ b/rich/json.py @@ -103,7 +103,6 @@ def __rich__(self) -> Text: if __name__ == "__main__": - import argparse import sys diff --git a/rich/layout.py b/rich/layout.py index 50ebd1882..7fa2852ea 100644 --- a/rich/layout.py +++ b/rich/layout.py @@ -227,7 +227,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)) @@ -403,7 +402,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 diff --git a/rich/live.py b/rich/live.py index 3ebbbc4cc..f0529a781 100644 --- a/rich/live.py +++ b/rich/live.py @@ -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, diff --git a/rich/live_render.py b/rich/live_render.py index f6fa7b2da..4284cccc4 100644 --- a/rich/live_render.py +++ b/rich/live_render.py @@ -82,7 +82,6 @@ def restore_cursor(self) -> Control: def __rich_console__( self, console: Console, options: ConsoleOptions ) -> RenderResult: - renderable = self.renderable style = console.get_style(self.style) lines = console.render_lines(renderable, options, style=style, pad=False) diff --git a/rich/progress_bar.py b/rich/progress_bar.py index 67361df2e..a2bf32614 100644 --- a/rich/progress_bar.py +++ b/rich/progress_bar.py @@ -156,7 +156,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 should_pulse = self.pulse or self.total is None diff --git a/rich/prompt.py b/rich/prompt.py index 064c959b1..36e0bba62 100644 --- a/rich/prompt.py +++ b/rich/prompt.py @@ -346,7 +346,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): diff --git a/rich/segment.py b/rich/segment.py index 9bcfc7c57..603d5097f 100644 --- a/rich/segment.py +++ b/rich/segment.py @@ -109,7 +109,6 @@ def is_control(self) -> bool: @classmethod @lru_cache(1024 * 16) def _split_cells(cls, segment: "Segment", cut: int) -> Tuple["Segment", "Segment"]: - text, style, control = segment _Segment = Segment diff --git a/rich/status.py b/rich/status.py index 09eff405e..65744838e 100644 --- a/rich/status.py +++ b/rich/status.py @@ -107,7 +107,6 @@ def __exit__( if __name__ == "__main__": # pragma: no cover - from time import sleep from .console import Console diff --git a/rich/table.py b/rich/table.py index 578d3d63c..5fc5ace0b 100644 --- a/rich/table.py +++ b/rich/table.py @@ -212,7 +212,6 @@ def __init__( caption_justify: "JustifyMethod" = "center", highlight: bool = False, ) -> None: - self.columns: List[Column] = [] self.rows: List[Row] = [] self.title = title @@ -471,7 +470,6 @@ def add_section(self) -> None: def __rich_console__( self, console: "Console", options: "ConsoleOptions" ) -> "RenderResult": - if not self.columns: yield Segment("\n") return @@ -685,7 +683,7 @@ def get_padding(first_row: bool, last_row: bool) -> Tuple[int, int, int, int]: getattr(renderable, "vertical", None) or column.vertical, ) else: - for (style, renderable) in raw_cells: + for style, renderable in raw_cells: yield _Cell( style, renderable, diff --git a/rich/traceback.py b/rich/traceback.py index 341f7f411..821c7501a 100644 --- a/rich/traceback.py +++ b/rich/traceback.py @@ -636,7 +636,6 @@ def render_locals(frame: Frame) -> Iterable[ConsoleRenderable]: excluded = False for frame_index, frame in enumerate(stack.frames): - if exclude_frames and frame_index in exclude_frames: excluded = True continue @@ -720,7 +719,6 @@ def render_locals(frame: Frame) -> Iterable[ConsoleRenderable]: if __name__ == "__main__": # pragma: no cover - from .console import Console console = Console() @@ -744,7 +742,6 @@ def foo(a: Any) -> None: bar(a) def error() -> None: - try: try: foo(0) diff --git a/rich/tree.py b/rich/tree.py index b9b7bbe54..8c5e71819 100644 --- a/rich/tree.py +++ b/rich/tree.py @@ -72,7 +72,6 @@ def add( def __rich_console__( self, console: "Console", options: "ConsoleOptions" ) -> "RenderResult": - stack: List[Iterator[Tuple[bool, Tree]]] = [] pop = stack.pop push = stack.append @@ -195,7 +194,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 diff --git a/tests/test_align.py b/tests/test_align.py index 5f67dcbc7..9abf3e2d2 100644 --- a/tests/test_align.py +++ b/tests/test_align.py @@ -8,7 +8,6 @@ def test_bad_align_legal(): - # Legal Align("foo", "left") Align("foo", "center") diff --git a/tests/test_color.py b/tests/test_color.py index 796f01983..010d79746 100644 --- a/tests/test_color.py +++ b/tests/test_color.py @@ -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 ) diff --git a/tests/test_file_proxy.py b/tests/test_file_proxy.py index 51c530aa3..2ec4d789e 100644 --- a/tests/test_file_proxy.py +++ b/tests/test_file_proxy.py @@ -28,7 +28,6 @@ def test_flush(): def test_new_lines(): - file = io.StringIO() console = Console(file=file) file_proxy = FileProxy(console, file) diff --git a/tests/test_live.py b/tests/test_live.py index 8e3d58928..f037e4b8b 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -22,7 +22,6 @@ def create_capture_console( def test_live_state() -> None: - with Live("") as live: assert live._started live.start() diff --git a/tests/test_progress.py b/tests/test_progress.py index 6a336d347..72497a0ca 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -150,7 +150,6 @@ def get_time(): def test_download_progress_uses_decimal_units() -> None: - column = DownloadColumn() test_task = Task(1, "test", 1000, 500, _get_time=lambda: 1.0) rendered_progress = str(column.render(test_task)) @@ -159,7 +158,6 @@ def test_download_progress_uses_decimal_units() -> None: def test_download_progress_uses_binary_units() -> None: - column = DownloadColumn(binary_units=True) test_task = Task(1, "test", 1024, 512, _get_time=lambda: 1.0) rendered_progress = str(column.render(test_task)) @@ -280,7 +278,6 @@ def test_render() -> None: def test_track() -> None: - console = Console( file=io.StringIO(), force_terminal=True, @@ -339,7 +336,6 @@ def test_progress_track() -> None: def test_columns() -> None: - console = Console( file=io.StringIO(), force_terminal=True, diff --git a/tests/test_stack.py b/tests/test_stack.py index 5bbb885db..e961ddd8b 100644 --- a/tests/test_stack.py +++ b/tests/test_stack.py @@ -2,7 +2,6 @@ def test_stack(): - stack = Stack() stack.push("foo") stack.push("bar") diff --git a/tests/test_status.py b/tests/test_status.py index 43ef94e01..c2aec5048 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -6,7 +6,6 @@ def test_status(): - console = Console( color_system=None, width=80, legacy_windows=False, get_time=lambda: 0.0 ) diff --git a/tests/test_table.py b/tests/test_table.py index 4faf9d537..2eea18979 100644 --- a/tests/test_table.py +++ b/tests/test_table.py @@ -114,7 +114,6 @@ def test_init_append_column(): def test_rich_measure(): - console = Console() assert Table("test_header", width=-1).__rich_measure__( console, console.options diff --git a/tests/test_traceback.py b/tests/test_traceback.py index 11b623ddf..cf24b0cc3 100644 --- a/tests/test_traceback.py +++ b/tests/test_traceback.py @@ -345,7 +345,6 @@ def level3(): if __name__ == "__main__": # pragma: no cover - expected = render(get_exception()) with open("_exception_render.py", "wt") as fh: diff --git a/tools/make_terminal_widths.py b/tools/make_terminal_widths.py index 850f67a91..1e5568346 100644 --- a/tools/make_terminal_widths.py +++ b/tools/make_terminal_widths.py @@ -40,7 +40,6 @@ def make_widths_table() -> List[Tuple[int, int, int]]: def get_cell_size(table: List[Tuple[int, int, int]], character: str) -> int: - codepoint = ord(character) lower_bound = 0 upper_bound = len(table) - 1