fix singleton typeing and __init__

This commit is contained in:
2026-01-12 23:34:34 -06:00
parent 00c72a7117
commit a07123d165
2 changed files with 12 additions and 6 deletions

View File

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