factory-pattern

How to register classes that inherit from an abstract class in python

How to register classes that inherit from an abstract class in python Question: I’m creating a module with a function that works as a factory of the implemented classes. It works registering the classes with the help of a metaclass (a pattern I have just copied from here). _registry = {} def register_class(cls): _registry[cls.__name__] = …

Total answers: 1

correctly override __new__ in python3

correctly override __new__ in python3 Question: So I am trying to override __new__ and let it exist as a factory to create derived instances. After reading a bit on SO, I am under the impression that I should be calling __new__ on the derived instance as well. BaseThing class BaseThing: def __init(self, name, **kwargs): self.name …

Total answers: 1