Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created April 18, 2024 07:36
Show Gist options
  • Save mypy-play/5e61f50c5c61bf4c90b5e1403f2b6be1 to your computer and use it in GitHub Desktop.
Save mypy-play/5e61f50c5c61bf4c90b5e1403f2b6be1 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
# Run the type checking with "mypy --strict foo.py"
class Add(tuple[int,int]):
pass
class Const(int):
pass
Expr = Add | Const
def my_eval(e : Expr) -> int:
match e:
case Add((a,b)):
return a + b
case Const(x):
return x
print(my_eval(Const(42)))
print(my_eval(Add((42,45))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment