Skip to content

Commit 0c130bb

Browse files
committed
Prevent lazy import when type checking
This checks whether type checking is being done, and if so, disables the lazy import as this is generally not supported by type checkers. This should not have any impact on the runtime performance as the lazy import should still be used at runtime. This is achieved by inspecting the [`TYPE_CHECKING`](https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING) variable. This should resolve issue #1682 and provide a temporary workaround for issue #1103. In the latter case, the addition of stubs would probably still be an improvement as I believe this would be faster. Signed-off-by: JP-Ellis <[email protected]>
1 parent b5c4ce2 commit 0c130bb

File tree

1,527 files changed

+3413
-2025
lines changed

Some content is hidden

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

1,527 files changed

+3413
-2025
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## TBD
6+
7+
### Fixed
8+
- Improve support for type checking by bypassing lazy-loading when type checking.
59

610
## [5.7.0] - 2022-04-05
711

Diff for: packages/python/plotly/codegen/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def perform_codegen():
267267
root_datatype_imports.append(f"._deprecations.{dep_clas}")
268268

269269
optional_figure_widget_import = f"""
270-
if sys.version_info < (3, 7):
270+
if sys.version_info < (3, 7) or TYPE_CHECKING:
271271
try:
272272
import ipywidgets as _ipywidgets
273273
from distutils.version import LooseVersion as _LooseVersion

Diff for: packages/python/plotly/codegen/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def build_from_imports_py(rel_modules=(), rel_classes=(), init_extra=""):
7575

7676
result = f"""\
7777
import sys
78-
if sys.version_info < (3, 7):
78+
from typing import TYPE_CHECKING
79+
if sys.version_info < (3, 7) or TYPE_CHECKING:
7980
{imports_str}
8081
else:
8182
from _plotly_utils.importers import relative_import

