Built-in function `len` used as condition
Using the `len` function to check if a sequence is empty is not idiomatic
and can be less performant than checking the truthiness of the object.
`len` doesn't know the context in which it is called, so if computing the
length means traversing the entire sequence, it must; it doesn't know
that the result is just being compared to 0. Computing the boolean value
can stop after it sees the first element, regardless of how long the
sequence actually is.
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
for line in self.r.readlines():
line = line.strip().decode()
# Note that msg is too long and gets wrapped, handle it special
- if last_key == 'msg' and len(line):
+ if last_key == 'msg' and line:
response['msg'] += line
else:
key = ''
def process_cmd(self):
buf = self.sock.recv(1024).decode('ascii')
- if not len(buf):
+ if not buf:
sys.exit(0)
cmd, buf = buf.split('\n', 1)
cmd = cmd.strip()
args = dict()
for n in buf.split('\n'):
n = n.strip()
- if len(n):
+ if n:
key, val = n.strip().split('=', 1)
args[key] = val
if cmd == 'start':