This file contains hidden or 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
class TC: | |
def __init__(self, *types): | |
self.types = types | |
def __call__(self, func): | |
def f(*args): | |
match [*args]: | |
case self.types: return func(*args) | |
case _: raise TypeError("type mismatch") | |
return f |
This file contains hidden or 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
""" | |
$ python3 fxn_logger.py | |
foo(4)...16 | |
foo(3, blah=None)...foo() got an unexpected keyword argument 'blah' | |
foo()...foo() missing 1 required positional argument: 'x' | |
Traceback (most recent call last): | |
File "fxn_logger.py", line 33, in <module> | |
foo() | |
File "fxn_logger.py", line 19, in __call__ | |
raise e |
This file contains hidden or 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
#!/usr/bin/env python3 | |
from random import random, randint | |
import operator | |
class Expr: | |
__slots__ = ["op", "x1", "x2"] | |
def __init__(self, x1, op=None, x2=None): |