From 757054d7afd64e85b9d9488e76dbe6a2775db701 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sun, 14 Jun 2026 15:50:20 +0200 Subject: [PATCH] chore: add examples for functions and overloads --- .../01_simple_type_checking/05_functions.py | 28 +++++++++++++++++++ .../06_overloads.midas | 8 ++++++ .../01_simple_type_checking/06_overloads.py | 14 ++++++++++ 3 files changed, 50 insertions(+) create mode 100644 examples/01_simple_type_checking/05_functions.py create mode 100644 examples/01_simple_type_checking/06_overloads.midas create mode 100644 examples/01_simple_type_checking/06_overloads.py diff --git a/examples/01_simple_type_checking/05_functions.py b/examples/01_simple_type_checking/05_functions.py new file mode 100644 index 0000000..9c04813 --- /dev/null +++ b/examples/01_simple_type_checking/05_functions.py @@ -0,0 +1,28 @@ +def incr(value: int): + return value + 1 + + +def decr(value: int): + return value - 1 + + +def foo(a: int, /, b: float, *, c: str): + return True + + +r1 = foo() # foo() missing 2 required positional arguments: 'a' and 'b' +r2 = foo(1) # foo() missing 1 required positional argument: 'b' +r3 = foo(1, 2.0) # foo() missing 1 required keyword-only argument: 'c' +r4 = foo(1, b=2.0) # foo() missing 1 required keyword-only argument: 'c' +r5 = foo(1, 2.0, "test") # foo() takes 2 positional arguments but 3 were given +r6 = foo(1, 2.0, b=3.0) # foo() got multiple values for argument 'b' +r7 = foo( + a=1 +) # foo() got some positional-only arguments passed as keyword arguments: 'a' +r8 = foo(g="test") # foo() got an unexpected keyword argument 'g' + +r9a = foo(1, 2.0, c="test") +r9b = foo(1, b=2.0, c="test") +r9c = foo(1, c="test", b=2.0) + +r10 = foo("a", 3, c=False) # wrong argument types diff --git a/examples/01_simple_type_checking/06_overloads.midas b/examples/01_simple_type_checking/06_overloads.midas new file mode 100644 index 0000000..47c80e0 --- /dev/null +++ b/examples/01_simple_type_checking/06_overloads.midas @@ -0,0 +1,8 @@ +type T1 = object +type T2 = object +type Foo = object + +extend Foo { + def bar: fn(T1, /) -> int + def bar: fn(T2, /) -> float +} diff --git a/examples/01_simple_type_checking/06_overloads.py b/examples/01_simple_type_checking/06_overloads.py new file mode 100644 index 0000000..105d5ce --- /dev/null +++ b/examples/01_simple_type_checking/06_overloads.py @@ -0,0 +1,14 @@ +# type: ignore +# ruff: disable [F821] + +foo: Foo +t1: T1 +t2: T2 + +a = foo.bar(t1) +b = foo.bar(t2) + +func = foo.bar + +c = func(t1) +d = func(t2)