Skip to content

Commit

Permalink
Update ruff and fix a large set of *preview* checks
Browse files Browse the repository at this point in the history
* unused variable (prefix `_` mark a private, standard for unused)
* use `set` literal for container check if value `Hashable`
  • Loading branch information
penguinolog committed Dec 5, 2023
1 parent 09f6c3b commit 363da9c
Show file tree
Hide file tree
Showing 31 changed files with 204 additions and 185 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ extend-select = [
extend-ignore = [
"PLR6301", "E203", "PLW3201",
# refactor rules (too many statements/arguments/branches)
"PLR0904", "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PLR2004",
"PLR0904", "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PLR0917", "PLR2004",
"PLC0415", # We have a lot of imports outside of top-level
"RET504", # Unnecessary variable assignment before return statement
"SIM108", # Use ternary operator,
"TRY003", #long messages prepare outside, ...
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.6
ruff==0.1.7
10 changes: 5 additions & 5 deletions urwid/curses_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def _setup_colour_pairs(self) -> None:

curses.init_pair(bg * 8 + 7 - fg, fg, bg)

def _curs_set(self, x):
if self.cursor_state in ("fixed", x):
def _curs_set(self, x: int):
if self.cursor_state in {"fixed", x}:
return
try:
curses.curs_set(x)
Expand Down Expand Up @@ -375,7 +375,7 @@ def _get_input(self, wait_tenths: int | None) -> tuple[list[str], list[int]]:
def _encode_mouse_event(self) -> list[int]:
# convert to escape sequence
last_state = next_state = self.last_bstate
(_id, x, y, z, bstate) = curses.getmouse()
(_id, x, y, _z, bstate) = curses.getmouse()

mod = 0
if bstate & curses.BUTTON_SHIFT:
Expand Down Expand Up @@ -505,7 +505,7 @@ def draw_screen(self, size: tuple[int, int], r):
if not self._started:
raise RuntimeError

cols, rows = size
_cols, rows = size

if r.rows() != rows:
raise ValueError("canvas size and passed size don't match")
Expand Down Expand Up @@ -533,7 +533,7 @@ def draw_screen(self, size: tuple[int, int], r):
self._setattr(a)
lasta = a
try:
if cs in ("0", "U"):
if cs in {"0", "U"}:
for i in range(len(seg)):
self.s.addch(0x400000 + seg[i])
else:
Expand Down
8 changes: 4 additions & 4 deletions urwid/display_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def __init__(self, fg: str, bg: str, colors: Literal[1, 16, 88, 256, 16777216] =
>>> AttrSpec('#ddb', '#004', 88)
AttrSpec('#ccc', '#000', colors=88)
"""
if colors not in (1, 16, 88, 256, 2**24):
if colors not in {1, 16, 88, 256, 2**24}:
raise AttrSpecError(f"invalid number of colors ({colors:d}).")
self.__value = 0 | _HIGH_88_COLOR * (colors == 88) | _HIGH_TRUE_COLOR * (colors == 2**24)
self.__set_foreground(fg)
Expand Down Expand Up @@ -760,7 +760,7 @@ def __set_foreground(self, foreground: str) -> None:
flags |= _ATTRIBUTES[part]
continue
# past this point we must be specifying a color
if part in ("", "default"):
if part in {"", "default"}:
scolor = 0
elif part in _BASIC_COLORS:
scolor = _BASIC_COLORS.index(part)
Expand Down Expand Up @@ -808,7 +808,7 @@ def background(self) -> str:

def __set_background(self, background: str) -> None:
flags = 0
if background in ("", "default"):
if background in {"", "default"}:
color = 0
elif background in _BASIC_COLORS:
color = _BASIC_COLORS.index(background)
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def register_palette(
"""

for item in palette:
if len(item) in (3, 4, 6):
if len(item) in {3, 4, 6}:
self.register_palette_entry(*item)
continue
if len(item) != 2:
Expand Down
4 changes: 2 additions & 2 deletions urwid/escape.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ def read_sgrmouse_info(self, keys, more_available: bool):
pos_m = 0
found_m = False
for k in keys:
value = value + chr(k)
if k in (ord("M"), ord("m")):
value += chr(k)
if k in {ord("M"), ord("m")}:
found_m = True
break
pos_m += 1
Expand Down
2 changes: 1 addition & 1 deletion urwid/event_loop/main_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def _run_screen_event_loop(self) -> None:
sec = next_alarm[0] - time.time()
if sec > 0:
break
tm, tie_break, callback = next_alarm
_tm, _tie_break, callback = next_alarm
callback()

if self.event_loop._alarms:
Expand Down
6 changes: 3 additions & 3 deletions urwid/event_loop/select_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ def _loop(self) -> None:
timeout = 0.0
tm = "idle"

ready, w, err = select.select(fds, [], fds, timeout)
ready, _w, _err = select.select(fds, [], fds, timeout)

else:
tm = None
ready, w, err = select.select(fds, [], fds)
ready, _w, _err = select.select(fds, [], fds)

if not ready:
if tm == "idle":
self._entering_idle()
self._did_something = False
elif tm is not None:
# must have been a timeout
tm, tie_break, alarm_callback = heapq.heappop(self._alarms)
tm, _tie_break, alarm_callback = heapq.heappop(self._alarms)
alarm_callback()
self._did_something = True

Expand Down
2 changes: 1 addition & 1 deletion urwid/event_loop/zmq_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _loop(self) -> None:
self._entering_idle()
self._did_something = False
elif state == "alarm":
due, tie_break, callback = heapq.heappop(self._alarms)
_due, _tie_break, callback = heapq.heappop(self._alarms)
callback()
self._did_something = True

Expand Down
2 changes: 1 addition & 1 deletion urwid/lcd_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def set_led_pin(self, led: Literal[0, 1, 2, 3], rg: Literal[0, 1], value: int):
"""
if not 0 <= led <= 3:
raise ValueError(led)
if rg not in (0, 1):
if rg not in {0, 1}:
raise ValueError(rg)
if not 0 <= value <= 100:
raise ValueError(value)
Expand Down
Loading

0 comments on commit 363da9c

Please sign in to comment.