Skip to content

Commit 17748b7

Browse files
committed
Remove accidental print statements
1 parent 4ac1e63 commit 17748b7

33 files changed

+161
-168
lines changed

pyproject.toml

+9-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ exclude = ["doc/", "pytensor/_version.py"]
129129
docstring-code-format = true
130130

131131
[tool.ruff.lint]
132-
select = ["B905", "C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC"]
132+
select = ["B905", "C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC", "T20"]
133133
ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203", "ISC001"]
134134
unfixable = [
135135
# zip-strict: the auto-fix adds `strict=False` but we might want `strict=True` instead
@@ -144,7 +144,12 @@ lines-after-imports = 2
144144
# TODO: Get rid of these:
145145
"**/__init__.py" = ["F401", "E402", "F403"]
146146
"pytensor/tensor/linalg.py" = ["F403"]
147-
"pytensor/link/c/cmodule.py" = ["PTH"]
147+
"pytensor/link/c/cmodule.py" = ["PTH", "T201"]
148+
"pytensor/misc/elemwise_time_test.py" = ["T201"]
149+
"pytensor/misc/elemwise_openmp_speedup.py" = ["T201"]
150+
"pytensor/misc/check_duplicate_key.py" = ["T201"]
151+
"pytensor/misc/check_blas.py" = ["T201"]
152+
"pytensor/bin/pytensor_cache.py" = ["T201"]
148153
# For the tests we skip because `pytest.importorskip` is used:
149154
"tests/link/jax/test_scalar.py" = ["E402"]
150155
"tests/link/jax/test_tensor_basic.py" = ["E402"]
@@ -158,6 +163,8 @@ lines-after-imports = 2
158163
"tests/sparse/test_sp2.py" = ["E402"]
159164
"tests/sparse/test_utils.py" = ["E402"]
160165
"tests/sparse/sandbox/test_sp.py" = ["E402", "F401"]
166+
"tests/compile/test_monitormode.py" = ["T201"]
167+
"scripts/run_mypy.py" = ["T201"]
161168

162169

163170
[tool.mypy]

pytensor/breakpoint.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ def perform(self, node, inputs, output_storage):
108108
f"'{self.name}' could not be casted to NumPy arrays"
109109
)
110110

111-
print("\n")
112-
print("-------------------------------------------------")
113-
print(f"Conditional breakpoint '{self.name}' activated\n")
114-
print("The monitored variables are stored, in order,")
115-
print("in the list variable 'monitored' as NumPy arrays.\n")
116-
print("Their contents can be altered and, when execution")
117-
print("resumes, the updated values will be used.")
118-
print("-------------------------------------------------")
111+
print("\n") # noqa: T201
112+
print("-------------------------------------------------") # noqa: T201
113+
print(f"Conditional breakpoint '{self.name}' activated\n") # noqa: T201
114+
print("The monitored variables are stored, in order,") # noqa: T201
115+
print("in the list variable 'monitored' as NumPy arrays.\n") # noqa: T201
116+
print("Their contents can be altered and, when execution") # noqa: T201
117+
print("resumes, the updated values will be used.") # noqa: T201
118+
print("-------------------------------------------------") # noqa: T201
119119

120120
try:
121121
import pudb

pytensor/compile/compiledir.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def cleanup():
9595
def print_title(title, overline="", underline=""):
9696
len_title = len(title)
9797
if overline:
98-
print(str(overline) * len_title)
99-
print(title)
98+
print(str(overline) * len_title) # noqa: T201
99+
print(title) # noqa: T201
100100
if underline:
101-
print(str(underline) * len_title)
101+
print(str(underline) * len_title) # noqa: T201
102102

103103

104104
def print_compiledir_content():
@@ -159,7 +159,7 @@ def print_compiledir_content():
159159
_logger.error(f"Could not read key file '{filename}'.")
160160

161161
print_title(f"PyTensor cache: {compiledir}", overline="=", underline="=")
162-
print()
162+
print() # noqa: T201
163163

164164
print_title(f"List of {len(table)} compiled individual ops", underline="+")
165165
print_title(
@@ -168,9 +168,9 @@ def print_compiledir_content():
168168
)
169169
table = sorted(table, key=lambda t: str(t[1]))
170170
for dir, op, types, compile_time in table:
171-
print(dir, f"{compile_time:.3f}s", op, types)
171+
print(dir, f"{compile_time:.3f}s", op, types) # noqa: T201
172172

173-
print()
173+
print() # noqa: T201
174174
print_title(
175175
f"List of {len(table_multiple_ops)} compiled sets of ops", underline="+"
176176
)
@@ -180,9 +180,9 @@ def print_compiledir_content():
180180
)
181181
table_multiple_ops = sorted(table_multiple_ops, key=lambda t: (t[1], t[2]))
182182
for dir, ops_to_str, types_to_str, compile_time in table_multiple_ops:
183-
print(dir, f"{compile_time:.3f}s", ops_to_str, types_to_str)
183+
print(dir, f"{compile_time:.3f}s", ops_to_str, types_to_str) # noqa: T201
184184

