On 10/26/2013 01:55 AM, Yaşar Arabacı wrote:
Hi people,

I wrote this decorator: https://gist.github.com/yasar11732/7163528

When this code executes:

     @debugging
     def myfunc(a, b, c, d = 48):
         a = 129
         return a + b

     print myfunc(12,15,17)

This is printed:

     function myfunc called
     a 12
     c 17
     b 15
     d 48
     assigned new value to a: 129
     returning 144
    144

I think I can be used instead of inserting and deleting print
statements when trying to see what is
passed to a function and what is assingned to what etc. I think it can
be helpful during debugging.

It works by rewriting ast of the function and inserting print nodes in it.

What do you think?



Looks very nice, but I've three  questions:

1. What happens, if a function has more then one decorator? Wouldn't it be better to
just remove the debugging decorator instead of removing all decorators?

2. In the case of an assignment (but holds for the return statement too).
think about the following code:

a = 0
@debugging
def foo():
    a = a +  1

def bar():
    #assign something else to a

Imagine foo() and bar() being called in two different threads. Wouldn't it be better

to replace  a = a + 1 by

|global_debugging_lock_objekt.acquire()|
a = a + 1
print "assigned new value to a, %r", a
|global_debugging_lock_objekt.release()|

for some global lock object.

3. What happens in the case of  a += 1?

bg,
Johannes

--
GLOBE Development GmbH
Königsberger Strasse 260
48157 MünsterGLOBE Development GmbH
Königsberger Strasse 260
48157 Münster
0251/5205 390

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to