-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ic does not show funtion name, *args or **kwargs inside a wrapper #153
Comments
I guess this is actually a consequence of it showing the local variable names. They just happen to be not very helpful here. You get the same when doing: from icecream import ic
def f(*args, **kwargs):
return args, kwargs
args = 1, 2
kwargs = {"a": 3}
ic(f(*args, **kwargs))
# ic| f(*args, **kwargs): ((1, 2), {'a': 3}) Not sure how one could distinguish this case from the wrapped function case. |
I think Microsoft stumbled on a similar issue with Pylance, and they solved it like this (not sure if applicable to ic): microsoft/pylance-release#4140 |
I just checked, adding type hints (as alluded to in that first pylance link, to leverage the better type hints introduced by from icecream import ic
from typing import Callable, TypeVar, ParamSpec
R = TypeVar("R")
P = ParamSpec("P")
def get_name(func: Callable[P, R]) -> Callable[P, R]:
@wraps(func)
def wrapper(self: object, *args: P.args, **kwargs: P.kwargs) -> R:
func_output = ic(func(self, *args, **kwargs))
return func_output
return wrapper
class A:
def a(self, x: str) -> str:
return x
a = A()
get_name(a.a)("foo")
# ic| func(self, *args, **kwargs): 'foo' Not unsurprising, since I guess |
returns 'ic| func(self, *args, **kwargs): None'
instead of the actual functio name, args, and kwargs
The text was updated successfully, but these errors were encountered: