pythonadvanced
Abc Abstract
Advanced Python pattern: abc-abstract
pythonPress ⌘/Ctrl + Shift + C to copy
from abc import ABC, abstractmethod
class Storage(ABC):
@abstractmethod
def save(self, key: str, value: str) -> None: ...
class DictStorage(Storage):
def __init__(self):
self._db: dict[str, str] = {}
def save(self, key: str, value: str) -> None:
self._db[key] = value
s = DictStorage()
s.save('user:1', 'alice')
print('saved')Use Cases
- advanced programming
- patterns
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
pythonadvanced
Abc Registry
Advanced Python pattern: abc-registry
Best for: advanced programming
#python#advanced
pythonintermediate
Abstract Base Classes with abc
Define interfaces and enforce method implementation with Python's abc module.
Best for: Interface contracts
#python#abc
pythonbeginner
Type Hints
Advanced Python pattern: type-hints
Best for: advanced programming
#python#advanced
pythonintermediate
Dataclass
Advanced Python pattern: dataclass
Best for: advanced programming
#python#advanced