Skip to content

Commit c3c84b9

Browse files
committed
f-strings everywhere! fffff
1 parent c8c2095 commit c3c84b9

21 files changed

+278
-425
lines changed

dash/_callback.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def register_clientside_callback(
215215
inline_scripts,
216216
clientside_function,
217217
*args,
218-
**kwargs
218+
**kwargs,
219219
):
220220
output, inputs, state, prevent_initial_call = handle_callback_args(args, kwargs)
221221
insert_callback(
@@ -238,8 +238,8 @@ def register_clientside_callback(
238238
if isinstance(output, (list, tuple)):
239239
out0 = output[0]
240240

241-
namespace = "_dashprivate_{}".format(out0.component_id)
242-
function_name = "{}".format(out0.component_property)
241+
namespace = f"_dashprivate_{out0.component_id}"
242+
function_name = out0.component_property
243243

244244
inline_scripts.append(
245245
_inline_clientside_template.format(

dash/_callback_context.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def has_context(func):
1111
def assert_context(*args, **kwargs):
1212
if not flask.has_request_context():
1313
raise exceptions.MissingCallbackContextException(
14-
"dash.callback_context.{} is only available from a callback!".format(
15-
getattr(func, "__name__")
16-
)
14+
f"dash.callback_context.{getattr(func, '__name__')} is only available from a callback!"
1715
)
1816
return func(*args, **kwargs)
1917

@@ -119,7 +117,7 @@ def record_timing(name, duration=None, description=None):
119117
timing_information = getattr(flask.g, "timing_information", {})
120118

121119
if name in timing_information:
122-
raise KeyError('Duplicate resource name "{}" found.'.format(name))
120+
raise KeyError(f'Duplicate resource name "{name}" found.')
123121

124122
timing_information[name] = {"dur": round(duration * 1000), "desc": description}
125123

dash/_configs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get_combined_config(name, val, default=None):
4747
if val is not None:
4848
return val
4949

50-
env = load_dash_env_vars().get("DASH_{}".format(name.upper()))
50+
env = load_dash_env_vars().get(f"DASH_{name.upper()}")
5151
if env is None:
5252
return default
5353

dash/_get_paths.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,10 @@ def app_get_relative_path(requests_pathname, path):
7070
return requests_pathname
7171
if not path.startswith("/"):
7272
raise exceptions.UnsupportedRelativePath(
73-
"""
73+
f"""
7474
Paths that aren't prefixed with a leading / are not supported.
75-
You supplied: {}
76-
""".format(
77-
path
78-
)
75+
You supplied: {path}
76+
"""
7977
)
8078
return "/".join([requests_pathname.rstrip("/"), path.lstrip("/")])
8179

@@ -137,12 +135,10 @@ def app_strip_relative_path(requests_pathname, path):
137135
requests_pathname != "/" and not path.startswith(requests_pathname.rstrip("/"))
138136
) or (requests_pathname == "/" and not path.startswith("/")):
139137
raise exceptions.UnsupportedRelativePath(
140-
"""
138+
f"""
141139
Paths that aren't prefixed with requests_pathname_prefix are not supported.
142-
You supplied: {} and requests_pathname_prefix was {}
143-
""".format(
144-
path, requests_pathname
145-
)
140+
You supplied: {path} and requests_pathname_prefix was {requests_pathname}
141+
"""
146142
)
147143
if requests_pathname != "/" and path.startswith(requests_pathname.rstrip("/")):
148144
path = path.replace(

dash/_grouping.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,16 @@ def _perform_make_grouping_like(value, next_values):
9494
if not isinstance(flat_values, list):
9595
raise ValueError(
9696
"The flat_values argument must be a list. "
97-
"Received value of type {typ}".format(typ=type(flat_values))
97+
f"Received value of type {type(flat_values)}"
9898
)
9999

100100
expected_length = len(flatten_grouping(schema))
101101
if len(flat_values) != expected_length:
102102
raise ValueError(
103-
"The specified grouping pattern requires {n} elements but received {m}\n"
104-
" Grouping patter: {pattern}\n"
105-
" Values: {flat_values}".format(
106-
n=expected_length,
107-
m=len(flat_values),
108-
pattern=repr(schema),
109-
flat_values=flat_values,
110-
)
103+
f"The specified grouping pattern requires {expected_length} "
104+
f"elements but received {len(flat_values)}\n"
105+
f" Grouping pattern: {repr(schema)}\n"
106+
f" Values: {flat_values}"
111107
)
112108

113109
return _perform_make_grouping_like(schema, list(flat_values))

dash/_utils.py

+14-23
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ def interpolate_str(template, **data):
3131

3232

3333
def format_tag(tag_name, attributes, inner="", closed=False, opened=False):
34-
tag = "<{tag} {attributes}"
34+
attributes = " ".join([f'{k}="{v}"' for k, v in attributes.items()])
35+
tag = f"<{tag_name} {attributes}"
3536
if closed:
3637
tag += "/>"
3738
elif opened:
3839
tag += ">"
3940
else:
40-
tag += ">" + inner + "</{tag}>"
41-
return tag.format(
42-
tag=tag_name,
43-
attributes=" ".join(['{}="{}"'.format(k, v) for k, v in attributes.items()]),
44-
)
41+
tag += ">" + inner + f"</{tag_name}>"
42+
return tag
4543

4644

4745
def generate_hash():
@@ -124,23 +122,16 @@ def first(self, *names):
124122

125123

126124
def create_callback_id(output):
125+
# A single dot within a dict id key or value is OK
126+
# but in case of multiple dots together escape each dot
127+
# with `\` so we don't mistake it for multi-outputs
128+
def _concat(x):
129+
return x.component_id_str().replace(".", "\\.") + "." + x.component_property
130+
127131
if isinstance(output, (list, tuple)):
128-
return "..{}..".format(
129-
"...".join(
130-
"{}.{}".format(
131-
# A single dot within a dict id key or value is OK
132-
# but in case of multiple dots together escape each dot
133-
# with `\` so we don't mistake it for multi-outputs
134-
x.component_id_str().replace(".", "\\."),
135-
x.component_property,
136-
)
137-
for x in output
138-
)
139-
)
140-
141-
return "{}.{}".format(
142-
output.component_id_str().replace(".", "\\."), output.component_property
143-
)
132+
return ".." + "...".join(_concat(x) for x in output) + ".."
133+
134+
return _concat(output)
144135

145136

146137
# inverse of create_callback_id - should only be relevant if an old renderer is
@@ -166,7 +157,7 @@ def inputs_to_dict(inputs_list):
166157
inputsi = i if isinstance(i, list) else [i]
167158
for ii in inputsi:
168159
id_str = stringify_id(ii["id"])
169-
inputs["{}.{}".format(id_str, ii["property"])] = ii.get("value")
160+
inputs[f'{id_str}.{ii["property"]}'] = ii.get("value")
170161
return inputs
171162

172163

0 commit comments

Comments
 (0)