diff --git a/pyproject.toml b/pyproject.toml index 705356fa13..81a1285da8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,8 +125,8 @@ line-length = 88 exclude = ["doc/", "pytensor/_version.py"] [tool.ruff.lint] -select = ["C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH"] -ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203"] +select = ["C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC"] +ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203", "ISC001"] [tool.ruff.lint.isort] diff --git a/pytensor/bin/pytensor_cache.py b/pytensor/bin/pytensor_cache.py index 66f074bf3f..b5d22876ec 100644 --- a/pytensor/bin/pytensor_cache.py +++ b/pytensor/bin/pytensor_cache.py @@ -30,9 +30,7 @@ def print_help(exit_status): print('Type "pytensor-cache clear" to erase the cache') print('Type "pytensor-cache list" to print the cache content') print('Type "pytensor-cache unlock" to unlock the cache directory') - print( - 'Type "pytensor-cache cleanup" to delete keys in the old ' "format/code version" - ) + print('Type "pytensor-cache cleanup" to delete keys in the old format/code version') print('Type "pytensor-cache purge" to force deletion of the cache directory') print( 'Type "pytensor-cache basecompiledir" ' diff --git a/pytensor/compile/debugmode.py b/pytensor/compile/debugmode.py index 672f9cf84d..bfcaf1ecf0 100644 --- a/pytensor/compile/debugmode.py +++ b/pytensor/compile/debugmode.py @@ -1614,14 +1614,10 @@ def f(): opt = str(reason[0][0]) msg = ( f"An optimization (probably {opt}) inserted an " - "apply node that raise an error." - + "\nThe information we have about this " - "optimizations is:" - + str(reason[0][1]) - + "\n" - + reason[0][2] - + "\n\nThe original exception: \n" - + str(e) + "apply node that raise an error.\n" + "The information we have about this optimization is:" + f"{reason[0][1]}\n{reason[0][2]}\n" + f"\nThe original exception: \n{e}" ) new_e = e.__class__(msg) exc_type, exc_value, exc_trace = sys.exc_info() @@ -1725,15 +1721,11 @@ def f(): raise opt = str(reason[0][0]) msg = ( - f"An optimization (probably {opt}) inserted " - "an apply node that raise an error." - + "\nThe information we have about this " - "optimizations is:" - + str(reason[0][1]) - + "\n" - + reason[0][2] - + "\n\nThe original exception: \n" - + str(e) + f"An optimization (probably {opt}) inserted an " + "apply node that raise an error.\n" + "The information we have about this optimization is:" + f"{reason[0][1]}\n{reason[0][2]}\n" + f"\nThe original exception: \n{e}" ) new_e = e.__class__(msg) exc_type, exc_value, exc_trace = sys.exc_info() diff --git a/pytensor/gradient.py b/pytensor/gradient.py index 6492de44fd..abf80bff43 100644 --- a/pytensor/gradient.py +++ b/pytensor/gradient.py @@ -802,20 +802,20 @@ def _node_to_pattern(node): if not isinstance(connection_pattern, list): raise TypeError( "Op.connection_pattern should return " - + f"list of list of bool, but for Op={node.op}" - + f"got {connection_pattern} with type {type(connection_pattern)}." + f"list of list of bool, but for Op={node.op}" + f"got {connection_pattern} with type {type(connection_pattern)}." ) if len(connection_pattern) != len(node.inputs): raise ValueError( f"{node.op}.connection_pattern should have {len(node.inputs)}" - + f" rows but has {len(connection_pattern)}." + f" rows but has {len(connection_pattern)}." ) for ii, output_pattern in enumerate(connection_pattern): if not isinstance(output_pattern, list): raise TypeError( f"{node.op}.connection_pattern should return" - + f" a list of lists, but element {int(ii)}" - + f"is {output_pattern} of type {type(output_pattern)}." + f" a list of lists, but element {int(ii)}" + f"is {output_pattern} of type {type(output_pattern)}." ) else: connection_pattern = [[True for output in node.outputs] for ipt in node.inputs] diff --git a/pytensor/graph/rewriting/db.py b/pytensor/graph/rewriting/db.py index a35ae6fe5d..f6cfac3a76 100644 --- a/pytensor/graph/rewriting/db.py +++ b/pytensor/graph/rewriting/db.py @@ -229,10 +229,10 @@ def __init__( def __str__(self): return ( "RewriteDatabaseQuery(" - + f"inc={self.include},ex={self.exclude}," - + f"require={self.require},subquery={self.subquery}," - + f"position_cutoff={self.position_cutoff}," - + f"extra_rewrites={self.extra_rewrites})" + f"inc={self.include},ex={self.exclude}," + f"require={self.require},subquery={self.subquery}," + f"position_cutoff={self.position_cutoff}," + f"extra_rewrites={self.extra_rewrites})" ) def __setstate__(self, state): diff --git a/pytensor/link/c/cmodule.py b/pytensor/link/c/cmodule.py index 942dafa7b7..d206c650e0 100644 --- a/pytensor/link/c/cmodule.py +++ b/pytensor/link/c/cmodule.py @@ -1744,9 +1744,7 @@ def std_lib_dirs_and_libs() -> tuple[list[str], ...] | None: if not os.path.exists(os.path.join(libdir, f)): print( "Your Python version is from Canopy. " - + "You need to install the package '" - + lib - + "' from Canopy package manager." + f"You need to install the package '{lib}' from Canopy package manager." ) libdirs = [ # Used in older Canopy @@ -1763,9 +1761,7 @@ def std_lib_dirs_and_libs() -> tuple[list[str], ...] | None: ): print( "Your Python version is from Canopy. " - + "You need to install the package '" - + lib - + "' from Canopy package manager." + f"You need to install the package '{lib}' from Canopy package manager." ) python_lib_dirs.insert(0, libdir) std_lib_dirs_and_libs.data = [libname], python_lib_dirs diff --git a/pytensor/link/utils.py b/pytensor/link/utils.py index 069498164b..c51b13c427 100644 --- a/pytensor/link/utils.py +++ b/pytensor/link/utils.py @@ -351,8 +351,8 @@ def raise_with_op( clients = [[c[0] for c in fgraph.clients[var]] for var in node.outputs] detailed_err_msg += ( f"Inputs shapes: {shapes}" - + f"\nInputs strides: {strides}" - + f"\nInputs values: {scalar_values}" + f"\nInputs strides: {strides}" + f"\nInputs values: {scalar_values}" ) if verbosity == "high": inpts = [ diff --git a/pytensor/scalar/basic.py b/pytensor/scalar/basic.py index 317baf680a..763323cdb2 100644 --- a/pytensor/scalar/basic.py +++ b/pytensor/scalar/basic.py @@ -1753,7 +1753,7 @@ def c_code(self, node, name, inputs, outputs, sub): if any(i.type in complex_types for i in node.inputs): raise NotImplementedError() # Test for both y>x and x>=y to detect NaN - return f"{z} = (({y})>({x})? ({y}): " f'(({x})>=({y})? ({x}): nan("")));' + return f'{z} = (({y})>({x})? ({y}): (({x})>=({y})? ({x}): nan("")));' def L_op(self, inputs, outputs, gout): (x, y) = inputs @@ -1795,7 +1795,7 @@ def c_code(self, node, name, inputs, outputs, sub): (z,) = outputs if any(i.type in complex_types for i in node.inputs): raise NotImplementedError() - return f"{z} = (({y})<({x})? ({y}): " f'(({x})<=({y})? ({x}): nan("")));' + return f'{z} = (({y})<({x})? ({y}): (({x})<=({y})? ({x}): nan("")));' def L_op(self, inputs, outputs, gout): (x, y) = inputs diff --git a/pytensor/sparse/basic.py b/pytensor/sparse/basic.py index e69d2196c2..a1f7fd5b13 100644 --- a/pytensor/sparse/basic.py +++ b/pytensor/sparse/basic.py @@ -1382,8 +1382,8 @@ def make_node(self, x, index): isinstance(ind, Variable) and getattr(ind, "ndim", -1) == 0 ) or np.isscalar(ind): raise NotImplementedError( - "PyTensor has no sparse vector" - + "Use X[a:b, c:d], X[a:b, c:c+1] or X[a:b] instead." + "PyTensor has no sparse vector. " + "Use X[a:b, c:d], X[a:b, c:c+1] or X[a:b] instead." ) else: raise ValueError( diff --git a/pytensor/tensor/conv/abstract_conv.py b/pytensor/tensor/conv/abstract_conv.py index 5b1c35e5f1..73d402cfca 100644 --- a/pytensor/tensor/conv/abstract_conv.py +++ b/pytensor/tensor/conv/abstract_conv.py @@ -2284,7 +2284,7 @@ def conv( """ if mode not in ("valid", "full"): raise ValueError( - f"invalid mode {mode}, which must be either " '"valid" or "full"' + f'invalid mode {mode}, which must be either "valid" or "full"' ) if isinstance(dilation, int): dilation = (dilation,) * self.convdim diff --git a/pytensor/tensor/fft.py b/pytensor/tensor/fft.py index 78cfc6439e..c04e26a6f8 100644 --- a/pytensor/tensor/fft.py +++ b/pytensor/tensor/fft.py @@ -80,7 +80,7 @@ def make_node(self, a, s=None): if a.ndim < 3: raise TypeError( f"{self.__class__.__name__}: input must have dimension >= 3, with " - + "first dimension batches and last real/imag parts" + "first dimension batches and last real/imag parts" ) if s is None: diff --git a/tests/tensor/test_blas_c.py b/tests/tensor/test_blas_c.py index 0f07a7366c..ee02bff71d 100644 --- a/tests/tensor/test_blas_c.py +++ b/tests/tensor/test_blas_c.py @@ -196,8 +196,8 @@ def test_force_gemv_init(self): if check_force_gemv_init(): warn( "WARNING: The current BLAS requires PyTensor to initialize" - + " memory for some GEMV calls which will result in a minor" - + " degradation in performance for such calls." + " memory for some GEMV calls which will result in a minor" + " degradation in performance for such calls." ) def t_gemv1(self, m_shp):