Skip to content

Commit a6b9585

Browse files
committed
Use implicit string concatenation instead of explicit
1 parent f75434f commit a6b9585

File tree

12 files changed

+33
-47
lines changed

12 files changed

+33
-47
lines changed

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ line-length = 88
125125
exclude = ["doc/", "pytensor/_version.py"]
126126

127127
[tool.ruff.lint]
128-
select = ["C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH"]
129-
ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203"]
128+
select = ["C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC"]
129+
ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203", "ISC001"]
130130

131131

132132
[tool.ruff.lint.isort]

pytensor/bin/pytensor_cache.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def print_help(exit_status):
3030
print('Type "pytensor-cache clear" to erase the cache')
3131
print('Type "pytensor-cache list" to print the cache content')
3232
print('Type "pytensor-cache unlock" to unlock the cache directory')
33-
print(
34-
'Type "pytensor-cache cleanup" to delete keys in the old ' "format/code version"
35-
)
33+
print('Type "pytensor-cache cleanup" to delete keys in the old format/code version')
3634
print('Type "pytensor-cache purge" to force deletion of the cache directory')
3735
print(
3836
'Type "pytensor-cache basecompiledir" '

pytensor/compile/debugmode.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -1614,14 +1614,10 @@ def f():
16141614
opt = str(reason[0][0])
16151615
msg = (
16161616
f"An optimization (probably {opt}) inserted an "
1617-
"apply node that raise an error."
1618-
+ "\nThe information we have about this "
1619-
"optimizations is:"
1620-
+ str(reason[0][1])
1621-
+ "\n"
1622-
+ reason[0][2]
1623-
+ "\n\nThe original exception: \n"
1624-
+ str(e)
1617+
"apply node that raise an error.\n"
1618+
"The information we have about this optimization is:"
1619+
f"{reason[0][1]}\n{reason[0][2]}\n"
1620+
f"\nThe original exception: \n{e}"
16251621
)
16261622
new_e = e.__class__(msg)
16271623
exc_type, exc_value, exc_trace = sys.exc_info()
@@ -1725,15 +1721,11 @@ def f():
17251721
raise
17261722
opt = str(reason[0][0])
17271723
msg = (
1728-
f"An optimization (probably {opt}) inserted "
1729-
"an apply node that raise an error."
1730-
+ "\nThe information we have about this "
1731-
"optimizations is:"
1732-
+ str(reason[0][1])
1733-
+ "\n"
1734-
+ reason[0][2]
1735-
+ "\n\nThe original exception: \n"
1736-
+ str(e)
1724+
f"An optimization (probably {opt}) inserted an "
1725+
"apply node that raise an error.\n"
1726+
"The information we have about this optimization is:"
1727+
f"{reason[0][1]}\n{reason[0][2]}\n"
1728+
f"\nThe original exception: \n{e}"
17371729
)
17381730
new_e = e.__class__(msg)
17391731
exc_type, exc_value, exc_trace = sys.exc_info()

pytensor/gradient.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -802,20 +802,20 @@ def _node_to_pattern(node):
802802
if not isinstance(connection_pattern, list):
803803
raise TypeError(
804804
"Op.connection_pattern should return "
805-
+ f"list of list of bool, but for Op={node.op}"
806-
+ f"got {connection_pattern} with type {type(connection_pattern)}."
805+
f"list of list of bool, but for Op={node.op}"
806+
f"got {connection_pattern} with type {type(connection_pattern)}."
807807
)
808808
if len(connection_pattern) != len(node.inputs):
809809
raise ValueError(
810810
f"{node.op}.connection_pattern should have {len(node.inputs)}"
811-
+ f" rows but has {len(connection_pattern)}."
811+
f" rows but has {len(connection_pattern)}."
812812
)
813813
for ii, output_pattern in enumerate(connection_pattern):
814814
if not isinstance(output_pattern, list):
815815
raise TypeError(
816816
f"{node.op}.connection_pattern should return"
817-
+ f" a list of lists, but element {int(ii)}"
818-
+ f"is {output_pattern} of type {type(output_pattern)}."
817+
f" a list of lists, but element {int(ii)}"
818+
f"is {output_pattern} of type {type(output_pattern)}."
819819
)
820820
else:
821821
connection_pattern = [[True for output in node.outputs] for ipt in node.inputs]

pytensor/graph/rewriting/db.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ def __init__(
229229
def __str__(self):
230230
return (
231231
"RewriteDatabaseQuery("
232-
+ f"inc={self.include},ex={self.exclude},"
233-
+ f"require={self.require},subquery={self.subquery},"
234-
+ f"position_cutoff={self.position_cutoff},"
235-
+ f"extra_rewrites={self.extra_rewrites})"
232+
f"inc={self.include},ex={self.exclude},"
233+
f"require={self.require},subquery={self.subquery},"
234+
f"position_cutoff={self.position_cutoff},"
235+
f"extra_rewrites={self.extra_rewrites})"
236236
)
237237

238238
def __setstate__(self, state):

pytensor/link/c/cmodule.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1744,9 +1744,7 @@ def std_lib_dirs_and_libs() -> tuple[list[str], ...] | None:
17441744
if not os.path.exists(os.path.join(libdir, f)):
17451745
print(
17461746
"Your Python version is from Canopy. "
1747-
+ "You need to install the package '"
1748-
+ lib
1749-
+ "' from Canopy package manager."
1747+
f"You need to install the package '{lib}' from Canopy package manager."
17501748
)
17511749
libdirs = [
17521750
# Used in older Canopy
@@ -1763,9 +1761,7 @@ def std_lib_dirs_and_libs() -> tuple[list[str], ...] | None:
17631761
):
17641762
print(
17651763
"Your Python version is from Canopy. "
1766-
+ "You need to install the package '"
1767-
+ lib
1768-
+ "' from Canopy package manager."
1764+
f"You need to install the package '{lib}' from Canopy package manager."
17691765
)
17701766
python_lib_dirs.insert(0, libdir)
17711767
std_lib_dirs_and_libs.data = [libname], python_lib_dirs

pytensor/link/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ def raise_with_op(
351351
clients = [[c[0] for c in fgraph.clients[var]] for var in node.outputs]
352352
detailed_err_msg += (
353353
f"Inputs shapes: {shapes}"
354-
+ f"\nInputs strides: {strides}"
355-
+ f"\nInputs values: {scalar_values}"
354+
f"\nInputs strides: {strides}"
355+
f"\nInputs values: {scalar_values}"
356356
)
357357
if verbosity == "high":
358358
inpts = [

pytensor/scalar/basic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ def c_code(self, node, name, inputs, outputs, sub):
17531753
if any(i.type in complex_types for i in node.inputs):
17541754
raise NotImplementedError()
17551755
# Test for both y>x and x>=y to detect NaN
1756-
return f"{z} = (({y})>({x})? ({y}): " f'(({x})>=({y})? ({x}): nan("")));'
1756+
return f'{z} = (({y})>({x})? ({y}): (({x})>=({y})? ({x}): nan("")));'
17571757

17581758
def L_op(self, inputs, outputs, gout):
17591759
(x, y) = inputs
@@ -1795,7 +1795,7 @@ def c_code(self, node, name, inputs, outputs, sub):
17951795
(z,) = outputs
17961796
if any(i.type in complex_types for i in node.inputs):
17971797
raise NotImplementedError()
1798-
return f"{z} = (({y})<({x})? ({y}): " f'(({x})<=({y})? ({x}): nan("")));'
1798+
return f'{z} = (({y})<({x})? ({y}): (({x})<=({y})? ({x}): nan("")));'
17991799

18001800
def L_op(self, inputs, outputs, gout):
18011801
(x, y) = inputs

pytensor/sparse/basic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,8 @@ def make_node(self, x, index):
13821382
isinstance(ind, Variable) and getattr(ind, "ndim", -1) == 0
13831383
) or np.isscalar(ind):
13841384
raise NotImplementedError(
1385-
"PyTensor has no sparse vector"
1386-
+ "Use X[a:b, c:d], X[a:b, c:c+1] or X[a:b] instead."
1385+
"PyTensor has no sparse vector. "
1386+
"Use X[a:b, c:d], X[a:b, c:c+1] or X[a:b] instead."
13871387
)
13881388
else:
13891389
raise ValueError(

pytensor/tensor/conv/abstract_conv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,7 @@ def conv(
22842284
"""
22852285
if mode not in ("valid", "full"):
22862286
raise ValueError(
2287-
f"invalid mode {mode}, which must be either " '"valid" or "full"'
2287+
f'invalid mode {mode}, which must be either "valid" or "full"'
22882288
)
22892289
if isinstance(dilation, int):
22902290
dilation = (dilation,) * self.convdim

pytensor/tensor/fft.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def make_node(self, a, s=None):
8080
if a.ndim < 3:
8181
raise TypeError(
8282
f"{self.__class__.__name__}: input must have dimension >= 3, with "
83-
+ "first dimension batches and last real/imag parts"
83+
"first dimension batches and last real/imag parts"
8484
)
8585

8686
if s is None:

tests/tensor/test_blas_c.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ def test_force_gemv_init(self):
196196
if check_force_gemv_init():
197197
warn(
198198
"WARNING: The current BLAS requires PyTensor to initialize"
199-
+ " memory for some GEMV calls which will result in a minor"
200-
+ " degradation in performance for such calls."
199+
" memory for some GEMV calls which will result in a minor"
200+
" degradation in performance for such calls."
201201
)
202202

203203
def t_gemv1(self, m_shp):

0 commit comments

Comments
 (0)