Skip to content

feat: restore type checking portion of code generation #5198

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
40 changes: 26 additions & 14 deletions codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,36 @@ def perform_codegen(reformat=True):
root_datatype_imports.append(f"._deprecations.{dep_clas}")

optional_figure_widget_import = f"""
__all__.append("FigureWidget")
orig_getattr = __getattr__
def __getattr__(import_name):
if import_name == "FigureWidget":
try:
import ipywidgets
from packaging.version import Version

if Version(ipywidgets.__version__) >= Version("7.0.0"):
from ..graph_objs._figurewidget import FigureWidget
if sys.version_info < (3, 7) or TYPE_CHECKING:
try:
import ipywidgets as _ipywidgets
from packaging.version import Version as _Version
if _Version(_ipywidgets.__version__) >= _Version("7.0.0"):
from ..graph_objs._figurewidget import FigureWidget
else:
raise ImportError()
except Exception:
from ..missing_anywidget import FigureWidget
else:
__all__.append("FigureWidget")
orig_getattr = __getattr__
def __getattr__(import_name):
if import_name == "FigureWidget":
try:
import ipywidgets
from packaging.version import Version
if Version(ipywidgets.__version__) >= Version("7.0.0"):
from ..graph_objs._figurewidget import FigureWidget
return FigureWidget
else:
raise ImportError()
except Exception:
from ..missing_anywidget import FigureWidget
return FigureWidget
else:
raise ImportError()
except Exception:
from ..missing_anywidget import FigureWidget
return FigureWidget

return orig_getattr(import_name)
return orig_getattr(import_name)
"""
# ### __all__ ###
for path_parts, class_names in alls.items():
Expand Down
16 changes: 10 additions & 6 deletions codegen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ def build_from_imports_py(rel_modules=(), rel_classes=(), init_extra=""):

result = f"""\
import sys
from _plotly_utils.importers import relative_import
__all__, __getattr__, __dir__ = relative_import(
__name__,
{repr(rel_modules)},
{repr(rel_classes)}
)
from typing import TYPE_CHECKING
if sys.version_info < (3, 7) or TYPE_CHECKING:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need sys.version_info < (3, 7) anymore - our minimum is past that. Which means we may not need import sys anymore either.

{imports_str}
else:
from _plotly_utils.importers import relative_import
__all__, __getattr__, __dir__ = relative_import(
__name__,
{repr(rel_modules)},
{repr(rel_classes)}
)

{init_extra}
"""
Expand Down