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 typing import TypeVar, Union, Callable, Optional | |
_ClsT = TypeVar('_ClsT', bound=type) | |
def add_method(func: Union[Callable, classmethod, staticmethod], | |
name: Optional[str] = None) -> Callable[[_ClsT], _ClsT]: | |
"""Class decorator that adds the given function as a method to the class""" |
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 logging | |
from collections import defaultdict | |
class TopicManager: | |
def __init__(self): | |
self.subscribers = defaultdict(set) | |
def subscribe(self, topic, callback): | |
"""Subscribes a callback function to a topic""" |
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 functools import wraps, partial | |
from inspect import signature | |
def curryable(func): | |
@wraps(func) | |
def curryable_func(*args, **kwargs): | |
try: | |
signature(func).bind(*args, **kwargs) | |
except TypeError: |