chore: add examples for functions and overloads
This commit is contained in:
28
examples/01_simple_type_checking/05_functions.py
Normal file
28
examples/01_simple_type_checking/05_functions.py
Normal file
@@ -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
|
||||
8
examples/01_simple_type_checking/06_overloads.midas
Normal file
8
examples/01_simple_type_checking/06_overloads.midas
Normal file
@@ -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
|
||||
}
|
||||
14
examples/01_simple_type_checking/06_overloads.py
Normal file
14
examples/01_simple_type_checking/06_overloads.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user