From 6f0e48eac4f20894c802c93ac75cfa4693fbaa36 Mon Sep 17 00:00:00 2001 From: rakiru Date: Thu, 11 Jan 2018 19:19:58 +0000 Subject: Replace None equality checks with identity checks Both work, but the identity check is the more correct/idiomatic approach (and also ever-so-slightly more efficient). --- asciifarm/client/display/fieldpad.py | 6 +++--- asciifarm/client/main.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'asciifarm/client') diff --git a/asciifarm/client/display/fieldpad.py b/asciifarm/client/display/fieldpad.py index 6619c1f..f64634e 100644 --- a/asciifarm/client/display/fieldpad.py +++ b/asciifarm/client/display/fieldpad.py @@ -29,14 +29,14 @@ class FieldPad: def changeCell(self, x, y, sprites): """ sprites must always have at least one element """ char, colour, bgcolour = sprites[0] - if bgcolour == None: + if bgcolour is None: for (ch, co, bg) in sprites: - if bg != None: + if bg is not None: bgcolour = bg break else: bgcolour = 0 - if colour != None and self.colours: + if colour is not None and self.colours: self.pad.addstr(y, x*self.charSize, char, self.colours.get(colour, bgcolour)) else: self.pad.addstr(y, x*self.charSize, char) diff --git a/asciifarm/client/main.py b/asciifarm/client/main.py index de77d09..48e89ad 100755 --- a/asciifarm/client/main.py +++ b/asciifarm/client/main.py @@ -57,7 +57,7 @@ def main(argv=None): keybindings = kf.read() address = args.address - if address == None: + if address is None: address = defaultAdresses[args.socket] if args.socket == "abstract": address = '\0' + address -- cgit From dccb4c8132800f9ee84cdfdaa602df76bfa65975 Mon Sep 17 00:00:00 2001 From: rakiru Date: Thu, 11 Jan 2018 20:25:39 +0000 Subject: Fix attempt to use non-existent name This theoretically also changes the meaning of the code from running the callback always, to only running the callback when there wasn't an error, which is what I'm assuming was meant, but in pratical terms, attempting to use `data` in the case of an error would have raised a `NameError` anyway. `else` on a try block will only run if nothing was raised. --- asciifarm/client/connection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'asciifarm/client') diff --git a/asciifarm/client/connection.py b/asciifarm/client/connection.py index 4eb0ffe..251d376 100644 --- a/asciifarm/client/connection.py +++ b/asciifarm/client/connection.py @@ -21,7 +21,8 @@ class Connection: data = receive(self.sock) except Exception as err: onError(err) - callback(data) + else: + callback(data) def send(self, message): send(self.sock, bytes(message, 'utf-8')) -- cgit From 7ba1804af2ec34094171127d6eada72a1d1e199f Mon Sep 17 00:00:00 2001 From: rakiru Date: Thu, 11 Jan 2018 20:28:03 +0000 Subject: Fix potential error if given invalid socket type --- asciifarm/client/connection.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'asciifarm/client') diff --git a/asciifarm/client/connection.py b/asciifarm/client/connection.py index 251d376..20f4964 100644 --- a/asciifarm/client/connection.py +++ b/asciifarm/client/connection.py @@ -10,6 +10,8 @@ class Connection: sockType = socket.AF_UNIX elif socketType == "inet": sockType = socket.AF_INET + else: + raise ValueError("Invalid socket type: %r" % (socketType,)) self.sock = socket.socket(sockType, socket.SOCK_STREAM) def connect(self, address): -- cgit