Skip to content

Commit 00cedb8

Browse files
committed
Use f-strings with python 3.6
1 parent 60b7538 commit 00cedb8

File tree

15 files changed

+32
-34
lines changed

15 files changed

+32
-34
lines changed

pytensor/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
105105
return None, None
106106
else:
107107
if verbose:
108-
print("unable to find command, tried {}".format(commands))
108+
print(f"unable to find command, tried {commands}")
109109
return None, None
110110
stdout = process.communicate()[0].strip().decode()
111111
if process.returncode != 0:

pytensor/configparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get_config_hash(self):
126126
return hash_from_code(
127127
"\n".join(
128128
[
129-
"{} = {}".format(cv.name, cv.__get__(self, self.__class__))
129+
f"{cv.name} = {cv.__get__(self, self.__class__)}"
130130
for cv in all_opts
131131
]
132132
)

pytensor/graph/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def __str__(self):
246246
return "{}{{{}}}".format(
247247
self.__class__.__name__,
248248
", ".join(
249-
"{}={!r}".format(p, getattr(self, p)) for p in props
249+
f"{p}={getattr(self, p)!r}" for p in props
250250
),
251251
)
252252

pytensor/link/c/basic.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,16 +1698,14 @@ def instantiate_code(self, n_args):
16981698
print(" return NULL;", file=code)
16991699
print(" }", file=code)
17001700
print(
1701-
"""\
1701+
f"""\
17021702
PyObject* thunk = PyCapsule_New((void*)(&{struct_name}_executor), NULL, {struct_name}_destructor);
17031703
if (thunk != NULL && PyCapsule_SetContext(thunk, struct_ptr) != 0) {{
17041704
PyErr_Clear();
17051705
Py_DECREF(thunk);
17061706
thunk = NULL;
17071707
}}
1708-
""".format(
1709-
**locals()
1710-
),
1708+
""",
17111709
file=code,
17121710
)
17131711
print(" return thunk; }", file=code)

pytensor/link/c/params_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def __init__(self, params_type, **kwargs):
265265
def __repr__(self):
266266
return "Params(%s)" % ", ".join(
267267
[
268-
("{}:{}:{}".format(k, type(self[k]).__name__, self[k]))
268+
(f"{k}:{type(self[k]).__name__}:{self[k]}")
269269
for k in sorted(self.keys())
270270
]
271271
)
@@ -431,7 +431,7 @@ def __getattr__(self, key):
431431
def __repr__(self):
432432
return "ParamsType<%s>" % ", ".join(
433433
[
434-
("{}:{}".format(self.fields[i], self.types[i]))
434+
(f"{self.fields[i]}:{self.types[i]}")
435435
for i in range(self.length)
436436
]
437437
)

pytensor/link/c/type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def __repr__(self):
489489
type(self).__name__,
490490
self.ctype,
491491
", ".join(
492-
"{}{}:{}".format(k, names_to_aliases[k], self[k])
492+
f"{k}{names_to_aliases[k]}:{self[k]}"
493493
for k in sorted(self.keys())
494494
),
495495
)

pytensor/scalar/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ def __str__(self):
11731173
if param:
11741174
return "{}{{{}}}".format(
11751175
self.__class__.__name__,
1176-
", ".join("{}={}".format(k, v) for k, v in param),
1176+
", ".join(f"{k}={v}" for k, v in param),
11771177
)
11781178
else:
11791179
return self.__class__.__name__

pytensor/scan/utils.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def from_node(node, clone=False) -> "ScanArgs":
710710
from pytensor.scan.op import Scan
711711

