mypy & typing singleton / factory classes
mypy & typing singleton / factory classes Question: I often use the following construct to generate singletons in my code: class Thing: pass class ThingSingletonFactory: _thing = None def __new__(cls) -> Thing: if cls._thing is None: cls._thing = Thing() return cls._thing def get_thing() -> Thing: return ThingSingletonFactory() thing = get_thing() same_thing = get_thing() assert thing …