Lets say decorator
has this definition:
def decorator(func: Callable[[], Any]) -> Callable[[], Any]:
def wrapper():
...
func()
...
#include "logger.hpp" | |
int bye() { | |
logger log("bye"); | |
log << "byeee"; | |
return 345; | |
} | |
int hihi() { | |
logger log("hi"); |
// Thanks craftablescience for some improvements! | |
#include <cstdio> | |
template<typename T = int> | |
class Range { | |
template<T start, T step> | |
class iterator { | |
T current = start; | |
public: |
#include <iostream> | |
#include <inttypes.h> | |
struct Test { | |
int x = 55; | |
virtual void test() { | |
printf("hello %d\n", this->x); | |
} | |
}; |
from typing import Callable, Generic, TypeVar | |
T = TypeVar("T") | |
class EventHandler(Generic[T]): | |
callbacks: list [Callable[[T], None]] = [] | |
def __iadd__(self, callback: Callable[[T], None]): | |
self.callbacks.append(callback) | |
return self |
class BritishNaming(type): | |
def __new__(mcs, *args): | |
cls = super().__new__(mcs, *args) | |
cls.__init__ = cls.__innit__ | |
return cls | |
class MyBritishClass(metaclass=BritishNaming): | |
def __innit__(self): | |
print("I am british now ig") |
# utils.py | |
from sys import argv | |
from typing import Any, Callable | |
def entry_point( | |
func: Callable[[list[str]], Any] | Callable[[], Any] | |
) -> Callable[[], Any]: | |
new_func = lambda: func(argv) if func.__code__.co_argcount == 1 else func() # type: ignore | |
if func.__module__ == "__main__": | |
new_func() |