Skip to content

Commit 29a0b6d

Browse files
authored
Simplify deprecation warnings with PEP 562 (dbc-team#928)
1 parent c15f55e commit 29a0b6d

File tree

1 file changed

+15
-39
lines changed

1 file changed

+15
-39
lines changed

dash_bootstrap_components/__init__.py

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Bootstrap themed components for use in Plotly Dash"""
22
import os
3-
import sys
43

54
from dash_bootstrap_components import _components, icons, themes
65
from dash_bootstrap_components._components import * # noqa
@@ -38,48 +37,25 @@
3837
Table.from_dataframe = classmethod(_generate_table_from_df)
3938

4039

41-
# TODO: when Python 3.6 support is dropped we can simplify this with PEP 562
42-
# https://www.python.org/dev/peps/pep-0562/
43-
class _V1DeprecationWarningWrapper:
44-
def __init__(self, wrapped, deprecated):
45-
self.wrapped = wrapped
46-
self.deprecated = deprecated
47-
48-
def __getattr__(self, name):
49-
if name in self.deprecated:
50-
raise AttributeError(
51-
f"{name} was deprecated in dash-bootstrap-components version "
52-
f"1.0.0. You are using {__version__}. For more details please "
53-
"see the migration guide: "
54-
"https://dash-bootstrap-components.opensource.faculty.ai/"
55-
"migration-guide/"
56-
)
57-
return getattr(self.wrapped, name)
58-
59-
def __setstate__(self, state):
60-
# ensure deprecated & wrapped fields are set to avoid recursive stack
61-
# explosion in __getattr__
62-
self.deprecated = state.get("deprecated", None)
63-
self.wrapped = state.get("wrapped", None)
64-
65-
def __dir__(self):
66-
# required for autocomplete. filter out os, and sys imports
67-
return [
68-
item
69-
for item in self.wrapped.__dir__()
70-
if item not in {"os", "sys"}
71-
]
72-
73-
74-
sys.modules[__name__] = _V1DeprecationWarningWrapper(
75-
sys.modules[__name__],
76-
[
40+
def __getattr__(name):
41+
if name in [
7742
"CardColumns",
7843
"CardDeck",
7944
"FormGroup",
8045
"InputGroupAddon",
8146
"Jumbotron",
8247
"ListGroupItemHeading",
8348
"ListGroupItemText",
84-
],
85-
)
49+
]:
50+
raise AttributeError(
51+
f"{name} was deprecated in dash-bootstrap-components version "
52+
f"1.0.0. You are using {__version__}. For more details please "
53+
"see the migration guide: "
54+
"https://dash-bootstrap-components.opensource.faculty.ai/"
55+
"migration-guide/"
56+
)
57+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
58+
59+
60+
def __dir__():
61+
return __all__

0 commit comments

Comments
 (0)