[Python-ideas] add variable "__this_func__" inside all functions' locals

语言破碎处 mlet_it_bew at 126.com
Tue Feb 28 19:12:28 EST 2017


How a function refer itself?
    def f():
        f() # fine... really???

consider these situations:
1) decorator
    @xxx
    def f():... # how can I access the wrapped version?

2) replace by other
    def f(): f() # call second!!
    a = T(f)     # to call first
    def f():...

3) refactor: rename function
    # first version
    def f():f()
    -------------------
    # second version, wrap it
    def f():
        log();
        try:            # to avoid indent
            _f_impl()
        except...
    def _f_impl(): _f_impl() # hadnot we rename it!


solution:
    # add __this_func__
    class C:
        @xxxx
        def f(self):
            self.f()
            __class__.f(self)
            __this_func__(self)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170301/81705b9e/attachment.html>


More information about the Python-ideas mailing list