[New-bugs-announce] [issue9157] Allow inspection of used decorators on a function

Mitar report at bugs.python.org
Mon Jul 5 03:28:15 CEST 2010


New submission from Mitar <mmitar at gmail.com>:

Sometimes it is useful to be able to check which decorators are already applied to a function, especially when you are constructing them dynamically. I am proposing that for all decorators in Python would be suggested that they maintain a list of used decorators on a function. It is most useful when all decorators do this.

It is the same reasoning why `inspect` module is in Python - to be able to inspect Python structures, to have this possibility. If you do not want it then you do can use Python structures as they were given to you. But you have an option to inspect them.

And I would like the same to see from decorators. It is not really so important that all decorators update this. If they would not then they would be hidden from inspection. But if developer wants to use inspection then he would choose such decorators which use this (or change them in this way). If all default Python's decorators would already be such it would be much easier to use them.

This could be implement by changing `wraps` function to pass over also the (for example) `__DECORATORS__` attribute of a function to a wrapped function and add this new decorator to a list, `__DECORATORS__`.

By default in a list ids of decorators would be maintained, but this could be overridden by `id` attribute of `wraps` function so that decorator can represent itself in some special way, for example as a tuple of its id and some significant parameters.

----------
messages: 109283
nosy: mitar
priority: normal
severity: normal
status: open
title: Allow inspection of used decorators on a function
type: feature request

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9157>
_______________________________________


More information about the New-bugs-announce mailing list