Skip to content

Commit e590fd0

Browse files
committed
use explicit relative imports for py2 compat
1 parent f150a8c commit e590fd0

File tree

6 files changed

+42
-38
lines changed

6 files changed

+42
-38
lines changed

plotly/basedatatypes.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import collections
22
import re
3-
import typing as typ
43
import warnings
54
from contextlib import contextmanager
65
from copy import deepcopy, copy
76
from pprint import PrettyPrinter
8-
from typing import Dict, Tuple, Union, Callable, List
97

10-
from plotly.optional_imports import get_module
8+
from .optional_imports import get_module
119

12-
import plotly.offline as pyo
10+
from . import offline as pyo
1311
from _plotly_utils.basevalidators import (
1412
CompoundValidator, CompoundArrayValidator, BaseDataValidator,
1513
BaseValidator)
16-
from plotly import animation
17-
from plotly.callbacks import (Points, BoxSelector, LassoSelector,
14+
from . import animation
15+
from .callbacks import (Points, BoxSelector, LassoSelector,
1816
InputDeviceState)
19-
from plotly.utils import ElidedPrettyPrinter
20-
from plotly.validators import (DataValidator, LayoutValidator, FramesValidator)
17+
from .utils import ElidedPrettyPrinter
18+
from .validators import (DataValidator, LayoutValidator, FramesValidator)
19+
2120

2221
# Optional imports
2322
# ----------------
@@ -2260,7 +2259,7 @@ def plotly_name(self):
22602259
return self._plotly_name
22612260

22622261
@property
2263-
def _parent_path_str(self) -> str:
2262+
def _parent_path_str(self):
22642263
"""
22652264
dot-separated path string to this object's parent.
22662265
@@ -2283,7 +2282,7 @@ def _parent_path_str(self) -> str:
22832282
raise NotImplementedError
22842283

22852284
@property
2286-
def _prop_descriptions(self) -> str:
2285+
def _prop_descriptions(self):
22872286
"""
22882287
Formatted string containing all of this obejcts child properties
22892288
and their descriptions
@@ -3162,7 +3161,7 @@ def _dispatch_change_callbacks(self, changed_paths):
31623161
for callback in callbacks:
31633162
callback(self, *callback_args)
31643163

3165-
def on_change(self, callback, *args, append=False):
3164+
def on_change(self, callback, append=False, *args):
31663165
"""
31673166
Register callback function to be called when certain properties or
31683167
subproperties of this object are modified.
@@ -3297,7 +3296,7 @@ class BaseLayoutHierarchyType(BasePlotlyType):
32973296
"""
32983297

32993298
@property
3300-
def _parent_path_str(self) -> str:
3299+
def _parent_path_str(self):
33013300
pass
33023301

33033302
def __init__(self, plotly_name, **kwargs):
@@ -3603,7 +3602,7 @@ def __init__(self, plotly_name, **kwargs):
36033602
# ---
36043603
# All trace types must have a top-level UID
36053604
@property
3606-
def uid(self) -> str:
3605+
def uid(self):
36073606
raise NotImplementedError
36083607

36093608
@uid.setter
@@ -3613,9 +3612,9 @@ def uid(self, val):
36133612
# Hover
36143613
# -----
36153614
def on_hover(self,
3616-
callback: typ.Callable[
3617-
['BaseTraceType', Points, InputDeviceState], None],
3615+
callback,
36183616
append=False):
3617+
# typ.Callable[['BaseTraceType', Points, InputDeviceState], None]
36193618
"""
36203619
Register function to be called when the user hovers over one or more
36213620
points in this trace
@@ -3650,7 +3649,7 @@ def on_hover(self,
36503649
if callback:
36513650
self._hover_callbacks.append(callback)
36523651

3653-
def _dispatch_on_hover(self, points: Points, state: InputDeviceState):
3652+
def _dispatch_on_hover(self, points, state):
36543653
"""
36553654
Dispatch points and device state all all hover callbacks
36563655
"""
@@ -3660,8 +3659,7 @@ def _dispatch_on_hover(self, points: Points, state: InputDeviceState):
36603659
# Unhover
36613660
# -------
36623661
def on_unhover(self,
3663-
callback: typ.Callable[
3664-
['BaseTraceType', Points, InputDeviceState], None],
3662+
callback,
36653663
append=False):
36663664
"""
36673665
Register function to be called when the user unhovers away from one
@@ -3697,7 +3695,7 @@ def on_unhover(self,
36973695
if callback:
36983696
self._unhover_callbacks.append(callback)
36993697

3700-
def _dispatch_on_unhover(self, points: Points, state: InputDeviceState):
3698+
def _dispatch_on_unhover(self, points, state):
37013699
"""
37023700
Dispatch points and device state all all hover callbacks
37033701
"""
@@ -3707,8 +3705,7 @@ def _dispatch_on_unhover(self, points: Points, state: InputDeviceState):
37073705
# Click
37083706
# -----
37093707
def on_click(self,
3710-
callback: typ.Callable[
3711-
['BaseTraceType', Points, InputDeviceState], None],
3708+
callback,
37123709
append=False):
37133710
"""
37143711
Register function to be called when the user clicks on one or more
@@ -3743,7 +3740,7 @@ def on_click(self,
37433740
if callback:
37443741
self._click_callbacks.append(callback)
37453742

3746-
def _dispatch_on_click(self, points: Points, state: InputDeviceState):
3743+
def _dispatch_on_click(self, points, state):
37473744
"""
37483745
Dispatch points and device state all all hover callbacks
37493746
"""
@@ -3754,9 +3751,7 @@ def _dispatch_on_click(self, points: Points, state: InputDeviceState):
37543751
# ------
37553752
def on_selection(
37563753
self,
3757-
callback: typ.Callable[[
3758-
'BaseTraceType', Points, typ.Union[BoxSelector, LassoSelector]
3759-
], None],
3754+
callback,
37603755
append=False):
37613756
"""
37623757
Register function to be called when the user selects one or more
@@ -3793,8 +3788,8 @@ def on_selection(
37933788
self._select_callbacks.append(callback)
37943789

37953790
def _dispatch_on_selection(self,
3796-
points: Points,
3797-
selector: typ.Union[BoxSelector, LassoSelector]):
3791+
points,
3792+
selector):
37983793
"""
37993794
Dispatch points and selector info to selection callbacks
38003795
"""

plotly/basewidget.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
from importlib import import_module
33
import os
44
import numbers
5-
from urllib import parse
5+
try:
6+
from urllib import parse
7+
except ImportError:
8+
from urlparse import urlparse as parse
69

710
import ipywidgets as widgets
811
from traitlets import List, Unicode, Dict, observe, Integer
9-
from plotly.basedatatypes import BaseFigure, BasePlotlyType
10-
from plotly.callbacks import (BoxSelector, LassoSelector,
11-
InputDeviceState, Points)
12-
from plotly.serializers import custom_serializers
12+
from .basedatatypes import BaseFigure, BasePlotlyType
13+
from .callbacks import (BoxSelector, LassoSelector,
14+
InputDeviceState, Points)
15+
from .serializers import custom_serializers
1316

1417

15-
@widgets.register
18+
@widgets.register()
1619
class BaseFigureWidget(BaseFigure, widgets.DOMWidget):
1720
"""
1821
Base class for FigureWidget. The FigureWidget class is code-generated as a

plotly/callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from plotly.utils import _list_repr_elided
1+
from .utils import _list_repr_elided
22

33

44
class InputDeviceState:

plotly/graph_objs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
from ._frame import Frame
6666
from ._figure import Figure
6767

68+
6869
try:
6970
import ipywidgets
7071
from ._figurewidget import FigureWidget

plotly/plotly/plotly.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
from plotly.api import v1, v2
3232
from plotly.basedatatypes import BaseTraceType
3333
from plotly.plotly import chunked_requests
34+
3435
from plotly.graph_objs import Scatter
36+
3537
from plotly.grid_objs import Grid, Column
3638
from plotly.dashboard_objs import dashboard_objs as dashboard
3739

3840
# This is imported like this for backwards compat. Careful if changing.
3941
from plotly.config import get_config, get_credentials
4042

43+
4144
__all__ = None
4245

4346
DEFAULT_PLOT_OPTIONS = {
@@ -631,14 +634,16 @@ def write(self, trace, layout=None,
631634
validate = False
632635

633636
# Convert trace objects to dictionaries
637+
634638
if isinstance(trace, BaseTraceType):
635-
trace = trace.to_plotly_json()
639+
trace = trace.to_plotly_json()
636640

637641
stream_object = dict()
638642
stream_object.update(trace)
639643
if 'type' not in stream_object:
640644
# tests if Scatter contains invalid kwargs
641-
dummy_obj = copy.deepcopy(Scatter(**stream_object))
645+
# TODO: replace Scatter with something else
646+
#dummy_obj = copy.deepcopy(Scatter(**stream_object))
642647
stream_object = Scatter(**stream_object)
643648
stream_object['type'] = 'scatter'
644649

plotly/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from plotly.basedatatypes import Undefined
2-
from plotly.optional_imports import get_module
1+
from .basedatatypes import Undefined
2+
from .optional_imports import get_module
33
np = get_module('numpy')
44

55
def _py_to_js(v, widget_manager):

0 commit comments

Comments
 (0)