is it possible to see if a class has a decorator ?

Stef Mientki stef.mientki at gmail.com
Mon Dec 6 06:29:32 EST 2010


On 06-12-2010 12:08, Ben Finney wrote:
> Stef Mientki <stef.mientki at gmail.com> writes:
>
>> I would like to know if a class definition has a decorator,
> I'm not sure what this question means.
>
> Applying a decorator to a class definition produces a normal class.
>
> Classes don't “have” decorators; classes can be returned by a decorator
> function, but AFAIK the resulting class doesn't “have” the decorator in
> any sense.
>
>> is that possible ?
> The return value of a decorator isn't special in any way, AFAIK.
>
> Any function can return a class object or a function object, and any
> function can be used as a decorator.
>
> The only thing that makes a function a decorator is how it is used in
> the code; but it doesn't leave a trace that I know of.
>
> Now, what is it you're trying to do? Perhaps there's a better solution
> we can come up with.
>
Thanks Ben,
here some more explanation.

I've a number of (dynamic) applications,
launched from a central wrapper.
All these modules have a class "Start", which launches the application and embeds them in the
wrapper application.

Module 1:
class Start ():
    ....

Module 2:
@auth
class Start ():
    ...

When the wrapper application is started, it looks for all dynamic modules (without importing them),
and list these application in a hierarchical tree.
In the above axmple,
I would like to know that the class "Start" in Module 2 has the decorator  "Auth", *without
importing the module*,
(so depending on the user logged in, I can decide to add or not add the module to the hierarchical
tree).

thanks,
Stef Mientki



 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101206/d231168e/attachment-0001.html>


More information about the Python-list mailing list