From feb72b189a32e1989b5cc01340c85b12c2495a06 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 18 May 2022 11:34:43 +0000 Subject: [PATCH] Remove assert statement from non-test files Usage of assert statement in application logic is discouraged. assert is removed with compiling to optimised byte code (python -o producing *.pyo files). Consider raising an exception instead. Ideally, assert statement should be used only in tests. --- examples/color_patches/color_patches/server.py | 3 ++- .../conways_game_of_life/conways_game_of_life/portrayal.py | 3 ++- examples/hex_snowflake/hex_snowflake/portrayal.py | 3 ++- examples/pd_grid/pd_grid/portrayal.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/color_patches/color_patches/server.py b/examples/color_patches/color_patches/server.py index e0636c2492b..1ed8750a0d7 100644 --- a/examples/color_patches/color_patches/server.py +++ b/examples/color_patches/color_patches/server.py @@ -46,7 +46,8 @@ def color_patch_draw(cell): :return: the portrayal dictionary. """ - assert cell is not None + if cell is None: + raise AssertionError portrayal = {"Shape": "rect", "w": 1, "h": 1, "Filled": "true", "Layer": 0} portrayal["x"] = cell.get_row() portrayal["y"] = cell.get_col() diff --git a/examples/conways_game_of_life/conways_game_of_life/portrayal.py b/examples/conways_game_of_life/conways_game_of_life/portrayal.py index a2e88760730..4f68468d857 100644 --- a/examples/conways_game_of_life/conways_game_of_life/portrayal.py +++ b/examples/conways_game_of_life/conways_game_of_life/portrayal.py @@ -5,7 +5,8 @@ def portrayCell(cell): :param cell: the cell in the simulation :return: the portrayal dictionary. """ - assert cell is not None + if cell is None: + raise AssertionError return { "Shape": "rect", "w": 1, diff --git a/examples/hex_snowflake/hex_snowflake/portrayal.py b/examples/hex_snowflake/hex_snowflake/portrayal.py index 802de1cc641..a0a4020e896 100644 --- a/examples/hex_snowflake/hex_snowflake/portrayal.py +++ b/examples/hex_snowflake/hex_snowflake/portrayal.py @@ -5,7 +5,8 @@ def portrayCell(cell): :param cell: the cell in the simulation :return: the portrayal dictionary. """ - assert cell is not None + if cell is None: + raise AssertionError return { "Shape": "hex", "r": 1, diff --git a/examples/pd_grid/pd_grid/portrayal.py b/examples/pd_grid/pd_grid/portrayal.py index 490d94331d3..a7df44a439f 100644 --- a/examples/pd_grid/pd_grid/portrayal.py +++ b/examples/pd_grid/pd_grid/portrayal.py @@ -5,7 +5,8 @@ def portrayPDAgent(agent): :param agent: the agent in the simulation :return: the portrayal dictionary """ - assert agent is not None + if agent is None: + raise AssertionError return { "Shape": "rect", "w": 1,