Parametrized decorator and vscode intellisense /u/pylessard Python Education

I want to make a parametrized decorator that enable type hints to work. I got the solution above that makes mypy happy, but VsCode is unable to show the function signature. Is that a VsCode limitation or is there a better way to handle type hints here?

from typing import TypeVar, Callable, Any T = TypeVar('T') def my_decorator(name:str) -> Callable[[Callable[..., T]], Callable[..., T]]: def _decorator(function:Callable[..., T]) -> Callable[..., T]: def _wrapper(*args:Any, **kwargs:Any) -> T: print(f"Before {name}") result = function(*args, **kwargs) print(f"After {name}") return result return _wrapper return _decorator @my_decorator("hello") def my_func(a:int) -> int: return a + 1 

This is what vscode shows when I hover “my_func“ from a different module

(function) def my_func(...) -> int

Would like to replace the ellipsis with the proper types.

submitted by /u/pylessard
[link] [comments]

​r/learnpython I want to make a parametrized decorator that enable type hints to work. I got the solution above that makes mypy happy, but VsCode is unable to show the function signature. Is that a VsCode limitation or is there a better way to handle type hints here? from typing import TypeVar, Callable, Any T = TypeVar(‘T’) def my_decorator(name:str) -> Callable[[Callable[…, T]], Callable[…, T]]: def _decorator(function:Callable[…, T]) -> Callable[…, T]: def _wrapper(*args:Any, **kwargs:Any) -> T: print(f”Before {name}”) result = function(*args, **kwargs) print(f”After {name}”) return result return _wrapper return _decorator @my_decorator(“hello”) def my_func(a:int) -> int: return a + 1 This is what vscode shows when I hover “my_func“ from a different module (function) def my_func(…) -> int Would like to replace the ellipsis with the proper types. submitted by /u/pylessard [link] [comments] 

I want to make a parametrized decorator that enable type hints to work. I got the solution above that makes mypy happy, but VsCode is unable to show the function signature. Is that a VsCode limitation or is there a better way to handle type hints here?

from typing import TypeVar, Callable, Any T = TypeVar('T') def my_decorator(name:str) -> Callable[[Callable[..., T]], Callable[..., T]]: def _decorator(function:Callable[..., T]) -> Callable[..., T]: def _wrapper(*args:Any, **kwargs:Any) -> T: print(f"Before {name}") result = function(*args, **kwargs) print(f"After {name}") return result return _wrapper return _decorator @my_decorator("hello") def my_func(a:int) -> int: return a + 1 

This is what vscode shows when I hover “my_func“ from a different module

(function) def my_func(...) -> int

Would like to replace the ellipsis with the proper types.

submitted by /u/pylessard
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *