chore: add examples for functions and overloads

This commit is contained in:
2026-06-14 15:50:20 +02:00
parent 25a96d20e1
commit 757054d7af
3 changed files with 50 additions and 0 deletions

View 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

View 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
}

View 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)