This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Singleton allocator | |
class Database: | |
def __init__(self): | |
pass | |
_instance = None | |
def __new__(cls, *args, **kwargs): | |
if cls._instance is not None: | |
cls._instance = super().__new__(cls, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import time | |
from typing import Callable, Any | |
def async_timed(): | |
def wrapper(func: Callable) -> Callable: | |
@functools.wraps(func) | |
async def wrapped(*args, **kwargs) -> Any: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from typing import Any | |
@dataclass | |
class SafeInt: | |
value: Any | |
def __post_init__(self) -> None: | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example of a Database class with Singleton pattern implementation and CRUD methods | |
import sqlite3 | |
from dataclasses import dataclass | |
from typing import ClassVar, Self | |
class DatabaseError(Exception): | |
pass |