Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By applying a suspected decorator, catching exceptions, and then testing whether the result contains a <code>__call__</code> method, you could produce a guess as to whether a given callable is a decorator or not. But it will be only a guess, not a guarantee.</p> <p>Beyond that, I do not believe what you want will be possible in general, due to the dynamically typed nature of the Python language and to the special treatment of built-in functions in the CPython interpreter. It is not possible to programmatically tell whether a callable will accept another callable as an argument, or what type its return value will have. Also, in CPython, for functions implemented in C, you cannot even inspect a callable to see how many arguments it accepts.</p> <p>The word "decorator" can be taken to mean different things. One way to define it is, a decorator is any callable that accepts a single (callable) argument and returns a callable.</p> <p>Note that I have not even used the word "function" in this definition; it would actually be incorrect to do so. Indeed, some commonly used decorators have strange properties:</p> <ul> <li>The built-in <code>classmethod</code> and <code>staticmethod</code> decorators return descriptor objects, not functions.</li> <li>Since language version 2.6 you can decorate classes, not just functions and methods.</li> <li>Any class containing an <code>__init__(self, somecallable)</code> method and a <code>__call__(self, *args, **kwargs)</code> method can be used as a decorator.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload