Advertisement
gubichas

10.2

Dec 20th, 2022 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #10.2
  2. import typing
  3. import inspect
  4. from typing import get_origin
  5. def check_types(func):
  6.     def wrapper(*args):
  7.         expected = func.__annotations__
  8.         signature = inspect.signature(func)
  9.         actual = signature.bind(*args).arguments
  10.         for i in actual:
  11.             if get_origin(expected[i]) != True:
  12.                 expected_type = expected[i]
  13.                 if not type(actual[i]) == expected_type:
  14.                     raise NameError('That is Error')
  15.             else:
  16.                 expected_type = get_origin(expected[i])
  17.         return func(*args)
  18.     return wrapper
  19. @check_types
  20. def func(a:5 ,b: int) -> str:
  21.  
  22.     return a*b
  23.  
  24.  
  25. func(6,5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement