A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-August/047097.html below:

[Python-Dev] PEP 318 - writing to func_name attribute

[Python-Dev] PEP 318 - writing to func_name attribute [Python-Dev] PEP 318 - writing to func_name attributeSkip Montanaro skip at pobox.com
Fri Aug 6 15:18:33 CEST 2004
One thing I added awhile back to PEP 318 as an open issue is that for ease
of writing wrappers the func_name attribute of a function object should be
writable.  For example, in situations where the decorator returns a new
function object (often, I would think) it would really be nice if that new
function object had the same name as the undecorated function.  Consider:

    def a(func):
        def _inner(*args, **kwds):
            return func(*args, **kwds)
        return _inner

    @a
    def func(*args, **kwds):
        print args
        print kwds

    print "func's name:", func.func_name

I realize you can use new.function() to create a new function object, but
that seems like a fair amount of extra complexity just to change the
function's name.  I'd prefer it if the decorator could be written as:

    def a(func):
        def _inner(*args, **kwds):
            return func(*args, **kwds)
        _inner.func_name = func.func_name
        return _inner

That fails because func_name is readonly.  Any chance this restriction can
be loosened up?

Skip
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4