|
@@ -118,13 +118,49 @@ def add(a: int, b: int):
|
|
|
return a + b
|
|
|
|
|
|
|
|
|
+def monkey_patching(arg='Monkey', kwarg='patching'):
|
|
|
+ def decorator(func):
|
|
|
+ @wraps(func)
|
|
|
+ def wrapper(*_args, **_kwargs):
|
|
|
+ patched_args = (arg, )*len(_args)
|
|
|
+ patched_kwargs = {key:kwarg for key, _ in _kwargs.items()}
|
|
|
+ return func(*patched_args, **patched_kwargs)
|
|
|
+ return wrapper
|
|
|
+ return decorator
|
|
|
+
|
|
|
+
|
|
|
+@monkey_patching(kwarg='Duper')
|
|
|
+def print_args_kwargs(*args, **kwargs):
|
|
|
+ for i, value in enumerate(args):
|
|
|
+ print(i, value)
|
|
|
+ for k, v in sorted(kwargs.items()):
|
|
|
+ print(f'{k} = {v}')
|
|
|
+
|
|
|
+
|
|
|
+def pass_arguments(*args_, **kwargs_):
|
|
|
+ def decorator(func):
|
|
|
+ @wraps(func)
|
|
|
+ def wrapper(*args, **kwargs):
|
|
|
+ print(args_, kwargs_)
|
|
|
+ return func(*args, **kwargs)
|
|
|
+ return wrapper
|
|
|
+ return decorator
|
|
|
+
|
|
|
+
|
|
|
+@pass_arguments(s='Когда', w='-', r='нибудь!')
|
|
|
+def concatenate(**kwargs):
|
|
|
+ result = ""
|
|
|
+ for arg in kwargs.values():
|
|
|
+ result += str(arg)
|
|
|
+ return result
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def main():
|
|
|
|
|
|
- print(add(4, 5))
|
|
|
- print(add(5, 8))
|
|
|
- print(add(9, 43))
|
|
|
- print(add(10, 33))
|
|
|
- print(add.__name__)
|
|
|
+ print(concatenate(a="Я", b="Выучу", c="Этот", d="Питон", e="!"))
|
|
|
+
|
|
|
+ # print_args_kwargs(1, 2, 3, 4, b=300, w=40, t=50, a=100)
|
|
|
|
|
|
'''
|
|
|
print(get_product(23, 5)) # Вычисляем в первый раз
|