Код: Выделить всё
import functools
def myWrapper(func): # type: ignore
@functools.wraps(func)
def f(*args, **kwargs): # type: ignore
return func(*args, **kwargs)
return f
@myWrapper
def hello(text: str, n: int = 1) -> str:
return "hello world"
def helloNoWrap(text: str, n: int = 1) -> str:
return "hello world"
print(hello.__annotations__)
print(helloNoWrap.__annotations__)
hello("hello", 5, 4)
helloNoWrap("hello", 5, 4)
Код: Выделить всё
{'text': , 'n': , 'return': }
{'text': , 'n': , 'return': }
Traceback (most recent call last):
File "/Users/davidpitchford/repos/crawler/test_typing.py", line 19, in
hello("hello", 5, 4)
File "/Users/davidpitchford/repos/crawler/test_typing.py", line 6, in f
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: hello() takes from 1 to 2 positional arguments but 3 were given
Код: Выделить всё
test_typing.py:20: error: Too many arguments for "helloNoWrap" [call-arg]
Found 1 error in 1 file (checked 1 source file)
Подробнее здесь: https://stackoverflow.com/questions/793 ... t-properly
Мобильная версия