From a7e0b692c0cef05ff9c8a10b94f307a0d280afe2 Mon Sep 17 00:00:00 2001 From: Chris Davoren Date: Wed, 15 Nov 2023 12:37:48 +1000 Subject: [PATCH] style: run through black formatter in neovim --- toyrobot/robot.py | 34 ++++++++++++---------------------- trexamples.py | 26 ++++++++++++++------------ 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/toyrobot/robot.py b/toyrobot/robot.py index be2d5cb..952f13d 100644 --- a/toyrobot/robot.py +++ b/toyrobot/robot.py @@ -32,17 +32,10 @@ class Robot: "SOUTH": 4, "SOUTHWEST": 5, "WEST": 6, - "NORTHWEST": 7 + "NORTHWEST": 7, } - VALID_COMMANDS = [ - "BLOCK", - "PLACE", - "MOVE", - "LEFT", - "RIGHT", - "REPORT" - ] + VALID_COMMANDS = ["BLOCK", "PLACE", "MOVE", "LEFT", "RIGHT", "REPORT"] # Private internals # Key corresponds to numerical direction defined in Robot.directions @@ -159,8 +152,7 @@ class Robot: self._position_x = new_position_x self._position_y = new_position_y - def place(self, position_x: int, position_y: int, - direction_name: str = None): + def place(self, position_x: int, position_y: int, direction_name: str = None): """ Places the Robot instance at the specified coordinates with the specified direction. @@ -262,7 +254,7 @@ class Robot: def interpret_command(self, command: str): """ - Interprets a given string command and applies the appropriate + Interprets a given string command and applies the appropriate transformation to this Robot instance. Fails silently if the command is unrecognized or invalid. @@ -274,11 +266,10 @@ class Robot: """ command = command.upper() - command_tokens = [x.strip() for x in command.split(' ') if len(x) > 0] + command_tokens = [x.strip() for x in command.split(" ") if len(x) > 0] # This is not strictly necessary as case - if len(command_tokens) == 0 or not command_tokens[0] in \ - Robot.VALID_COMMANDS: + if len(command_tokens) == 0 or not command_tokens[0] in Robot.VALID_COMMANDS: return match command_tokens[0]: @@ -289,7 +280,7 @@ class Robot: # print('Insufficient tokens...') return - parameter_tokens = [x.strip() for x in command_tokens[1].split(',')] + parameter_tokens = [x.strip() for x in command_tokens[1].split(",")] if len(parameter_tokens) < 2: # print('Insufficient parameters...') @@ -299,7 +290,7 @@ class Robot: # print("Adding block: {} {}".format(block_x, block_y)) self.add_block(block_x, block_y) - except ValueError as ve: + except ValueError: # print('Integer parsing error...') return case "PLACE": @@ -307,8 +298,7 @@ class Robot: # Must have parameters if len(command_tokens) < 2: return - parameter_tokens = [x.strip() for x in \ - command_tokens[1].split(',')] + parameter_tokens = [x.strip() for x in command_tokens[1].split(",")] # Must have at least X, Y if len(parameter_tokens) < 2: @@ -318,7 +308,7 @@ class Robot: place_x = int(parameter_tokens[0]) place_y = int(parameter_tokens[1]) - # Direction parameter is optional on second and subsequent + # Direction parameter is optional on second and subsequent # placements. The place() method accounts for an absent # direction on first call and fails silently. # print("PLACE command parsed: {}, {}".format(place_x, place_y)) @@ -327,7 +317,7 @@ class Robot: self.place(place_x, place_y, place_direction) else: self.place(place_x, place_y) - except ValueError as ve: + except ValueError: # Unable to convert x or y token to int return case "MOVE": @@ -355,5 +345,5 @@ class Robot: self._position_x, self._position_y, self.get_direction(), - ":".join([str(x) for x in self._blocks]) + ":".join([str(x) for x in self._blocks]), ) diff --git a/trexamples.py b/trexamples.py index b004bc1..bdf591d 100644 --- a/trexamples.py +++ b/trexamples.py @@ -12,28 +12,30 @@ def feed_file(filename: str, robot: toyrobot.Robot): def main(): - print('a)') - feed_file('example_a.txt', toyrobot.Robot()) + print("a)") + feed_file("example_a.txt", toyrobot.Robot()) print() - print('b)') - feed_file('example_b.txt', toyrobot.Robot()) + print("b)") + feed_file("example_b.txt", toyrobot.Robot()) print() - print('c)') - feed_file('example_c.txt', toyrobot.Robot()) + print("c)") + feed_file("example_c.txt", toyrobot.Robot()) print() - print('d)') - feed_file('example_d.txt', toyrobot.Robot()) + print("d)") + feed_file("example_d.txt", toyrobot.Robot()) print() - print('e)') - feed_file('example_e.txt', toyrobot.Robot()) + print("e)") + feed_file("example_e.txt", toyrobot.Robot()) print() - print('f)') - feed_file('example_f.txt', toyrobot.Robot()) + print("f)") + feed_file("example_f.txt", toyrobot.Robot()) print() + + if __name__ == "__main__": main()