Skip to content

Fix 5186 type checking renegerate code #5199

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 2 commits 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ doc/check-or-enforce-order.py

tests/percy/*.html
tests/percy/pandas2/*.html
test_path.png
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 TYPE_CHECKING:
{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
3 changes: 1 addition & 2 deletions plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"""

import sys
from typing import TYPE_CHECKING
from _plotly_utils.importers import relative_import
import importlib.metadata
Expand All @@ -35,7 +34,7 @@
__version__ = importlib.metadata.version("plotly")
version = __version__

if sys.version_info < (3, 7) or TYPE_CHECKING:
if TYPE_CHECKING:
from plotly import (
graph_objs,
tools,
Expand Down
Loading