Skip to content

Commit b61e4d0

Browse files
wilhelmhbalexcjohnson
authored andcommitted
Fix linting
1 parent 3ab52cd commit b61e4d0

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

dash/dash.py

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,38 @@ class _NoUpdate(object):
102102
"""
103103

104104

105+
def _handle_callback_args(args, kwargs):
106+
"""Split args into outputs, inputs and states"""
107+
prevent_initial_call = None
108+
for k, v in kwargs.items():
109+
if k == "prevent_initial_call":
110+
prevent_initial_call = v
111+
else:
112+
raise TypeError(
113+
"callback got an unexpected keyword argument '{}'".format(k)
114+
)
115+
args = [
116+
arg
117+
# for backward compatibility, one arg can be a list
118+
for arg_or_list in args
119+
# flatten args that are lists
120+
for arg in (
121+
arg_or_list if isinstance(arg_or_list, (list, tuple))
122+
else [arg_or_list]
123+
)
124+
]
125+
return [
126+
# split according to type Output, Input, State
127+
[arg for arg in args if isinstance(arg, class_)]
128+
for class_ in [Output, Input, State]
129+
] + [
130+
# keep list of args in order, for matching order
131+
# in the callback's parameters
132+
[arg for arg in args if not isinstance(arg, Output)],
133+
prevent_initial_call
134+
]
135+
136+
105137
# pylint: disable=too-many-instance-attributes
106138
# pylint: disable=too-many-arguments, too-many-locals
107139
class Dash(object):
@@ -913,7 +945,7 @@ def clientside_callback(self, clientside_function, *args, **kwargs):
913945
not to fire when its outputs are first added to the page. Defaults to
914946
`False` unless `prevent_initial_callbacks=True` at the app level.
915947
"""
916-
output, inputs, state, callback_args, prevent_initial_call = self._handle_callback_args(args, kwargs)
948+
output, inputs, state, callback_args, prevent_initial_call = _handle_callback_args(args, kwargs)
917949
self._insert_callback(output, inputs, state, callback_args)
918950

919951
# If JS source is explicitly given, create a namespace and function
@@ -945,37 +977,6 @@ def clientside_callback(self, clientside_function, *args, **kwargs):
945977
"function_name": function_name,
946978
}
947979

948-
def _handle_callback_args(self, args, kwargs):
949-
"""Split args into outputs, inputs and states"""
950-
prevent_initial_call = None
951-
for k, v in kwargs.items():
952-
if k == "prevent_initial_call":
953-
prevent_initial_call = v
954-
else:
955-
raise TypeError(
956-
"callback got an unexpected keyword argument '{}'".format(k)
957-
)
958-
args = [
959-
arg
960-
# for backward compatibility, one arg can be a list
961-
for arg_or_list in args
962-
# flatten args that are lists
963-
for arg in (
964-
arg_or_list if isinstance(arg_or_list, (list, tuple))
965-
else [arg_or_list]
966-
)
967-
]
968-
return [
969-
# split according to type Output, Input, State
970-
[arg for arg in args if isinstance(arg, class_)]
971-
for class_ in [Output, Input, State]
972-
] + [
973-
# keep list of args in order, for matching order
974-
# in the callback's parameters
975-
[arg for arg in args if not isinstance(arg, Output)],
976-
prevent_initial_call
977-
]
978-
979980
def callback(self, *args, **kwargs):
980981
"""
981982
Normally used as a decorator, `@app.callback` provides a server-side
@@ -988,7 +989,7 @@ def callback(self, *args, **kwargs):
988989
not to fire when its outputs are first added to the page. Defaults to
989990
`False` unless `prevent_initial_callbacks=True` at the app level.
990991
"""
991-
output, inputs, state, callback_args, prevent_initial_call = self._handle_callback_args(args, kwargs)
992+
output, inputs, state, callback_args, prevent_initial_call = _handle_callback_args(args, kwargs)
992993
callback_id = self._insert_callback(output, inputs, state, callback_args, prevent_initial_call)
993994

994995
def wrap_func(func):

tests/integration/test_integration.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,10 @@ def update_output(value):
647647
def test_inin019_callback_dep_types():
648648
app = Dash(__name__)
649649
app.layout = html.Div(
650-
[html.Div("child", id="in1"), html.Div("state", id="state1"), html.Div(id="out1"),
651-
html.Div("child", id="in2"), html.Div("state", id="state2"), html.Div(id="out2"),
652-
html.Div("child", id="in3"), html.Div("state", id="state3"), html.Div(id="out3"),
650+
[
651+
html.Div("child", id="in1"), html.Div("state", id="state1"), html.Div(id="out1"),
652+
html.Div("child", id="in2"), html.Div("state", id="state2"), html.Div(id="out2"),
653+
html.Div("child", id="in3"), html.Div("state", id="state3"), html.Div(id="out3"),
653654
]
654655
)
655656

0 commit comments

Comments
 (0)