Skip to content

Commit 491f93e

Browse files
Some pylint and pyupgrade cleanups (#29)
* Fix line endings of empty files * Use `not in` for membership test * Remove unused imports * Fix implicit string concatenation * Remove python 2 coding statement * Change python2's Text into str * Remove useless linebreaks * Remove useless parentheses * Use new-style dictionary and set constructors * There is no more IOError (alias to OSError now) * Use .format instead of % string interpolation * Use super() without redundant arguments * Remove redundant read flag from open * Avoid building lists unnecessarily * Use f-strings with python 3.6 * Black reformat Co-authored-by: Michael Osthege <[email protected]>
1 parent 2d0ae94 commit 491f93e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+398
-467
lines changed

doc/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# pytensor documentation build configuration file, created by
42
# sphinx-quickstart on Tue Oct 7 16:34:06 2008.
53
#

doc/extending/extending_pytensor_solution_1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def grad(self, inputs, output_grads):
7373
import numpy as np
7474

7575
from tests import unittest_tools as utt
76-
from pytensor import function, printing
7776
from pytensor import tensor as at
7877
from pytensor.graph.basic import Apply
7978
from pytensor.graph.op import Op

doc/generate_dtype_tensor_table.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
letters = [
42
('b', 'int8'),
53
('w', 'int16'),

doc/scripts/docgen.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
21
import sys
32
import os
43
import shutil
5-
import inspect
64
import getopt
75
from collections import defaultdict
86

@@ -16,7 +14,7 @@
1614
sys.argv[1:],
1715
'o:f:',
1816
['rst', 'help', 'nopdf', 'cache', 'check', 'test'])
19-
options.update(dict([x, y or True] for x, y in opts))
17+
options.update({x: y or True for x, y in opts})
2018
if options['--help']:
2119
print(f'Usage: {sys.argv[0]} [OPTIONS] [files...]')
2220
print(' -o <dir>: output the html files in the specified dir')
@@ -100,8 +98,6 @@ def call_sphinx(builder, workdir):
10098
shutil.rmtree(workdir)
10199
except OSError as e:
102100
print('OSError:', e)
103-
except IOError as e:
104-
print('IOError:', e)
105101

106102
if options['--test']:
107103
mkdir("doc")

pytensor/_version.py

Lines changed: 3 additions & 3 deletions
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 %s" % (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:
@@ -155,7 +155,7 @@ def git_get_keywords(versionfile_abs):
155155
# _version.py.
156156
keywords = {}
157157
try:
158-
with open(versionfile_abs, "r") as fobj:
158+
with open(versionfile_abs) as fobj:
159159
for line in fobj:
160160
if line.strip().startswith("git_refnames ="):
161161
mo = re.search(r'=\s*"(.*)"', line)
@@ -351,7 +351,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
351351
if verbose:
352352
fmt = "tag '%s' doesn't start with prefix '%s'"
353353
print(fmt % (full_tag, tag_prefix))
354-
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
354+
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
355355
full_tag,
356356
tag_prefix,
357357
)

pytensor/compile/debugmode.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ def f():
16041604
# storage will be None
16051605
if thunk_py:
16061606
_logger.debug(
1607-
f"{i} - running thunk_py with None as " "output storage"
1607+
f"{i} - running thunk_py with None as output storage"
16081608
)
16091609
try:
16101610
thunk_py()
@@ -2063,15 +2063,15 @@ def __init__(
20632063
infolog = StringIO()
20642064
print("Optimization process is unstable...", file=infolog)
20652065
print(
2066-
" (HINT: Ops that the nodes point to must compare " "equal)",
2066+
" (HINT: Ops that the nodes point to must compare equal)",
20672067
file=infolog,
20682068
)
20692069
print(
2070-
"(event index) (one event trace) (other event " "trace)",
2070+
"(event index) (one event trace) (other event trace)",
20712071
file=infolog,
20722072
)
20732073
print(
2074-
"-------------------------------------------------" "----",
2074+
"-----------------------------------------------------",
20752075
file=infolog,
20762076
)
20772077
for j in range(max(len(li), len(l0))):
@@ -2292,7 +2292,7 @@ def __init__(
22922292

22932293
if not isinstance(linker, _DummyLinker):
22942294
raise Exception(
2295-
"DebugMode can only use its own linker! You " "should not provide one.",
2295+
"DebugMode can only use its own linker! You should not provide one.",
22962296
linker,
22972297
)
22982298

@@ -2318,7 +2318,7 @@ def __init__(
23182318
self.require_matching_strides = require_matching_strides
23192319

23202320
if not (self.check_c_code or self.check_py_code):
2321-
raise ValueError("DebugMode has to check at least one of c and py " "code")
2321+
raise ValueError("DebugMode has to check at least one of c and py code")
23222322

23232323
def __str__(self):
23242324
return "DebugMode(linker={}, optimizer={})".format(

pytensor/compile/function/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,7 @@ def opt_log1p(node):
300300
if uses_tuple:
301301
# we must use old semantics in this case.
302302
if profile:
303-
raise NotImplementedError(
304-
"profiling not supported in old-style " "function"
305-
)
303+
raise NotImplementedError("profiling not supported in old-style function")
306304
if uses_updates or uses_givens:
307305
raise NotImplementedError(
308306
"In() instances and tuple inputs trigger the old "

pytensor/compile/function/pfunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def clone_inputs(i):
181181
raise TypeError("update target must be a SharedVariable", store_into)
182182
if store_into in update_d:
183183
raise ValueError(
184-
"this shared variable already has an update " "expression",
184+
"this shared variable already has an update expression",
185185
(store_into, update_d[store_into]),
186186
)
187187

pytensor/compile/nanguardmode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def do_check_on(value, nd, var=None):
225225
print(pytensor.printing.debugprint(nd, file="str"), file=sio)
226226
else:
227227
print(
228-
"NanGuardMode found an error in an input of the " "graph.",
228+
"NanGuardMode found an error in an input of the graph.",
229229
file=sio,
230230
)
231231
# Add the stack trace

pytensor/compile/profiling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ def compute_max_stats(running_memory, stats):
13081308

13091309
if len(fct_memory) > 1:
13101310
print(
1311-
"Memory Profile (the max between all functions in " "that profile)",
1311+
"Memory Profile (the max between all functions in that profile)",
13121312
file=file,
13131313
)
13141314
else:

0 commit comments

Comments
 (0)