Skip to content
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

Decorator! #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Decorator! #73

wants to merge 2 commits into from

Conversation

alexmojaki
Copy link
Collaborator

Closes #32

Example:

from icecream import ic

@ic
def foo(x, y):
    return x + y

a = 1
b = 2
foo(a, b)
ic| called foo(1, 2)
ic| foo returned 3

What should the output look like? ycecream does this on return:

y| returned 3 from foo(1, 2) in 0.000043 seconds

Do we want to show arguments again or timing? I'm hesitant, but it'd be easy to implement and we can change it later either way.

We still need an explicit API in case people want to decorate functions dynamically, e.g. foo = ic.decorate(foo) instead of @ic. Is ic.decorate() fine? My thinking is that it expresses "I am doing the equivalent of @ic", which is equally non-descriptive, so I don't know if it makes sense to have a descriptive name like ic.log_calls or a pun like ic.sandwich.

Still required after resolving questions:

  1. Allowing arguments, e.g. @ic().
  2. Tests.
  3. Releasing the required functionality in Decorators alexmojaki/executing#20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow ic to be used as a decorator
1 participant