Skip to content

Commit cbcd78c

Browse files
authored
Merge pull request #251 from bluetech/more-lints
Enable more lints
2 parents ca51b8d + 0c11822 commit cbcd78c

16 files changed

+62
-43
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ repos:
1111
- repo: https://github.com/pre-commit/pre-commit-hooks
1212
rev: v4.5.0
1313
hooks:
14-
- id: trailing-whitespace
15-
- id: end-of-file-fixer
1614
- id: check-yaml
17-
- repo: https://github.com/asottile/pyupgrade
18-
rev: v3.15.1
19-
hooks:
20-
- id: pyupgrade
21-
args: [--py38-plus]
2215
- repo: https://github.com/astral-sh/ruff-pre-commit
2316
rev: v0.2.2
2417
hooks:

pyproject.toml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,35 @@ testing = [
4646
Homepage = "https://execnet.readthedocs.io/en/latest/"
4747

4848
[tool.ruff.lint]
49-
ignore = ["E741"]
50-
extend-select = ["I001"]
49+
extend-select = [
50+
"B", # bugbear
51+
"E", # pycodestyle
52+
"F", # pyflakes
53+
"I", # isort
54+
"PYI", # flake8-pyi
55+
"UP", # pyupgrade
56+
"RUF", # ruff
57+
"W", # pycodestyle
58+
"PIE", # flake8-pie
59+
"PGH", # pygrep-hooks
60+
"PLE", # pylint error
61+
"PLW", # pylint warning
62+
]
63+
ignore = [
64+
# bugbear ignore
65+
"B007", # Loop control variable `i` not used within loop body
66+
"B011", # Do not `assert False` (`python -O` removes these calls)
67+
# pycodestyle ignore
68+
"E501", # Line too long
69+
"E741", # Ambiguous variable name
70+
# ruff ignore
71+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
72+
# pylint ignore
73+
"PLW0603", # Using the global statement
74+
"PLW0120", # remove the else and dedent its contents
75+
"PLW2901", # for loop variable overwritten by assignment target
76+
"PLR5501", # Use `elif` instead of `else` then `if`
77+
]
5178

5279
[tool.ruff.lint.isort]
5380
force-single-line = true

src/execnet/gateway.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __init__(self, kwargs):
143143
self.__dict__.update(kwargs)
144144

145145
def __repr__(self):
146-
info = ", ".join("%s=%s" % item for item in sorted(self.__dict__.items()))
146+
info = ", ".join(f"{k}={v}" for k, v in sorted(self.__dict__.items()))
147147
return "<RInfo %r>" % info
148148

149149

@@ -201,8 +201,8 @@ def _source_of_function(function):
201201

202202
try:
203203
source = inspect.getsource(function)
204-
except OSError:
205-
raise ValueError("can't find source file for %s" % function)
204+
except OSError as e:
205+
raise ValueError("can't find source file for %s" % function) from e
206206

207207
source = textwrap.dedent(source) # just for inner functions
208208

src/execnet/gateway_base.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def get(self, timeout=None):
289289
try:
290290
return self._result
291291
except AttributeError:
292-
raise self._exc
292+
raise self._exc from None
293293

294294
def waitfinish(self, timeout=None):
295295
if not self._result_ready.wait(timeout):
@@ -528,7 +528,7 @@ def from_io(io):
528528
if not header:
529529
raise EOFError("empty read")
530530
except EOFError as e:
531-
raise EOFError("couldn't load message header, " + e.args[0])
531+
raise EOFError("couldn't load message header, " + e.args[0]) from None
532532
msgtype, channel, payload = struct.unpack("!bii", header)
533533
return Message(msgtype, channel, io.read(payload))
534534

@@ -542,9 +542,7 @@ def received(self, gateway):
542542

543543
def __repr__(self):
544544
name = self._types[self.msgcode][0]
545-
return "<Message {} channel={} lendata={}>".format(
546-
name, self.channelid, len(self.data)
547-
)
545+
return f"<Message {name} channel={self.channelid} lendata={len(self.data)}>"
548546

549547
def _status(message, gateway):
550548
# we use the channelid to send back information
@@ -851,7 +849,7 @@ def receive(self, timeout=None):
851849
try:
852850
x = itemqueue.get(timeout=timeout)
853851
except self.gateway.execmodel.queue.Empty:
854-
raise self.TimeoutError("no item after %r seconds" % timeout)
852+
raise self.TimeoutError("no item after %r seconds" % timeout) from None
855853
if x is ENDMARKER:
856854
itemqueue.put(x) # for other receivers
857855
raise self._getremoteerror() or EOFError()
@@ -865,7 +863,7 @@ def next(self):
865863
try:
866864
return self.receive()
867865
except EOFError:
868-
raise StopIteration
866+
raise StopIteration from None
869867

870868
__next__ = next
871869

@@ -1108,7 +1106,7 @@ def _send(self, msgcode, channelid=0, data=b""):
11081106
except (OSError, ValueError) as e:
11091107
self._trace("failed to send", message, e)
11101108
# ValueError might be because the IO is already closed
1111-
raise OSError("cannot send (already closed?)")
1109+
raise OSError("cannot send (already closed?)") from e
11121110

11131111
def _local_schedulexec(self, channel, sourcetask):
11141112
channel.close("execution disallowed")
@@ -1316,12 +1314,12 @@ def load(self, versioned=False):
13161314
loader = self.num2func[opcode]
13171315
except KeyError:
13181316
raise LoadError(
1319-
"unknown opcode %r - " "wire protocol corruption?" % (opcode,)
1320-
)
1317+
f"unknown opcode {opcode!r} - wire protocol corruption?"
1318+
) from None
13211319
loader(self)
13221320
except _Stop:
13231321
if len(self.stack) != 1:
1324-
raise LoadError("internal unserialization error")
1322+
raise LoadError("internal unserialization error") from None
13251323
return self.stack.pop(0)
13261324
else:
13271325
raise LoadError("didn't get STOP")
@@ -1550,7 +1548,7 @@ def _save(self, obj):
15501548
methodname = "save_" + tp.__name__
15511549
meth = getattr(self.__class__, methodname, None)
15521550
if meth is None:
1553-
raise DumpError(f"can't serialize {tp}")
1551+
raise DumpError(f"can't serialize {tp}") from None
15541552
dispatch = self._dispatch[tp] = meth
15551553
dispatch(self, obj)
15561554

