Skip to content

Commit

Permalink
Upgrade ruff to 0.2.0
Browse files Browse the repository at this point in the history
* Adopt config format
* Fix deprecation warnings and adopt typing annotations:
* * palette_test.py
* * `Canvas.content()`
  • Loading branch information
Aleksei Stepanov committed Feb 5, 2024
1 parent 58ce51a commit 3f502fb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
17 changes: 9 additions & 8 deletions examples/palette_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from __future__ import annotations

import re
import typing

import urwid

Expand Down Expand Up @@ -352,11 +353,11 @@ def main():
mode_radio_buttons = []
chart_radio_buttons = []

def fcs(widget):
def fcs(widget) -> urwid.AttrMap:
# wrap widgets that can take focus
return urwid.AttrMap(widget, None, "focus")

def set_mode(colors, is_foreground_chart):
def set_mode(colors: int, is_foreground_chart: bool) -> None:
# set terminal mode and redraw chart
screen.set_terminal_properties(colors)
screen.reset_default_terminal_palette()
Expand All @@ -369,23 +370,23 @@ def set_mode(colors, is_foreground_chart):
txt = chart_fn(chart, "default", colors)
lb[chart_offset] = urwid.Text(txt, wrap=urwid.CLIP)

def on_mode_change(rb, state, colors):
def on_mode_change(colors: int, rb: urwid.RadioButton, state: bool) -> None:
# if this radio button is checked
if state:
is_foreground_chart = chart_radio_buttons[0].state
set_mode(colors, is_foreground_chart)

def mode_rb(text, colors, state=False):
def mode_rb(text: str, colors: int, state: bool = False) -> urwid.AttrMap:
# mode radio buttons
rb = urwid.RadioButton(mode_radio_buttons, text, state)
urwid.connect_signal(rb, "change", on_mode_change, colors)
urwid.connect_signal(rb, "change", on_mode_change, user_args=(colors,))
return fcs(rb)

def on_chart_change(rb, state):
def on_chart_change(rb: urwid.RadioButton, state: bool) -> None:
# handle foreground check box state change
set_mode(screen.colors, state)

def click_exit(button):
def click_exit(button) -> typing.NoReturn:
raise urwid.ExitMainLoop()

lb.extend(
Expand Down Expand Up @@ -423,7 +424,7 @@ def click_exit(button):

set_mode(16, True) # displays the chart

def unhandled_input(key):
def unhandled_input(key: str | tuple[str, int, int, int]) -> None:
if key in ("Q", "q", "esc"):
raise urwid.ExitMainLoop()

Expand Down
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,11 @@ ignore_missing_imports = true

[tool.ruff]
line-length = 120
show-source = true
output-format = "full"
target-version = "py37"
ignore-init-module-imports = true

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401", "SIM105"]

[tool.ruff.lint]
ignore-init-module-imports = true
extend-select = [
"E",
"W", # also pycodestyle warnings
Expand Down Expand Up @@ -185,6 +182,10 @@ extend-ignore = [
"TRY003", #long messages prepare outside, ...
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "SIM105"]


[tool.ruff.lint.isort]
known-third-party = []

Expand Down
2 changes: 1 addition & 1 deletion ruff-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruff == 0.1.14
ruff==0.2.0
14 changes: 8 additions & 6 deletions urwid/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
if typing.TYPE_CHECKING:
from collections.abc import Hashable, Iterable, Sequence

from typing_extensions import Literal

from .widget import Widget


Expand Down Expand Up @@ -294,7 +296,7 @@ def content(
cols: int | None = None,
rows: int | None = None,
attr=None,
) -> Iterable[list[tuple[object, object, bytes]]]:
) -> Iterable[list[tuple[object, Literal["0", "U"] | None, bytes]]]:
raise NotImplementedError()

def cols(self):
Expand Down Expand Up @@ -492,7 +494,7 @@ def content(
cols: int | None = 0,
rows: int | None = 0,
attr=None,
) -> Iterable[tuple[object, object, bytes]]:
) -> Iterable[tuple[object, Literal["0", "U"] | None, bytes]]:
"""
Return the canvas content as a list of rows where each row
is a list of (attr, cs, text) tuples.
Expand Down Expand Up @@ -560,7 +562,7 @@ class BlankCanvas(Canvas):
"""

def __init__(self) -> None:
super().__init__(None)
super().__init__()

def content(
self,
Expand All @@ -569,7 +571,7 @@ def content(
cols: int | None = 0,
rows: int | None = 0,
attr=None,
) -> Iterable[list[tuple[object, object, bytes]]]:
) -> Iterable[list[tuple[object, Literal["0", "U"] | None, bytes]]]:
"""
return (cols, rows) of spaces with default attributes.
"""
Expand Down Expand Up @@ -621,7 +623,7 @@ def content(
cols: int | None = None,
rows: int | None = None,
attr=None,
) -> Iterable[list[tuple[object, object, bytes]]]:
) -> Iterable[list[tuple[object, Literal["0", "U"] | None, bytes]]]:
if cols is None:
cols = self.size[0]
if rows is None:
Expand Down Expand Up @@ -724,7 +726,7 @@ def content(
cols: int | None = None,
rows: int | None = None,
attr=None,
) -> Iterable[list[tuple[object, object, bytes]]]:
) -> Iterable[list[tuple[object, Literal["0", "U"] | None, bytes]]]:
"""
Return the canvas content as a list of rows where each row
is a list of (attr, cs, text) tuples.
Expand Down
2 changes: 1 addition & 1 deletion urwid/vterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ def content(
cols: int | None = None,
rows: int | None = None,
attr=None,
) -> Iterable[list[tuple[object, object, bytes]]]:
) -> Iterable[list[tuple[object, Literal["0", "U"] | None, bytes]]]:
if self.scrolling_up == 0:
yield from self.term
else:
Expand Down

0 comments on commit 3f502fb

Please sign in to comment.