Skip to content

Commit e44f228

Browse files
committed
Improved error for removed attributes
1 parent 216dcf8 commit e44f228

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

dash/_obsolete.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# pylint: disable=too-few-public-methods
2+
from .exceptions import ObsoleteAttributeException
3+
4+
5+
class ObsoleteAttribute:
6+
def __init__(self, message: str, exc=ObsoleteAttributeException):
7+
self.message = message
8+
self.exc = exc
9+
10+
11+
class ObsoleteChecker:
12+
_obsolete_attributes = {
13+
"run_server": ObsoleteAttribute("app.run_server has been replaced by app.run"),
14+
"long_callback": ObsoleteAttribute(
15+
"app.long_callback has been removed, use app.callback(..., background=True) instead"
16+
),
17+
}
18+
19+
def __getattr__(self, name: str):
20+
if name in self._obsolete_attributes:
21+
err = self._obsolete_attributes[name]
22+
raise err.exc(err.message)
23+
return getattr(self, name)

dash/dash.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
from . import _get_app
6767

6868
from ._grouping import map_grouping, grouping_len, update_args_group
69+
from ._obsolete import ObsoleteChecker
6970

7071
from . import _pages
7172
from ._pages import (
@@ -194,7 +195,7 @@ def _do_skip(error):
194195

195196
# pylint: disable=too-many-instance-attributes
196197
# pylint: disable=too-many-arguments, too-many-locals
197-
class Dash:
198+
class Dash(ObsoleteChecker):
198199
"""Dash is a framework for building analytical web applications.
199200
No JavaScript required.
200201

dash/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class ObsoleteKwargException(DashException):
1010
pass
1111

1212

13+
class ObsoleteAttributeException(DashException):
14+
pass
15+
16+
1317
class NoLayoutException(DashException):
1418
pass
1519

0 commit comments

Comments
 (0)