From 2e872d4ecccaa89eb24686c28417e9de40d8039c Mon Sep 17 00:00:00 2001 From: Aleksei Stepanov Date: Tue, 28 Mar 2023 17:32:04 +0200 Subject: [PATCH] Add DeprecationWarning to the deprecated methods most IDE's will recognize it and annotate during new code usage call with "warnings as errors" mode will help to refactor other users --- urwid/display_common.py | 6 +++++- urwid/signals.py | 6 ++++++ urwid/widget.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/urwid/display_common.py b/urwid/display_common.py index ae96c5c22..2d4d8283c 100755 --- a/urwid/display_common.py +++ b/urwid/display_common.py @@ -23,6 +23,7 @@ import os import sys +import warnings try: import termios @@ -869,10 +870,13 @@ def run_wrapper(self, fn, *args, **kwargs): Deprecated in favor of calling `start` as a context manager. """ + warnings.warn( + "run_wrapper is deprecated in favor of calling `start` as a context manager.", + DeprecationWarning, + ) with self.start(*args, **kwargs): return fn() - def register_palette(self, palette): """Register a set of palette entries. diff --git a/urwid/signals.py b/urwid/signals.py index ecbdc43e6..d4ecc714b 100644 --- a/urwid/signals.py +++ b/urwid/signals.py @@ -23,6 +23,7 @@ from __future__ import annotations import itertools +import warnings import weakref @@ -149,6 +150,11 @@ def connect(self, obj, name, callback, user_arg=None, weak_args=None, user_args= handler can also be disconnected by calling urwid.disconnect_signal, which doesn't need this key. """ + if user_arg is not None: + warnings.warn( + "Don't use user_arg argument, use user_args instead.", + DeprecationWarning, + ) sig_cls = obj.__class__ if not name in self._supported.get(sig_cls, []): diff --git a/urwid/widget.py b/urwid/widget.py index ab6793dfe..a8692b294 100644 --- a/urwid/widget.py +++ b/urwid/widget.py @@ -22,6 +22,7 @@ from __future__ import annotations +import warnings from operator import attrgetter from urwid import signals, text_layout @@ -623,6 +624,17 @@ class FlowWidget(Widget): """ _sizing = frozenset([FLOW]) + def __init__(self, *args, **kwargs): + warnings.warn( + """ + FlowWidget is deprecated. Inherit from Widget and add: + + _sizing = frozenset(['flow']) + + at the top of your class definition instead.""", + DeprecationWarning, + ) + def rows(self, size, focus=False): """ All flow widgets must implement this function. @@ -651,6 +663,18 @@ class BoxWidget(Widget): _selectable = True _sizing = frozenset([BOX]) + def __init__(self, *args, **kwargs): + warnings.warn( + """ + BoxWidget is deprecated. Inherit from Widget and add: + + _sizing = frozenset(['box']) + _selectable = True + + at the top of your class definition instead.""", + DeprecationWarning, + ) + def render(self, size, focus=False): """ All widgets must implement this function. @@ -680,6 +704,17 @@ class FixedWidget(Widget): """ _sizing = frozenset([FIXED]) + def __init__(self, *args, **kwargs): + warnings.warn( + """ + FixedWidget is deprecated. Inherit from Widget and add: + + _sizing = frozenset(['fixed']) + + at the top of your class definition instead.""", + DeprecationWarning, + ) + def render(self, size, focus=False): """ All widgets must implement this function.