185-
print()
185+
print() # noqa: T201
186186
print_title(
187187
(
188188
f"List of {len(table_op_class)} compiled Op classes and "
@@ -191,33 +191,33 @@ def print_compiledir_content():
191191
underline="+",
192192
)
193193
for op_class, nb in reversed(table_op_class.most_common()):
194-
print(op_class, nb)
194+
print(op_class, nb) # noqa: T201
195195

196196
if big_key_files:
197197
big_key_files = sorted(big_key_files, key=lambda t: str(t[1]))
198198
big_total_size = sum(sz for _, sz, _ in big_key_files)
199-
print(
199+
print( # noqa: T201
200200
f"There are directories with key files bigger than {int(max_key_file_size)} bytes "
201201
"(they probably contain big tensor constants)"
202202
)
203-
print(
203+
print( # noqa: T201
204204
f"They use {int(big_total_size)} bytes out of {int(total_key_sizes)} (total size "
205205
"used by all key files)"
206206
)
207207

208208
for dir, size, ops in big_key_files:
209-
print(dir, size, ops)
209+
print(dir, size, ops) # noqa: T201
210210

211211
nb_keys = sorted(nb_keys.items())
212-
print()
212+
print() # noqa: T201
213213
print_title("Number of keys for a compiled module", underline="+")
214214
print_title(
215215
"number of keys/number of modules with that number of keys", underline="-"
216216
)
217217
for n_k, n_m in nb_keys:
218-
print(n_k, n_m)
219-
print()
220-
print(
218+
print(n_k, n_m) # noqa: T201
219+
print() # noqa: T201
220+
print( # noqa: T201
221221
f"Skipped {int(zeros_op)} files that contained 0 op "
222222
"(are they always pytensor.scalar ops?)"
223223
)
@@ -242,18 +242,18 @@ def basecompiledir_ls():
242242
subdirs = sorted(subdirs)
243243
others = sorted(others)
244244

245-
print(f"Base compile dir is {config.base_compiledir}")
246-
print("Sub-directories (possible compile caches):")
245+
print(f"Base compile dir is {config.base_compiledir}") # noqa: T201
246+
print("Sub-directories (possible compile caches):") # noqa: T201
247247
for d in subdirs:
248-
print(f" {d}")
248+
print(f" {d}") # noqa: T201
249249
if not subdirs:
250-
print(" (None)")
250+
print(" (None)") # noqa: T201
251251

252252
if others:
253-
print()
254-
print("Other files in base_compiledir:")
253+
print() # noqa: T201
254+
print("Other files in base_compiledir:") # noqa: T201
255255
for f in others:
256-
print(f" {f}")
256+
print(f" {f}") # noqa: T201
257257

258258

259259
def basecompiledir_purge():

pytensor/compile/debugmode.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1315,9 +1315,9 @@ def on_change_input(self, fgraph, node, i, r, new_r, reason=None):
13151315

13161316
def printstuff(self):
13171317
for key in self.equiv:
1318-
print(key)
1318+
print(key) # noqa: T201
13191319
for e in self.equiv[key]:
1320-
print(" ", e)
1320+
print(" ", e) # noqa: T201
13211321

13221322

13231323
# List of default version of make thunk.
@@ -1569,7 +1569,7 @@ def f():
15691569
#####
15701570
for r, s in storage_map.items():
15711571
if s[0] is not None:
1572-
print(r, s)
1572+
print(r, s) # noqa: T201
15731573
assert s[0] is None
15741574

15751575
# try:
@@ -2079,7 +2079,7 @@ def __init__(
20792079
raise StochasticOrder(infolog.getvalue())
20802080
else:
20812081
if self.verbose:
2082-
print(
2082+
print( # noqa: T201
20832083
"OPTCHECK: optimization",
20842084
i,
20852085
"of",

pytensor/compile/mode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def __init__(self, header):
178178
def apply(self, fgraph):
179179
import pytensor.printing
180180

181-
print("PrintCurrentFunctionGraph:", self.header)
181+
print("PrintCurrentFunctionGraph:", self.header) # noqa: T201
182182
pytensor.printing.debugprint(fgraph.outputs)
183183

184184

pytensor/compile/monitormode.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def detect_nan(fgraph, i, node, fn):
108108
not isinstance(output[0], np.random.RandomState | np.random.Generator)
109109
and np.isnan(output[0]).any()
110110
):
111-
print("*** NaN detected ***")
111+
print("*** NaN detected ***") # noqa: T201
112112
debugprint(node)
113-
print(f"Inputs : {[input[0] for input in fn.inputs]}")
114-
print(f"Outputs: {[output[0] for output in fn.outputs]}")
113+
print(f"Inputs : {[input[0] for input in fn.inputs]}") # noqa: T201
114+
print(f"Outputs: {[output[0] for output in fn.outputs]}") # noqa: T201
115115
break

pytensor/compile/nanguardmode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def do_check_on(value, nd, var=None):
236236
if config.NanGuardMode__action == "raise":
237237
raise AssertionError(msg)
238238
elif config.NanGuardMode__action == "pdb":
239-
print(msg)
239+
print(msg) # noqa: T201
240240
import pdb
241241

242242
pdb.set_trace()

pytensor/compile/profiling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _atexit_print_fn():
8282
to_sum.append(ps)
8383
else:
8484
# TODO print the name if there is one!
85-
print("Skipping empty Profile")
85+
print("Skipping empty Profile") # noqa: T201
8686
if len(to_sum) > 1:
8787
# Make a global profile
8888
cum = copy.copy(to_sum[0])
@@ -125,7 +125,7 @@ def _atexit_print_fn():
125125
assert len(merge) == len(cum.rewriter_profile[1])
126126
cum.rewriter_profile = (cum.rewriter_profile[0], merge)
127127
except Exception as e:
128-
print(e)
128+
print(e) # noqa: T201
129129
cum.rewriter_profile = None
130130
else:
131131
cum.rewriter_profile = None

pytensor/graph/features.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def validate_(self, fgraph):
491491
if verbose:
492492
r = uf.f_locals.get("r", "")
493493
reason = uf_info.function
494-
print(f"validate failed on node {r}.\n Reason: {reason}, {e}")
494+
print(f"validate failed on node {r}.\n Reason: {reason}, {e}") # noqa: T201
495495
raise
496496
t1 = time.perf_counter()
497497
if fgraph.profile:
@@ -603,13 +603,13 @@ def replace_all_validate(
603603
except Exception as e:
604604
fgraph.revert(chk)
605605
if verbose:
606-
print(
606+
print( # noqa: T201
607607
f"rewriting: validate failed on node {r}.\n Reason: {reason}, {e}"
608608
)
609609
raise
610610

611611
if verbose:
612-
print(
612+
print( # noqa: T201
613613
f"rewriting: rewrite {reason} replaces {r} of {r.owner} with {new_r} of {new_r.owner}"
614614
)
615615

@@ -692,11 +692,11 @@ def on_import(self, fgraph, node, reason):
692692
except TypeError: # node.op is unhashable
693693
return
694694
except Exception as e:
695-
print("OFFENDING node", type(node), type(node.op), file=sys.stderr)
695+
print("OFFENDING node", type(node), type(node.op), file=sys.stderr) # noqa: T201
696696
try:
697-
print("OFFENDING node hash", hash(node.op), file=sys.stderr)
697+
print("OFFENDING node hash", hash(node.op), file=sys.stderr) # noqa: T201
698698
except Exception:
699-
print("OFFENDING node not hashable", file=sys.stderr)
699+
print("OFFENDING node not hashable", file=sys.stderr) # noqa: T201
700700
raise e
701701

702702
def on_prune(self, fgraph, node, reason):
@@ -725,27 +725,27 @@ def __init__(self, active=True):
725725

726726
def on_attach(self, fgraph):
727727
if self.active:
728-
print("-- attaching to: ", fgraph)
728+
print("-- attaching to: ", fgraph) # noqa: T201
729729

730730
def on_detach(self, fgraph):
731731
"""
732732
Should remove any dynamically added functionality
733733
that it installed into the function_graph
734734
"""
735735
if self.active:
736-
print("-- detaching from: ", fgraph)
736+
print("-- detaching from: ", fgraph) # noqa: T201
737737

738738
def on_import(self, fgraph, node, reason):
739739
if self.active:
740-
print(f"-- importing: {node}, reason: {reason}")
740+
print(f"-- importing: {node}, reason: {reason}") # noqa: T201
741741

742742
def on_prune(self, fgraph, node, reason):
743743
if self.active:
744-
print(f"-- pruning: {node}, reason: {reason}")
744+
print(f"-- pruning: {node}, reason: {reason}") # noqa: T201
745745

746746
def on_change_input(self, fgraph, node, i, r, new_r, reason=None):
747747
if self.active:
748-
print(f"-- changing ({node}.inputs[{i}]) from {r} to {new_r}")
748+
print(f"-- changing ({node}.inputs[{i}]) from {r} to {new_r}") # noqa: T201
749749

750750

751751
class PreserveVariableAttributes(Feature):

pytensor/graph/fg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def replace(
491491
if verbose is None:
492492
verbose = config.optimizer_verbose
493493
if verbose:
494-
print(
494+
print( # noqa: T201
495495
f"rewriting: rewrite {reason} replaces {var} of {var.owner} with {new_var} of {new_var.owner}"
496496
)
497497

0 commit comments

Comments
 (0)