@@ -1574,8 +1572,8 @@ def save_str(self, s):
15741572
def _write_unicode_string(self, s):
15751573
try:
15761574
as_bytes = s.encode("utf-8")
1577-
except UnicodeEncodeError:
1578-
raise DumpError("strings must be utf-8 encodable")
1575+
except UnicodeEncodeError as e:
1576+
raise DumpError("strings must be utf-8 encodable") from e
15791577
self._write_byte_sequence(as_bytes)
15801578

15811579
def _write_byte_sequence(self, bytes_):
@@ -1593,7 +1591,7 @@ def _save_integral(self, i, short_op, long_op):
15931591
def save_int(self, i):
15941592
self._save_integral(i, opcode.INT, opcode.LONGINT)
15951593

1596-
def save_long(self, l): # noqa:E741
1594+
def save_long(self, l):
15971595
self._save_integral(l, opcode.LONG, opcode.LONGLONG)
15981596

15991597
def save_float(self, flt):

src/execnet/gateway_bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def bootstrap_exec(io, spec):
5050
except EOFError:
5151
ret = io.wait()
5252
if ret == 255:
53-
raise HostNotFound(io.remoteaddress)
53+
raise HostNotFound(io.remoteaddress) from None
5454

5555

5656
def bootstrap_socket(io, id):

src/execnet/rsync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RSync:
2424
def __init__(self, sourcedir, callback=None, verbose=True):
2525
self._sourcedir = str(sourcedir)
2626
self._verbose = verbose
27-
assert callback is None or hasattr(callback, "__call__")
27+
assert callback is None or callable(callback)
2828
self._callback = callback
2929
self._channels = {}
3030
self._receivequeue = Queue()
@@ -168,7 +168,7 @@ def _send_directory(self, path):
168168
names.append(name)
169169
subpaths.append(p)
170170
mode = os.lstat(path).st_mode
171-
self._broadcast([mode] + names)
171+
self._broadcast([mode, *names])
172172
for p in subpaths:
173173
self._send_directory_structure(p)
174174

src/execnet/rsync_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def receive_directory_structure(path, relcomponents):
4242
entrynames = {}
4343
for entryname in msg:
4444
destpath = os.path.join(path, entryname)
45-
receive_directory_structure(destpath, relcomponents + [entryname])
45+
receive_directory_structure(destpath, [*relcomponents, entryname])
4646
entrynames[entryname] = True
4747
if options.get("delete"):
4848
for othername in os.listdir(path):

src/execnet/script/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def run(self):
5555

5656
while 1:
5757
try:
58-
clientfile.write("%s %s >>> " % loc)
58+
clientfile.write("{} {} >>> ".format(*loc))
5959
clientfile.flush()
6060
line = filein.readline()
6161
if not line:

src/execnet/script/socketserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def print_(*args):
4848
def exec_from_one_connection(serversock):
4949
print_(progname, "Entering Accept loop", serversock.getsockname())
5050
clientsock, address = serversock.accept()
51-
print_(progname, "got new connection from %s %s" % address)
51+
print_(progname, "got new connection from {} {}".format(*address))
5252
clientfile = clientsock.makefile("rb")
5353
print_("reading line")
5454
# rstrip so that we can use \r\n for telnet testing
@@ -60,7 +60,7 @@ def exec_from_one_connection(serversock):
6060
co = compile(source + "\n", "<socket server>", "exec")
6161
print_(progname, "compiled source, executing")
6262
try:
63-
exec_(co, g) # noqa
63+
exec_(co, g) # noqa: F821
6464
finally:
6565
print_(progname, "finished executing code")
6666
# background thread might hold a reference to this (!?)

testing/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ def gw(request, execmodel, group):
152152
proxygw = group.makegateway("popen//id=%s" % pname)
153153
# assert group['proxygw'].remote_status().receiving
154154
gw = group.makegateway(
155-
"socket//id=socket//installvia=%s"
156-
"//execmodel=%s" % (pname, execmodel.backend)
155+
f"socket//id=socket//installvia={pname}"
156+
f"//execmodel={execmodel.backend}"
157157
)
158158
gw.proxygw = proxygw
159159
assert pname in group

0 commit comments

Comments
 (0)