Skip to content

Commit b142cb5

Browse files
ArmavicaricardoV94
authored andcommitted
RUF safe autofixes
1 parent 9d7c2ec commit b142cb5

File tree

10 files changed

+12
-12
lines changed

10 files changed

+12
-12
lines changed

pytensor/graph/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def __hash__(self):
728728
return hash((type(self), self.id, self.type))
729729

730730
def __repr__(self):
731-
return f"{type(self).__name__}({repr(self.id)}, {repr(self.type)})"
731+
return f"{type(self).__name__}({self.id!r}, {self.type!r})"
732732

733733
def signature(self) -> tuple[_TypeType, _IdType]:
734734
return (self.type, self.id)
@@ -774,7 +774,7 @@ def __repr__(self):
774774
data_str = repr(self.data)
775775
if len(data_str) > 20:
776776
data_str = data_str[:10].strip() + " ... " + data_str[-10:].strip()
777-
return f"{type(self).__name__}({repr(self.type)}, data={data_str})"
777+
return f"{type(self).__name__}({self.type!r}, data={data_str})"
778778

779779
def clone(self, **kwargs):
780780
return self

pytensor/graph/rewriting/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ def __str__(self):
10911091
return getattr(self, "__name__", repr(self))
10921092

10931093
def __repr__(self):
1094-
return f"FromFunctionNodeRewriter({repr(self.fn)}, {repr(self._tracks)}, {repr(self.requirements)})"
1094+
return f"FromFunctionNodeRewriter({self.fn!r}, {self._tracks!r}, {self.requirements!r})"
10951095

10961096
def print_summary(self, stream=sys.stdout, level=0, depth=-1):
10971097
print(f"{' ' * level}{self.transform} id={id(self)}", file=stream)

pytensor/graph/rewriting/unify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __str__(self):
6969
return f"~{self.token} [{self.constraint}]"
7070

7171
def __repr__(self):
72-
return f"{type(self).__name__}({repr(self.constraint)}, {self.token})"
72+
return f"{type(self).__name__}({self.constraint!r}, {self.token})"
7373

7474

7575
def car_Variable(x):

pytensor/link/c/type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def c_support_code(self, **kwargs):
607607
self.pyint_compat_code
608608
+ "".join(
609609
f"""
610-
#define {k} {str(self[k])}
610+
#define {k} {self[k]!s}
611611
"""
612612
for k in sorted(self.keys())
613613
)

pytensor/tensor/blas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"PyTensor flag blas__ldflags is empty. "
138138
"Falling back on slower implementations for "
139139
"dot(matrix, vector), dot(vector, matrix) and "
140-
f"dot(vector, vector) ({str(e)})"
140+
f"dot(vector, vector) ({e!s})"
141141
)
142142

143143

pytensor/tensor/elemwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def as_scalar(t):
602602

603603
if not isinstance(scalar_igrads, (list, tuple)):
604604
raise TypeError(
605-
f"{str(self.scalar_op)}.grad returned {str(type(scalar_igrads))} instead of list or tuple"
605+
f"{self.scalar_op!s}.grad returned {type(scalar_igrads)!s} instead of list or tuple"
606606
)
607607

608608
nd = inputs[0].type.ndim # this is the same for everyone

pytensor/tensor/random/var.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

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

1313

1414
class RandomGeneratorSharedVariable(SharedVariable):
1515
def __str__(self):
16-
return self.name or f"RandomGeneratorSharedVariable({repr(self.container)})"
16+
return self.name or f"RandomGeneratorSharedVariable({self.container!r})"
1717

1818

1919
@shared_constructor.register(np.random.RandomState)

pytensor/tensor/rewriting/shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def get_node_infer_shape(self, node):
150150
msg = (
151151
f"Failed to infer_shape from Op {node.op}.\nInput shapes: "
152152
f"{[self.shape_of[r] for r in node.inputs]}\nException encountered during infer_shape: "
153-
f"{type(e)}\nException message: {str(e)}\nTraceback: {traceback.format_exc()}"
153+
f"{type(e)}\nException message: {e!s}\nTraceback: {traceback.format_exc()}"
154154
)
155155
if config.on_shape_error == "raise":
156156
raise Exception(msg).with_traceback(e.__traceback__)

pytensor/tensor/type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def filter(self, data, strict=False, allow_downcast=None):
199199
"this loss, you can: "
200200
f"1) explicitly cast your data to {self.dtype}, or "
201201
'2) set "allow_input_downcast=True" when calling '
202-
f'"function". Value: "{repr(data)}"'
202+
f'"function". Value: "{data!r}"'
203203
)
204204
raise TypeError(err_msg)
205205
elif (

tests/graph/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ def test_NominalVariable():
683683
assert not nv4.equals(nv5)
684684
assert hash(nv4) != hash(nv5)
685685

686-
assert repr(nv5) == f"NominalVariable(2, {repr(type3)})"
686+
assert repr(nv5) == f"NominalVariable(2, {type3!r})"
687687

688688
assert nv5.signature() == (type3, 2)
689689

0 commit comments

Comments
 (0)