On Mon, Dec 21, 2020 at 1:09 PM Jonathan Fine <jfine2358@gmail.com> wrote:
Going back to that, I don't see why something like
    a = Timer(time_consuming_function)()
shouldn't actually provide the semantics wanted for
    @Timer
    a = time_consuming_function()

that was my first thought on this thread -- but it's not so simple. decorators work on functions (and classes) because they are special statements that both create an object and bind a name, so:

@a_decorator
def a_function():
    ...

is the same as:

def a_function():
    ...
a_function = a_decorator(a_function).

So we *could* have decoration syntax work for a certain subset of statements of the form:

@a_decorator
a_name = <something>

would mean:
a_name = <something>
a_name = a_decorator(a_name)

but that that would only  work for simple assignments and I don't think it would work for the case at hand, as <something> would get evaluated before the reassignment.

So I'm not sure what it *should* mean that would be useful.

-CHB



 


My preference is for code that's easier to read rather than quicker to type. It's said that easy reading is hard writing.

I'm also reminded of Einstein's (or is it?) Everything Should Be Made as Simple as Possible, But Not Simpler.

-- 
Jonathan


--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython