Skip to content

Commit

Permalink
Regression: fix typo in windows encoding detection + properties
Browse files Browse the repository at this point in the history
* Temporary `get_pref_col`, `move_cursor_to_coords`, `mouse_event`
  should be temporary properties (due to `hasattr` usage in a call chain)
  • Loading branch information
penguinolog committed Dec 11, 2023
1 parent bed9ca2 commit 6dccd5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion urwid/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def detect_encoding() -> str:
# in older versions maybe need to set TTF font manually to support more symbols
# (this does not affect unicode IO).
if sys.platform == "win32" and sys.getdefaultencoding() == "utf-8":
return "urf-8"
return "utf-8"
# Try to determine if using a supported double-byte encoding
import locale

Expand Down
31 changes: 13 additions & 18 deletions urwid/widget/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from .constants import Sizing

if typing.TYPE_CHECKING:
from collections.abc import Hashable
from collections.abc import Callable, Hashable


class WidgetMeta(MetaSuper, signals.MetaSignals):
Expand Down Expand Up @@ -722,33 +722,28 @@ def selectable(self) -> bool:
def get_cursor_coords(self, size: tuple[()] | tuple[int] | tuple[int, int]) -> tuple[int, int] | None:
return get_delegate(self).get_cursor_coords(size)

def get_pref_col(self, size: tuple[()] | tuple[int] | tuple[int, int]) -> int:
return get_delegate(self).get_pref_col(size)
@property
def get_pref_col(self) -> Callable[[tuple[()] | tuple[int] | tuple[int, int]], int | None]:
# TODO(Aleksei): Get rid of property usage after getting rid of "if getattr"
return get_delegate(self).get_pref_col

def keypress(self, size: tuple[()] | tuple[int] | tuple[int, int], key: str) -> str | None:
return get_delegate(self).keypress(size, key)

def move_cursor_to_coords(
self,
size: tuple[()] | tuple[int] | tuple[int, int],
col: int,
row: int,
) -> bool:
return get_delegate(self).move_cursor_to_coords(size, col, row)
@property
def move_cursor_to_coords(self) -> Callable[[[tuple[()] | tuple[int] | tuple[int, int], int, int]], bool]:
# TODO(Aleksei): Get rid of property usage after getting rid of "if getattr"
return get_delegate(self).move_cursor_to_coords

def rows(self, size: tuple[int], focus: bool = False) -> int:
return get_delegate(self).rows(size, focus=focus)

@property
def mouse_event(
self,
size: tuple[()] | tuple[int] | tuple[int, int],
event,
button: int,
col: int,
row: int,
focus: bool,
) -> bool | None:
return get_delegate(self).mouse_event(size, event, button, col, row, focus)
) -> Callable[[tuple[()] | tuple[int] | tuple[int, int], str, int, int, int, bool], bool | None]:
# TODO(Aleksei): Get rid of property usage after getting rid of "if getattr"
return get_delegate(self).mouse_event

def sizing(self) -> frozenset[Sizing]:
return get_delegate(self).sizing()
Expand Down

0 comments on commit 6dccd5a

Please sign in to comment.