712712
if not isinstance(node.op, Scan):
713-
raise TypeError("{} is not a Scan node".format(node))
713+
raise TypeError(f"{node} is not a Scan node")
714714
return ScanArgs(
715715
node.inputs,
716716
node.outputs,
@@ -885,9 +885,9 @@ def find_among_fields(
885885

886886
field_prefix = field_name[:8]
887887
if field_prefix.endswith("in"):
888-
agg_field_name = "{}puts".format(field_prefix)
888+
agg_field_name = f"{field_prefix}puts"
889889
else:
890-
agg_field_name = "{}tputs".format(field_prefix)
890+
agg_field_name = f"{field_prefix}tputs"
891891

892892
agg_list = getattr(self, agg_field_name)
893893

@@ -934,12 +934,12 @@ def get_dependent_nodes(
934934
field_info = self.find_among_fields(i)
935935

936936
if field_info is None:
937-
raise ValueError("{} not found among fields.".format(i))
937+
raise ValueError(f"{i} not found among fields.")
938938

939939
# Find the `var_mappings` key suffix that matches the field/set of
940940
# arguments containing our source node
941941
if field_info.name[:8].endswith("_in"):
942-
map_key_suffix = "{}p".format(field_info.name[:8])
942+
map_key_suffix = f"{field_info.name[:8]}p"
943943
else:
944944
map_key_suffix = field_info.name[:9]
945945

@@ -963,9 +963,9 @@ def get_dependent_nodes(
963963
# it either forms `"*_inputs"` or `"*_outputs"`.
964964
to_agg_field_prefix = k[:9]
965965
if to_agg_field_prefix.endswith("p"):
966-
to_agg_field_name = "{}uts".format(to_agg_field_prefix)
966+
to_agg_field_name = f"{to_agg_field_prefix}uts"
967967
else:
968-
to_agg_field_name = "{}puts".format(to_agg_field_prefix)
968+
to_agg_field_name = f"{to_agg_field_prefix}puts"
969969

970970
to_agg_field = getattr(self, to_agg_field_name)
971971

@@ -1047,29 +1047,29 @@ def merge(self, other: "ScanArgs") -> "ScanArgs":
10471047

10481048
def __str__(self):
10491049
inner_arg_strs = [
1050-
"\t{}={}".format(p, getattr(self, p))
1050+
f"\t{p}={getattr(self, p)}"
10511051
for p in self.field_names
10521052
if p.startswith("outer_in") or p == "n_steps"
10531053
]
10541054
inner_arg_strs += [
1055-
"\t{}={}".format(p, getattr(self, p))
1055+
f"\t{p}={getattr(self, p)}"
10561056
for p in self.field_names
10571057
if p.startswith("inner_in")
10581058
]
10591059
inner_arg_strs += [
1060-
"\tmit_mot_in_slices={}".format(self.mit_mot_in_slices),
1061-
"\tmit_sot_in_slices={}".format(self.mit_sot_in_slices),
1060+
f"\tmit_mot_in_slices={self.mit_mot_in_slices}",
1061+
f"\tmit_sot_in_slices={self.mit_sot_in_slices}",
10621062
]
10631063
inner_arg_strs += [
1064-
"\t{}={}".format(p, getattr(self, p))
1064+
f"\t{p}={getattr(self, p)}"
10651065
for p in self.field_names
10661066
if p.startswith("inner_out")
10671067
]
10681068
inner_arg_strs += [
1069-
"\tmit_mot_out_slices={}".format(self.mit_mot_out_slices),
1069+
f"\tmit_mot_out_slices={self.mit_mot_out_slices}",
10701070
]
10711071
inner_arg_strs += [
1072-
"\t{}={}".format(p, getattr(self, p))
1072+
f"\t{p}={getattr(self, p)}"
10731073
for p in self.field_names
10741074
if p.startswith("outer_out")
10751075
]

pytensor/tensor/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ def __str__(self):
21802180
return "{}{{{}}}".format(
21812181
self.__class__.__name__,
21822182
", ".join(
2183-
"{}={!r}".format(p, getattr(self, p)) for p in self.__props__
2183+
f"{p}={getattr(self, p)!r}" for p in self.__props__
21842184
),
21852185
)
21862186

pytensor/tensor/blas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ def contiguous(var, ndim):
23632363
),
23642364
"(%s)"
23652365
% " || ".join(
2366-
"{strides}[{i}] == type_size".format(strides=strides, i=i)
2366+
f"{strides}[{i}] == type_size"
23672367
for i in range(1, ndim)
23682368
),
23692369
]

pytensor/tensor/elemwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ def _c_all(self, node, nodename, inames, onames, sub):
10151015
# No loops
10161016
task_decl = "".join(
10171017
[
1018-
"{}& {}_i = *{}_iter;\n".format(dtype, name, name)
1018+
f"{dtype}& {name}_i = *{name}_iter;\n"
10191019
for name, dtype in zip(
10201020
inames + list(real_onames), idtypes + list(real_odtypes)
10211021
)

pytensor/tensor/random/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def __getattr__(self, obj):
204204
)
205205

206206
if ns_obj is None:
207-
raise AttributeError("No attribute {}.".format(obj))
207+
raise AttributeError(f"No attribute {obj}.")
208208

209209
from pytensor.tensor.random.op import RandomVariable
210210

@@ -215,7 +215,7 @@ def meta_obj(*args, **kwargs):
215215
return self.gen(ns_obj, *args, **kwargs)
216216

217217
else:
218-
raise AttributeError("No attribute {}.".format(obj))
218+
raise AttributeError(f"No attribute {obj}.")
219219

220220
setattr(self, obj, meta_obj)
221221
return getattr(self, obj)

pytensor/tensor/random/var.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class RandomStateSharedVariable(SharedVariable):
1010
def __str__(self):
11-
return self.name or "RandomStateSharedVariable({})".format(repr(self.container))
11+
return self.name or f"RandomStateSharedVariable({repr(self.container)})"
1212

1313

1414
class RandomGeneratorSharedVariable(SharedVariable):

pytensor/tensor/var.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ def __str__(self):
10371037
name = self.name
10381038
else:
10391039
name = "TensorConstant"
1040-
return "{}{{{}}}".format(name, val)
1040+
return f"{name}{{{val}}}"
10411041

10421042
def signature(self):
10431043
return TensorConstantSignature((self.type, self.data))

versioneer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
411411
return None, None
412412
else:
413413
if verbose:
414-
print("unable to find command, tried {}".format(commands))
414+
print(f"unable to find command, tried {commands}")
415415
return None, None
416416
stdout = process.communicate()[0].strip().decode()
417417
if process.returncode != 0:
@@ -1713,7 +1713,7 @@ def get_versions(verbose=False):
17131713
try:
17141714
ver = versions_from_file(versionfile_abs)
17151715
if verbose:
1716-
print("got version from file {} {}".format(versionfile_abs, ver))
1716+
print(f"got version from file {versionfile_abs} {ver}")
17171717
return ver
17181718
except NotThisMethod:
17191719
pass

0 commit comments

Comments
 (0)