Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #10.2
- import typing
- import inspect
- from typing import get_origin
- def check_types(func):
- def wrapper(*args):
- expected = func.__annotations__
- signature = inspect.signature(func)
- actual = signature.bind(*args).arguments
- for i in actual:
- if get_origin(expected[i]) != True:
- expected_type = expected[i]
- if not type(actual[i]) == expected_type:
- raise NameError('That is Error')
- else:
- expected_type = get_origin(expected[i])
- return func(*args)
- return wrapper
- @check_types
- def func(a:5 ,b: int) -> str:
- return a*b
- func(6,5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement