Code Monkey home page Code Monkey logo

Comments (2)

micheles avatar micheles commented on July 24, 2024

You should make your case better, I am not understanding what you are proposing. The decorator module has never been a collection of useful decorators, so it is really hard to have something added to it. Not to see that any extension is out of question, but you should convince me that this is general enough to be included.

from decorator.

pakal avatar pakal commented on July 24, 2024

Actually if I see well the "resolving_decorator" included in that package, it's because imho it's just a variant of the "decorator.decorator" utility.

Below is an excerpt from the decorator documentation.

>>> @decorator
... def trace(f, *args, **kw):
... kwstr = ', '.join('%r: %r' % (k, kw[k]) for k in sorted(kw))
... print("calling %s with args %s, {%s}" % (f.__name__, args, kwstr))
... return f(*args, **kw)

As you see, when the decorated function get called at runtime, all arguments are passed as standard "_args, *_kw" pair. So inside this "trace" decorator, it's complicated to extract, for example, an argument which would be an SQL session, because one doesn't know if it's in "args" (passed by position) or "kwargs" (passed by keyword).

The "resolving_decorator" would allow "trace" to receive a single "**all_kwargs" data set, with all arguments already bound to their final "local variable" name. Thus "trace" could simply do all_kwargs.get("sql_session"), and fiddle with this pre-resolved parameter. The only constraint would be, of course, that all decorated functions which want to have sql session handling, expose a "sql_session" argument in their signature.

from decorator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.