Skip to content

Commit

Permalink
Add DeprecationWarning to the deprecated methods
Browse files Browse the repository at this point in the history
most IDE's will recognize it and annotate during new code usage
call with "warnings as errors" mode will help to refactor other users
  • Loading branch information
Aleksei Stepanov committed Mar 29, 2023
1 parent 5548465 commit 2e872d4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion urwid/display_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import os
import sys
import warnings

try:
import termios
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions urwid/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from __future__ import annotations

import itertools
import warnings
import weakref


Expand Down Expand Up @@ -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, []):
Expand Down
35 changes: 35 additions & 0 deletions urwid/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from __future__ import annotations

import warnings
from operator import attrgetter

from urwid import signals, text_layout
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2e872d4

Please sign in to comment.