From b4e02f62c4adee87cbe22e82e4a78fccc13bd99a Mon Sep 17 00:00:00 2001 From: rht Date: Mon, 17 Jan 2022 08:13:35 -0500 Subject: [PATCH] refactor: Use slots for creator.create --- deap/creator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deap/creator.py b/deap/creator.py index 9b0f61aab..0cb0acbc5 100644 --- a/deap/creator.py +++ b/deap/creator.py @@ -164,8 +164,11 @@ def initType(self, *args, **kargs): for obj_name, obj in dict_inst.iteritems(): setattr(self, obj_name, obj()) if base.__init__ is not object.__init__: + for k, v in dict_cls.iteritems(): + setattr(self, k, v) base.__init__(self, *args, **kargs) - objtype = type(str(name), (base,), dict_cls) + slots = list(kargs.keys()) + objtype = type(str(name), (base,), {'__slots__': slots}) objtype.__init__ = initType globals()[name] = objtype