Веткакому надо сломать - сломает
8 сообщений · –R зачем падать. вот тебе good_singleton. class Singleton(type): """ Singleton implementation. Example of usage: >>> class MyClass(metaclass=Singleton): ... pass >>> instance1 = MyClass() >>> instance2 = MyClass() >>> instance1 is instance2 # True """ _instances: dict[type, Any] = {} def __call__(cls, *args: Any, **kwargs: Any) -> Any: if cls not in cls._instances: cls._instances[cls] = super().__call__(*args, **kwargs) return cls._instances[cls] R R class Singleton(type): _instances: dict[type, Any] = {} def __call__(cls, *args: Any, **kwargs: Any) -> Any: if cls not in cls._instances: cls._instances[cls] = super().__call__(*args, **kwargs) return cls._instances[cls] raise AssertionError(f"Cannot initialize more than one instance of class {cls.__name__}")
Ю R