Skip to content

Commit b1c8b7e

Browse files
pylint: fix no-else-return cases
Fix all cases of R1705 no-else-return. Part of #270
1 parent 9194944 commit b1c8b7e

8 files changed

Lines changed: 41 additions & 41 deletions

File tree

tarantool/connection.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,26 +1207,26 @@ def check(): # Check that connection is alive
12071207
if exc.errno == errno.EBADF:
12081208
return errno.ECONNRESET
12091209
return exc.errno
1210+
1211+
if os.name == 'nt':
1212+
flag = socket.MSG_PEEK
1213+
self._socket.setblocking(False)
12101214
else:
1211-
if os.name == 'nt':
1212-
flag = socket.MSG_PEEK
1213-
self._socket.setblocking(False)
1214-
else:
1215-
flag = socket.MSG_DONTWAIT | socket.MSG_PEEK
1216-
retbytes = self._sys_recv(sock_fd, buf, 1, flag)
1217-
1218-
err = 0
1219-
if os.name!= 'nt':
1220-
err = ctypes.get_errno()
1221-
else:
1222-
err = ctypes.get_last_error()
1223-
self._socket.setblocking(True)
1224-
1225-
if (retbytes < 0) and err in (errno.EAGAIN, errno.EWOULDBLOCK, WWSAEWOULDBLOCK):
1226-
ctypes.set_errno(0)
1227-
return errno.EAGAIN
1228-
else:
1229-
return errno.ECONNRESET
1215+
flag = socket.MSG_DONTWAIT | socket.MSG_PEEK
1216+
retbytes = self._sys_recv(sock_fd, buf, 1, flag)
1217+
1218+
err = 0
1219+
if os.name!= 'nt':
1220+
err = ctypes.get_errno()
1221+
else:
1222+
err = ctypes.get_last_error()
1223+
self._socket.setblocking(True)
1224+
1225+
if (retbytes < 0) and err in (errno.EAGAIN, errno.EWOULDBLOCK, WWSAEWOULDBLOCK):
1226+
ctypes.set_errno(0)
1227+
return errno.EAGAIN
1228+
1229+
return errno.ECONNRESET
12301230

12311231
last_errno = check()
12321232
if self.connected and last_errno == errno.EAGAIN:
@@ -1561,7 +1561,7 @@ def _join_v17(self, server_uuid):
15611561
yield resp
15621562
if resp.code >= REQUEST_TYPE_ERROR:
15631563
return
1564-
elif resp.code == REQUEST_TYPE_OK:
1564+
if resp.code == REQUEST_TYPE_OK:
15651565
if state == JoinState.HANDSHAKE:
15661566
state = JoinState.INITIAL
15671567
elif state == JoinState.INITIAL:

tarantool/connection_pool.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,15 @@ def getnext(self, mode):
308308

309309
if mode == Mode.ANY:
310310
return self._getnext_by_mode(self.any_iter)
311-
elif mode == Mode.RW:
311+
if mode == Mode.RW:
312312
return self._getnext_by_mode(self.rw_iter,
313313
err_msg="Can't find healthy rw instance in pool")
314-
elif mode == Mode.RO:
314+
if mode == Mode.RO:
315315
return self._getnext_by_mode(self.ro_iter,
316316
err_msg="Can't find healthy ro instance in pool")
317-
elif mode == Mode.PREFER_RO:
317+
if mode == Mode.PREFER_RO:
318318
return self._getnext_by_mode(self.ro_iter, self.rw_iter)
319-
elif mode == Mode.PREFER_RW:
319+
if mode == Mode.PREFER_RW:
320320
return self._getnext_by_mode(self.rw_iter, self.ro_iter)
321321

322322
raise ValueError(f"Unexpected mode {mode}")

tarantool/error.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ def os_strerror_patched(code):
186186
message = os_strerror_orig(code)
187187
if not message.startswith("Unknown"):
188188
return message
189-
else:
190-
return _code2str.get(code, f"Unknown error {code}")
189+
190+
return _code2str.get(code, f"Unknown error {code}")
191191

192192
os.strerror = os_strerror_patched
193193
del os_strerror_patched

tarantool/mesh_connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def format_error(address, err):
159159

160160
# Looks okay.
161161
return result, None
162-
elif isinstance(result['port'], str):
162+
163+
if isinstance(result['port'], str):
163164
# Looks like a unix address.
164165

165166
# Expect no host.

tarantool/msgpack_ext/datetime.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ def decode(data, _):
169169
tz = tt_timezones.indexToTimezone[tzindex]
170170
return Datetime(timestamp=seconds, nsec=nsec, tz=tz,
171171
timestamp_since_utc_epoch=True)
172-
elif tzoffset != 0:
172+
if tzoffset != 0:
173173
return Datetime(timestamp=seconds, nsec=nsec, tzoffset=tzoffset,
174174
timestamp_since_utc_epoch=True)
175-
else:
176-
return Datetime(timestamp=seconds, nsec=nsec,
177-
timestamp_since_utc_epoch=True)
175+
176+
return Datetime(timestamp=seconds, nsec=nsec,
177+
timestamp_since_utc_epoch=True)

tarantool/msgpack_ext/types/datetime.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,10 @@ def __sub__(self, other):
480480
sec = self_dt.second - other_dt.second,
481481
nsec = self_nsec - other_nsec,
482482
)
483-
elif isinstance(other, Interval):
483+
if isinstance(other, Interval):
484484
return self._interval_operation(other, sign=-1)
485-
else:
486-
raise TypeError(f"unsupported operand type(s) for -: '{type(self)}' and '{type(other)}'")
485+
486+
raise TypeError(f"unsupported operand type(s) for -: '{type(self)}' and '{type(other)}'")
487487

488488
def __eq__(self, other):
489489
"""
@@ -498,10 +498,9 @@ def __eq__(self, other):
498498

499499
if isinstance(other, Datetime):
500500
return self._datetime == other._datetime
501-
elif isinstance(other, pandas.Timestamp):
501+
if isinstance(other, pandas.Timestamp):
502502
return self._datetime == other
503-
else:
504-
return False
503+
return False
505504

506505
def __str__(self):
507506
return self._datetime.__str__()

tarantool/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def wrap_key(*args, first=True, select=False):
4545
if len(args) == 1:
4646
if isinstance(args[0], (list, tuple)) and first:
4747
return wrap_key(*args[0], first=False, select=select)
48-
elif args[0] is None and select:
48+
if args[0] is None and select:
4949
return []
5050

5151
return list(args)

test/suites/lib/tarantool_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ def wait_until_started(self):
310310
if ans in ('running', 'hot_standby', 'orphan') or ans.startswith('replica'):
311311
temp.disconnect()
312312
return True
313-
elif ans in ('loading',):
313+
if ans in ('loading',):
314314
continue
315-
else:
316-
raise ValueError(f"Strange output for `box.info.status`: {ans}")
315+
316+
raise ValueError(f"Strange output for `box.info.status`: {ans}")
317317
except socket.error as exc:
318318
if exc.errno == errno.ECONNREFUSED:
319319
time.sleep(0.1)

0 commit comments

Comments
 (0)