From 97aedc0895135f50ea3d72b1c82f130216675bac Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Sat, 18 Sep 2021 18:24:54 -0500 Subject: [PATCH] Add __slots__ to data enumerations These types still have a __dict__, since they inherit from Enum, but using __slots__ for the inherited properties can still improve access times. --- bonemarketsolver/data/adjustments.py | 2 ++ bonemarketsolver/data/appendages.py | 2 ++ bonemarketsolver/data/buyers.py | 2 ++ bonemarketsolver/data/costs.py | 2 ++ bonemarketsolver/data/declarations.py | 2 ++ bonemarketsolver/data/diplomat_fascinations.py | 1 + bonemarketsolver/data/embellishments.py | 2 ++ bonemarketsolver/data/fluctuations.py | 2 ++ bonemarketsolver/data/occasional_buyers.py | 2 ++ bonemarketsolver/data/skulls.py | 2 ++ bonemarketsolver/data/torsos.py | 2 ++ 11 files changed, 21 insertions(+) diff --git a/bonemarketsolver/data/adjustments.py b/bonemarketsolver/data/adjustments.py index 6d59d01..9dd2814 100644 --- a/bonemarketsolver/data/adjustments.py +++ b/bonemarketsolver/data/adjustments.py @@ -9,6 +9,8 @@ from ..objects.action import Action class Adjustment(Enum): """An action that is taken after all parts have been added to a skeleton.""" + __slots__ = '_value_', '_name_', '__objclass__' + CARVE_AWAY_AGE = Action( "Carve away some evidence of age", cost = Cost.ACTION.value, diff --git a/bonemarketsolver/data/appendages.py b/bonemarketsolver/data/appendages.py index 2820411..53c896c 100644 --- a/bonemarketsolver/data/appendages.py +++ b/bonemarketsolver/data/appendages.py @@ -9,6 +9,8 @@ from ..objects.action import Action class Appendage(Enum): """An action that is taken once all skulls are added to a skeleton.""" + __slots__ = '_value_', '_name_', '__objclass__' + # Cost from this scales with limbs and is partially implemented separately ADD_JOINTS = Action( "Add four more joints to your skeleton", diff --git a/bonemarketsolver/data/buyers.py b/bonemarketsolver/data/buyers.py index b202485..5ea79e8 100644 --- a/bonemarketsolver/data/buyers.py +++ b/bonemarketsolver/data/buyers.py @@ -9,6 +9,8 @@ from ..objects.action import Action class Buyer(Enum): """An action that converts a skeleton into revenue.""" + __slots__ = '_value_', '_name_', '__objclass__' + A_PALAEONTOLOGIST_WITH_HOARDING_PROPENSITIES = Action( "Sell a complete skeleton to the Bone Hoarder", cost = Cost.ACTION.value diff --git a/bonemarketsolver/data/costs.py b/bonemarketsolver/data/costs.py index 043dc1f..a4f3c4c 100644 --- a/bonemarketsolver/data/costs.py +++ b/bonemarketsolver/data/costs.py @@ -8,6 +8,8 @@ from ortools.sat.python import cp_model class Cost(Enum): """The number of pennies needed to produce a quality.""" + __slots__ = '_value_', '_name_', '__objclass__' + # This is your baseline EPA: the pennies you could generate using an action for a generic grind. ACTION = 400 diff --git a/bonemarketsolver/data/declarations.py b/bonemarketsolver/data/declarations.py index 2fc286a..ca64642 100644 --- a/bonemarketsolver/data/declarations.py +++ b/bonemarketsolver/data/declarations.py @@ -9,6 +9,8 @@ from ..objects.action import Action class Declaration(Enum): """An action that is taken after all adjustments have been made to a skeleton.""" + __slots__ = '_value_', '_name_', '__objclass__' + AMPHIBIAN = Action( "Declare your (Skeleton Type) a completed Amphibian", cost = Cost.ACTION.value diff --git a/bonemarketsolver/data/diplomat_fascinations.py b/bonemarketsolver/data/diplomat_fascinations.py index 8738230..5275efe 100644 --- a/bonemarketsolver/data/diplomat_fascinations.py +++ b/bonemarketsolver/data/diplomat_fascinations.py @@ -12,3 +12,4 @@ DiplomatFascination = Enum( module = __name__ ) DiplomatFascination.__doc__ = "The current fascination of the Trifling Diplomat." +DiplomatFascination.__slots__ = '_value_', '_name_', '__objclass__' diff --git a/bonemarketsolver/data/embellishments.py b/bonemarketsolver/data/embellishments.py index 138e073..3519ff9 100644 --- a/bonemarketsolver/data/embellishments.py +++ b/bonemarketsolver/data/embellishments.py @@ -9,6 +9,8 @@ from ..objects.action import Action class Embellishment(Enum): """An action is taken after a declaration has been made for a skeleton.""" + __slots__ = '_value_', '_name_', '__objclass__' + MORE_PLAUSIBLE = Action( "Make it seem just a bit more plausible", cost = Cost.ACTION.value + Cost.REVISIONIST_NARRATIVE.value, diff --git a/bonemarketsolver/data/fluctuations.py b/bonemarketsolver/data/fluctuations.py index 14392f0..615dacd 100644 --- a/bonemarketsolver/data/fluctuations.py +++ b/bonemarketsolver/data/fluctuations.py @@ -6,6 +6,8 @@ from enum import Enum class Fluctuation(Enum): """Which skeleton attribute is currently boosted.""" + __slots__ = '_value_', '_name_', '__objclass__' + ANTIQUITY = 1 AMALGAMY = 2 MENACE = 3 diff --git a/bonemarketsolver/data/occasional_buyers.py b/bonemarketsolver/data/occasional_buyers.py index 7bbb008..ad14430 100644 --- a/bonemarketsolver/data/occasional_buyers.py +++ b/bonemarketsolver/data/occasional_buyers.py @@ -8,6 +8,8 @@ from .buyers import Buyer class OccasionalBuyer(Enum): """Which of several unusual buyers are available.""" + __slots__ = '_value_', '_name_', '__objclass__' + AN_ENTHUSIAST_IN_SKULLS = [Buyer.AN_ENTHUSIAST_IN_SKULLS] A_DREARY_MIDNIGHTER = [Buyer.A_DREARY_MIDNIGHTER] diff --git a/bonemarketsolver/data/skulls.py b/bonemarketsolver/data/skulls.py index d37285f..e141d19 100644 --- a/bonemarketsolver/data/skulls.py +++ b/bonemarketsolver/data/skulls.py @@ -9,6 +9,8 @@ from ..objects.action import Action class Skull(Enum): """An action that is taken immediately after starting a skeleton.""" + __slots__ = '_value_', '_name_', '__objclass__' + BAPTIST_SKULL = Action( "Duplicate the skull of John the Baptist, if you can call that a skull", cost = Cost.ACTION.value + 500*Cost.BONE_FRAGMENT.value + 10*Cost.PEPPERCAPS.value, diff --git a/bonemarketsolver/data/torsos.py b/bonemarketsolver/data/torsos.py index 29fccb9..2beec0f 100644 --- a/bonemarketsolver/data/torsos.py +++ b/bonemarketsolver/data/torsos.py @@ -9,6 +9,8 @@ from ..objects.action import Action class Torso(Enum): """An action that initiates a skeleton.""" + __slots__ = '_value_', '_name_', '__objclass__' + HEADLESS_HUMANOID = Action( "Reassemble your Headless Humanoid", cost = Cost.ACTION.value + Cost.HEADLESS_SKELETON.value,