Code Monkey home page Code Monkey logo

Comments (8)

micheles avatar micheles commented on August 28, 2024 1

The documentation is correct, it is saying that you cannot decorate a staticmethod, meaning that dec(staticmethod(func_or_coro)) is not working. It is implicit that
staticmethod(dec(func_or_coro)) works since there is nothing strange there.

from decorator.

micheles avatar micheles commented on August 28, 2024

The trick with staticmethod/classmethod is that the decorator module works only if you use the right order, which is the one you are using. The opposite order will not work:

    @log_start_stop
    @staticmethod
    async def make_task(n):

For me this is a non-problem, of course the right order if the first one, because the decorator has to be applied to the function not to the staticmethod. With wrapt it would work in both orders.

from decorator.

yjqiang avatar yjqiang commented on August 28, 2024

The trick with staticmethod/classmethod is that the decorator module works only if you use the right order, which is the one you are using. The opposite order will not work:

    @log_start_stop
    @staticmethod
    async def make_task(n):

For me this is a non-problem, of course the right order if the first one, because the decorator has to be applied to the function not to the staticmethod. With wrapt it would work in both orders.

But it doesn't support coroutine.😢

from decorator.

micheles avatar micheles commented on August 28, 2024

I am right in understanding that you are happy with the current behavior and I can close issue?
If you have a problem please be more explicit.

from decorator.

yjqiang avatar yjqiang commented on August 28, 2024

I am right in understanding that you are happy with the current behavior and I can close issue?
If you have a problem please be more explicit.

Yeah, you can close this. But would you like to add something about this to documentation?

from decorator.

micheles avatar micheles commented on August 28, 2024

I will change it is cleaner and safer to decorate only functions -> it is cleaner and safer to decorate only functions and coroutines.

from decorator.

yjqiang avatar yjqiang commented on August 28, 2024

And how about change If you want to decorate things like classmethods/staticmethods and general callables - which I will never support in the decorator module - I suggest you to look at the wrapt project by Graeme Dumpleton. to If you want to decorate things like classmethods/staticmethods and general callables - which I will never support in the decorator module - I suggest you to look at the wrapt project by Graeme Dumpleton. But you can use the decorator module on these things carefully right now and it should work.?

from decorator.

yjqiang avatar yjqiang commented on August 28, 2024

The documentation is correct, it is saying that you cannot decorate a staticmethod, meaning that dec(staticmethod(func_or_coro)) is not working. It is implicit that
staticmethod(dec(func_or_coro)) works since there is nothing strange there.

Got it. Sorry for my poor English, I misunderstood the documentation.

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.