Skip to content

Commit f157d56

Browse files
committed
fix: re-instating TYPE_CHECKING to address type-checking issues
1. Restore `TYPE_CHECKING` code clauses in `codegen/__init__.py` and `codegen/utils.py` that were removed in #4978. 1. Update `requires-optional.txt` to specify `black==25.1.0` to be consistent with version specified in `pyproject.toml`. 1. Change required Python version in `pyproject.toml` to 3.9 because desired version of `black` does not work with Python 3.8. closes #5186
1 parent c044f1e commit f157d56

File tree

2,585 files changed

+126261
-112284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,585 files changed

+126261
-112284
lines changed

codegen/__init__.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -271,24 +271,36 @@ def perform_codegen(reformat=True):
271271
root_datatype_imports.append(f"._deprecations.{dep_clas}")
272272

273273
optional_figure_widget_import = f"""
274-
__all__.append("FigureWidget")
275-
orig_getattr = __getattr__
276-
def __getattr__(import_name):
277-
if import_name == "FigureWidget":
278-
try:
279-
import ipywidgets
280-
from packaging.version import Version
281-
282-
if Version(ipywidgets.__version__) >= Version("7.0.0"):
283-
from ..graph_objs._figurewidget import FigureWidget
274+
if sys.version_info < (3, 7) or TYPE_CHECKING:
275+
try:
276+
import ipywidgets as _ipywidgets
277+
from packaging.version import Version as _Version
278+
if _Version(_ipywidgets.__version__) >= _Version("7.0.0"):
279+
from ..graph_objs._figurewidget import FigureWidget
280+
else:
281+
raise ImportError()
282+
except Exception:
283+
from ..missing_anywidget import FigureWidget
284+
else:
285+
__all__.append("FigureWidget")
286+
orig_getattr = __getattr__
287+
def __getattr__(import_name):
288+
if import_name == "FigureWidget":
289+
try:
290+
import ipywidgets
291+
from packaging.version import Version
292+
if Version(ipywidgets.__version__) >= Version("7.0.0"):
293+
from ..graph_objs._figurewidget import FigureWidget
294+
return FigureWidget
295+
else:
296+
raise ImportError()
297+
except Exception:
298+
from ..missing_anywidget import FigureWidget
284299
return FigureWidget
285300
else:
286301
raise ImportError()
287-
except Exception:
288-
from ..missing_anywidget import FigureWidget
289-
return FigureWidget
290302
291-
return orig_getattr(import_name)
303+
return orig_getattr(import_name)
292304
"""
293305
# ### __all__ ###
294306
for path_parts, class_names in alls.items():

codegen/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,16 @@ def build_from_imports_py(rel_modules=(), rel_classes=(), init_extra=""):
8282

8383
result = f"""\
8484
import sys
85-
from _plotly_utils.importers import relative_import
86-
__all__, __getattr__, __dir__ = relative_import(
87-
__name__,
88-
{repr(rel_modules)},
89-
{repr(rel_classes)}
90-
)
85+
from typing import TYPE_CHECKING
86+
if sys.version_info < (3, 7) or TYPE_CHECKING:
87+
{imports_str}
88+
else:
89+
from _plotly_utils.importers import relative_import
90+
__all__, __getattr__, __dir__ = relative_import(
91+
__name__,
92+
{repr(rel_modules)},
93+
{repr(rel_classes)}
94+
)
9195
9296
{init_extra}
9397
"""

0 commit comments

Comments
 (0)