From eb5e97acc73fa41210c2d63fcc14a6bbc0775256 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Fri, 7 Feb 2020 11:44:24 +0200 Subject: [PATCH] Refactoring / code cleanup. Use a frozenset()-like list. See: * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well. --- pysollib/game/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 4406b47d..db624bbb 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -471,6 +471,10 @@ class GameSaveInfo(NewStruct): stack_caps = attr.ib(factory=list) +_Game_LOAD_CLASSES = [GameGlobalSaveInfo, GameGlobalStatsStruct, GameMoves, + GameSaveInfo, GameStatsStruct, ] + + class Game(object): # for self.gstats.updated U_PLAY = _GLOBAL_U_PLAY @@ -3147,11 +3151,7 @@ class Game(object): if isinstance(t, type): if not isinstance(obj, t): # accept old storage format in case: - if (t == GameMoves - or t == GameGlobalStatsStruct - or t == GameStatsStruct - or t == GameSaveInfo - or t == GameGlobalSaveInfo): + if t in _Game_LOAD_CLASSES: assert isinstance(obj, Struct), err_txt else: assert False, err_txt