Skip to content

Commit

Permalink
Fix ListBox.contents: it should return final entity (#751)
Browse files Browse the repository at this point in the history
Fix #146
  • Loading branch information
penguinolog committed Jan 17, 2024
1 parent 9e199e2 commit 5d4977f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions urwid/listbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
if typing.TYPE_CHECKING:
from collections.abc import Callable, Hashable

from typing_extensions import Literal
from typing_extensions import Literal, Self

from urwid.canvas import CompositeCanvas

Expand Down Expand Up @@ -280,7 +280,7 @@ class ListBox(Widget, WidgetContainerMixin):
_selectable = True
_sizing = frozenset([Sizing.BOX])

def __init__(self, body: ListWalker):
def __init__(self, body: ListWalker) -> None:
"""
:param body: a ListWalker subclass such as
:class:`SimpleFocusListWalker` that contains
Expand Down Expand Up @@ -314,7 +314,7 @@ def __init__(self, body: ListWalker):
self.set_focus_valign_pending = None

@property
def body(self):
def body(self) -> ListWalker:
"""
a ListWalker subclass such as :class:`SimpleFocusListWalker` that contains
widgets to be displayed inside the list box
Expand Down Expand Up @@ -700,6 +700,19 @@ def _contents(self):
class ListBoxContents:
__getitem__ = self._contents__getitem__

__len__ = self.__len__

def __repr__(inner_self) -> str:
return f"<{inner_self.__class__.__name__} for {self!r} at 0x{id(inner_self):X}>"

def __call__(inner_self) -> Self:
warnings.warn(
"ListBox.contents is a property, not a method",
DeprecationWarning,
stacklevel=3,
)
return inner_self

return ListBoxContents()

def _contents__getitem__(self, key):
Expand Down Expand Up @@ -734,7 +747,7 @@ def contents(self):
You must use the list walker stored as
:attr:`.body` to perform manipulation and iteration, if supported.
"""
return self._contents
return self._contents()

def options(self):
"""
Expand Down

0 comments on commit 5d4977f

Please sign in to comment.