develop #3

Merged
itdominator merged 69 commits from develop into master 2026-03-23 04:51:23 +00:00
136 changed files with 5020 additions and 437 deletions
Showing only changes of commit a07123d165 - Show all commits

View File

@@ -1,4 +1,5 @@
# Python imports # Python imports
from typing import Type, TypeVar, Any
# Lib imports # Lib imports
@@ -11,10 +12,12 @@ class SingletonError(Exception):
T = TypeVar('T', bound='Singleton')
class Singleton: class Singleton:
_instance = None _instance = None
def __new__(cls, *args, **kwargs): def __new__(cls: Type[T], *args: Any, **kwargs: Any) -> T:
if cls._instance is not None: if cls._instance is not None:
logger.debug(f"'{cls.__name__}' is a Singleton. Returning instance...") logger.debug(f"'{cls.__name__}' is a Singleton. Returning instance...")
return cls._instance return cls._instance
@@ -22,7 +25,7 @@ class Singleton:
cls._instance = super(Singleton, cls).__new__(cls) cls._instance = super(Singleton, cls).__new__(cls)
return cls._instance return cls._instance
def __init__(self): def __init__(self) -> None:
if self._instance is not None: if self._instance is not None:
return return

View File

@@ -1,4 +1,5 @@
# Python imports # Python imports
from typing import Type, TypeVar, Any
# Lib imports # Lib imports
@@ -11,16 +12,18 @@ class SingletonError(Exception):
T = TypeVar('T', bound='SingletonRaised')
class SingletonRaised: class SingletonRaised:
_instance = None _instance = None
def __new__(cls, *args, **kwargs): def __new__(cls: Type[T], *args: Any, **kwargs: Any) -> T:
if cls._instance is not None: if cls._instance is not None:
raise SingletonError(f"'{cls.__name__}' is a Singleton. Cannot create a new instance...") raise SingletonError(f"'{cls.__name__}' is a Singleton. Cannot create a new instance...")
cls._instance = super(Singleton, cls).__new__(cls) cls._instance = super(SingletonRaised, cls).__new__(cls)
return cls._instance return cls._instance
def __init__(self): def __init__(self) -> None:
if cls._instance is not None: if self._instance is not None:
return return