Diff for: packages/python/plotly/plotly/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
"""
2828
from __future__ import absolute_import
2929
import sys
30+
from typing import TYPE_CHECKING
3031
from _plotly_utils.importers import relative_import
3132

3233

33-
if sys.version_info < (3, 7):
34+
if sys.version_info < (3, 7) or TYPE_CHECKING:
3435
from plotly import (
3536
graph_objs,
3637
tools,

Diff for: packages/python/plotly/plotly/graph_objects/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
2+
from typing import TYPE_CHECKING
23

3-
if sys.version_info < (3, 7):
4+
if sys.version_info < (3, 7) or TYPE_CHECKING:
45
from ..graph_objs import Waterfall
56
from ..graph_objs import Volume
67
from ..graph_objs import Violin
@@ -263,7 +264,7 @@
263264
)
264265

265266

266-
if sys.version_info < (3, 7):
267+
if sys.version_info < (3, 7) or TYPE_CHECKING:
267268
try:
268269
import ipywidgets as _ipywidgets
269270
from distutils.version import LooseVersion as _LooseVersion

Diff for: packages/python/plotly/plotly/graph_objs/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
2+
from typing import TYPE_CHECKING
23

3-
if sys.version_info < (3, 7):
4+
if sys.version_info < (3, 7) or TYPE_CHECKING:
45
from ._bar import Bar
56
from ._barpolar import Barpolar
67
from ._box import Box
@@ -263,7 +264,7 @@
263264
)
264265

265266

266-
if sys.version_info < (3, 7):
267+
if sys.version_info < (3, 7) or TYPE_CHECKING:
267268
try:
268269
import ipywidgets as _ipywidgets
269270
from distutils.version import LooseVersion as _LooseVersion

Diff for: packages/python/plotly/plotly/graph_objs/_carpet.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ def aaxis(self):
265265
Sets the tick label formatting rule using d3
266266
formatting mini-languages which are very
267267
similar to those in Python. For numbers, see: h
268-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
269-
ormat. And for dates see:
268+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
269+
format. And for dates see:
270270
https://github.com/d3/d3-time-
271271
format/tree/v2.2.3#locale_format. We add two
272272
items to d3's date formatter: "%h" for half of
@@ -575,8 +575,8 @@ def baxis(self):
575575
Sets the tick label formatting rule using d3
576576
formatting mini-languages which are very
577577
similar to those in Python. For numbers, see: h
578-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
579-
ormat. And for dates see:
578+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
579+
format. And for dates see:
580580
https://github.com/d3/d3-time-
581581
format/tree/v2.2.3#locale_format. We add two
582582
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_choropleth.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def colorbar(self):
244244
Sets the tick label formatting rule using d3
245245
formatting mini-languages which are very
246246
similar to those in Python. For numbers, see: h
247-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
248-
ormat. And for dates see:
247+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
248+
format. And for dates see:
249249
https://github.com/d3/d3-time-
250250
format/tree/v2.2.3#locale_format. We add two
251251
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_choroplethmapbox.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ def colorbar(self):
268268
Sets the tick label formatting rule using d3
269269
formatting mini-languages which are very
270270
similar to those in Python. For numbers, see: h
271-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
272-
ormat. And for dates see:
271+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
272+
format. And for dates see:
273273
https://github.com/d3/d3-time-
274274
format/tree/v2.2.3#locale_format. We add two
275275
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_cone.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ def colorbar(self):
370370
Sets the tick label formatting rule using d3
371371
formatting mini-languages which are very
372372
similar to those in Python. For numbers, see: h
373-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
374-
ormat. And for dates see:
373+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
374+
format. And for dates see:
375375
https://github.com/d3/d3-time-
376376
format/tree/v2.2.3#locale_format. We add two
377377
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_contour.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ def colorbar(self):
291291
Sets the tick label formatting rule using d3
292292
formatting mini-languages which are very
293293
similar to those in Python. For numbers, see: h
294-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
295-
ormat. And for dates see:
294+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
295+
format. And for dates see:
296296
https://github.com/d3/d3-time-
297297
format/tree/v2.2.3#locale_format. We add two
298298
items to d3's date formatter: "%h" for half of
@@ -534,8 +534,8 @@ def contours(self):
534534
Sets the contour label formatting rule using d3
535535
formatting mini-languages which are very
536536
similar to those in Python. For numbers, see: h
537-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
538-
ormat.
537+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
538+
format.
539539
operation
540540
Sets the constraint operation. "=" keeps
541541
regions equal to `value` "<" and "<=" keep

Diff for: packages/python/plotly/plotly/graph_objs/_contourcarpet.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ def colorbar(self):
464464
Sets the tick label formatting rule using d3
465465
formatting mini-languages which are very
466466
similar to those in Python. For numbers, see: h
467-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
468-
ormat. And for dates see:
467+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
468+
format. And for dates see:
469469
https://github.com/d3/d3-time-
470470
format/tree/v2.2.3#locale_format. We add two
471471
items to d3's date formatter: "%h" for half of
@@ -684,8 +684,8 @@ def contours(self):
684684
Sets the contour label formatting rule using d3
685685
formatting mini-languages which are very
686686
similar to those in Python. For numbers, see: h
687-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
688-
ormat.
687+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
688+
format.
689689
operation
690690
Sets the constraint operation. "=" keeps
691691
regions equal to `value` "<" and "<=" keep

Diff for: packages/python/plotly/plotly/graph_objs/_densitymapbox.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ def colorbar(self):
267267
Sets the tick label formatting rule using d3
268268
formatting mini-languages which are very
269269
similar to those in Python. For numbers, see: h
270-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
271-
ormat. And for dates see:
270+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
271+
format. And for dates see:
272272
https://github.com/d3/d3-time-
273273
format/tree/v2.2.3#locale_format. We add two
274274
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_heatmap.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ def colorbar(self):
266266
Sets the tick label formatting rule using d3
267267
formatting mini-languages which are very
268268
similar to those in Python. For numbers, see: h
269-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
270-
ormat. And for dates see:
269+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
270+
format. And for dates see:
271271
https://github.com/d3/d3-time-
272272
format/tree/v2.2.3#locale_format. We add two
273273
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_heatmapgl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ def colorbar(self):
243243
Sets the tick label formatting rule using d3
244244
formatting mini-languages which are very
245245
similar to those in Python. For numbers, see: h
246-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
247-
ormat. And for dates see:
246+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
247+
format. And for dates see:
248248
https://github.com/d3/d3-time-
249249
format/tree/v2.2.3#locale_format. We add two
250250
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_histogram2d.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ def colorbar(self):
328328
Sets the tick label formatting rule using d3
329329
formatting mini-languages which are very
330330
similar to those in Python. For numbers, see: h
331-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
332-
ormat. And for dates see:
331+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
332+
format. And for dates see:
333333
https://github.com/d3/d3-time-
334334
format/tree/v2.2.3#locale_format. We add two
335335
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_histogram2dcontour.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ def colorbar(self):
352352
Sets the tick label formatting rule using d3
353353
formatting mini-languages which are very
354354
similar to those in Python. For numbers, see: h
355-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
356-
ormat. And for dates see:
355+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
356+
format. And for dates see:
357357
https://github.com/d3/d3-time-
358358
format/tree/v2.2.3#locale_format. We add two
359359
items to d3's date formatter: "%h" for half of
@@ -574,8 +574,8 @@ def contours(self):
574574
Sets the contour label formatting rule using d3
575575
formatting mini-languages which are very
576576
similar to those in Python. For numbers, see: h
577-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
578-
ormat.
577+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
578+
format.
579579
operation
580580
Sets the constraint operation. "=" keeps
581581
regions equal to `value` "<" and "<=" keep

Diff for: packages/python/plotly/plotly/graph_objs/_indicator.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def delta(self):
135135
Sets the value formatting rule using d3
136136
formatting mini-languages which are very
137137
similar to those in Python. For numbers, see: h
138-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
139-
ormat.
138+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
139+
format.
140140
141141
Returns
142142
-------
@@ -452,8 +452,8 @@ def number(self):
452452
Sets the value formatting rule using d3
453453
formatting mini-languages which are very
454454
similar to those in Python. For numbers, see: h
455-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
456-
ormat.
455+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
456+
format.
457457
458458
Returns
459459
-------

Diff for: packages/python/plotly/plotly/graph_objs/_isosurface.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ def colorbar(self):
376376
Sets the tick label formatting rule using d3
377377
formatting mini-languages which are very
378378
similar to those in Python. For numbers, see: h
379-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
380-
ormat. And for dates see:
379+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
380+
format. And for dates see:
381381
https://github.com/d3/d3-time-
382382
format/tree/v2.2.3#locale_format. We add two
383383
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_layout.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3981,8 +3981,8 @@ def xaxis(self):
39813981
Sets the hover text formatting rule using d3
39823982
formatting mini-languages which are very
39833983
similar to those in Python. For numbers, see: h
3984-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
3985-
ormat. And for dates see:
3984+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
3985+
format. And for dates see:
39863986
https://github.com/d3/d3-time-
39873987
format/tree/v2.2.3#locale_format. We add two
39883988
items to d3's date formatter: "%h" for half of
@@ -4196,8 +4196,8 @@ def xaxis(self):
41964196
Sets the tick label formatting rule using d3
41974197
formatting mini-languages which are very
41984198
similar to those in Python. For numbers, see: h
4199-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
4200-
ormat. And for dates see:
4199+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
4200+
format. And for dates see:
42014201
https://github.com/d3/d3-time-
42024202
format/tree/v2.2.3#locale_format. We add two
42034203
items to d3's date formatter: "%h" for half of
@@ -4484,8 +4484,8 @@ def yaxis(self):
44844484
Sets the hover text formatting rule using d3
44854485
formatting mini-languages which are very
44864486
similar to those in Python. For numbers, see: h
4487-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
4488-
ormat. And for dates see:
4487+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
4488+
format. And for dates see:
44894489
https://github.com/d3/d3-time-
44904490
format/tree/v2.2.3#locale_format. We add two
44914491
items to d3's date formatter: "%h" for half of
@@ -4691,8 +4691,8 @@ def yaxis(self):
46914691
Sets the tick label formatting rule using d3
46924692
formatting mini-languages which are very
46934693
similar to those in Python. For numbers, see: h
4694-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
4695-
ormat. And for dates see:
4694+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
4695+
format. And for dates see:
46964696
https://github.com/d3/d3-time-
46974697
format/tree/v2.2.3#locale_format. We add two
46984698
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_mesh3d.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ def colorbar(self):
452452
Sets the tick label formatting rule using d3
453453
formatting mini-languages which are very
454454
similar to those in Python. For numbers, see: h
455-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
456-
ormat. And for dates see:
455+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
456+
format. And for dates see:
457457
https://github.com/d3/d3-time-
458458
format/tree/v2.2.3#locale_format. We add two
459459
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_parcats.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ def line(self):
535535
only when this field is shown. Numbers are
536536
formatted using d3-format's syntax
537537
%{variable:d3-format}, for example "Price:
538-
%{y:$.2f}". https://github.com/d3/d3-format/tre
539-
e/v1.4.5#d3-format for details on the
538+
%{y:$.2f}". https://github.com/d3/d3-
539+
format/tree/v1.4.5#d3-format for details on the
540540
formatting syntax. Dates are formatted using
541541
d3-time-format's syntax %{variable|d3-time-
542542
format}, for example "Day: %{2019-01-01|%A}".

Diff for: packages/python/plotly/plotly/graph_objs/_parcoords.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def dimensions(self):
136136
Sets the tick label formatting rule using d3
137137
formatting mini-languages which are very
138138
similar to those in Python. For numbers, see: h
139-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
140-
ormat. And for dates see:
139+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
140+
format. And for dates see:
141141
https://github.com/d3/d3-time-
142142
format/tree/v2.2.3#locale_format. We add two
143143
items to d3's date formatter: "%h" for half of

Diff for: packages/python/plotly/plotly/graph_objs/_sankey.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ def link(self):
386386
only when this field is shown. Numbers are
387387
formatted using d3-format's syntax
388388
%{variable:d3-format}, for example "Price:
389-
%{y:$.2f}". https://github.com/d3/d3-format/tre
390-
e/v1.4.5#d3-format for details on the
389+
%{y:$.2f}". https://github.com/d3/d3-
390+
format/tree/v1.4.5#d3-format for details on the
391391
formatting syntax. Dates are formatted using
392392
d3-time-format's syntax %{variable|d3-time-
393393
format}, for example "Day: %{2019-01-01|%A}".
@@ -575,8 +575,8 @@ def node(self):
575575
only when this field is shown. Numbers are
576576
formatted using d3-format's syntax
577577
%{variable:d3-format}, for example "Price:
578-
%{y:$.2f}". https://github.com/d3/d3-format/tre
579-
e/v1.4.5#d3-format for details on the
578+
%{y:$.2f}". https://github.com/d3/d3-
579+
format/tree/v1.4.5#d3-format for details on the
580580
formatting syntax. Dates are formatted using
581581
d3-time-format's syntax %{variable|d3-time-
582582
format}, for example "Day: %{2019-01-01|%A}".

Diff for: packages/python/plotly/plotly/graph_objs/_streamtube.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ def colorbar(self):
345345
Sets the tick label formatting rule using d3
346346
formatting mini-languages which are very
347347
similar to those in Python. For numbers, see: h
348-
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-f
349-
ormat. And for dates see:
348+
ttps://github.com/d3/d3-format/tree/v1.4.5#d3-
349+
format. And for dates see:
350350
https://github.com/d3/d3-time-
351351
format/tree/v2.2.3#locale_format. We add two
352352
items to d3's date formatter: "%h" for half of

0 commit comments

Comments
 (0)