Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49913 > unrolled thread
| Started by | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| First post | 2013-07-05 02:14 +0100 |
| Last post | 2013-07-05 02:14 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Decorator help Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-05 02:14 +0100
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| Date | 2013-07-05 02:14 +0100 |
| Subject | Re: Decorator help |
| Message-ID | <mailman.4259.1372986890.3114.python-list@python.org> |
On 4 July 2013 06:39, Peter Otten <__peter__@web.de> wrote:
> Joshua Landau wrote:
>
>> On 3 July 2013 23:19, Joshua Landau <joshua.landau.ws@gmail.com> wrote:
>>> If you don't want to do that, you'd need to use introspection of a
>>> remarkably hacky sort. If you want that, well, it'll take a mo.
>>
>> After some effort I'm pretty confident that the hacky way is impossible.
>
> Well, technically it's
>
> func.func_closure[0].cell_contents.__name__
>
> but of course you cannot know that for the general case.
I didn't want to do something like that as it implies a lot of
knowledge about the function -- which implies that there's no reason
to do it hacky in the first place. I was using
"inspect.getclosurevars(func).nonlocals" and that "coerces" to a
dictionary first. It's the "correct" way of doing things. But you
never know what name the function inside the wrapper is bound to, so I
didn't accept that.
Also, your method has undefined behaviour AFAIK -- the order of
func_closure is compiler-dependant. If you want to do something like
this, I recommend my method (but it doesn't work for the general case
in the slightest):
inspect.getclosurevars(func).nonlocals["func"].__name__
If you can't assume the name it's stored in, but you can know the
order of closure variables *then* use Peter's. But again, don't use
either; it's impossible just as I said.
Back to top | Article view | comp.lang.python
csiph-web