Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify deprecation errors with PEP 562 #928

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 15 additions & 39 deletions dash_bootstrap_components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Bootstrap themed components for use in Plotly Dash"""
import os
import sys

from dash_bootstrap_components import _components, icons, themes
from dash_bootstrap_components._components import * # noqa
Expand Down Expand Up @@ -38,48 +37,25 @@
Table.from_dataframe = classmethod(_generate_table_from_df)


# TODO: when Python 3.6 support is dropped we can simplify this with PEP 562
# https://www.python.org/dev/peps/pep-0562/
class _V1DeprecationWarningWrapper:
def __init__(self, wrapped, deprecated):
self.wrapped = wrapped
self.deprecated = deprecated

def __getattr__(self, name):
if name in self.deprecated:
raise AttributeError(
f"{name} was deprecated in dash-bootstrap-components version "
f"1.0.0. You are using {__version__}. For more details please "
"see the migration guide: "
"https://dash-bootstrap-components.opensource.faculty.ai/"
"migration-guide/"
)
return getattr(self.wrapped, name)

def __setstate__(self, state):
# ensure deprecated & wrapped fields are set to avoid recursive stack
# explosion in __getattr__
self.deprecated = state.get("deprecated", None)
self.wrapped = state.get("wrapped", None)

def __dir__(self):
# required for autocomplete. filter out os, and sys imports
return [
item
for item in self.wrapped.__dir__()
if item not in {"os", "sys"}
]


sys.modules[__name__] = _V1DeprecationWarningWrapper(
sys.modules[__name__],
[
def __getattr__(name):
if name in [
"CardColumns",
"CardDeck",
"FormGroup",
"InputGroupAddon",
"Jumbotron",
"ListGroupItemHeading",
"ListGroupItemText",
],
)
]:
raise AttributeError(
f"{name} was deprecated in dash-bootstrap-components version "
f"1.0.0. You are using {__version__}. For more details please "
"see the migration guide: "
"https://dash-bootstrap-components.opensource.faculty.ai/"
"migration-guide/"
)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


def __dir__():
return __all__