]> granicus.if.org Git - python/commitdiff
Patch from Georg Brandl: Fix co_lineno of decorated function and class objects. If...
authorChristian Heimes <christian@cheimes.de>
Sat, 23 Feb 2008 15:01:06 +0000 (15:01 +0000)
committerChristian Heimes <christian@cheimes.de>
Sat, 23 Feb 2008 15:01:06 +0000 (15:01 +0000)
Lib/test/test_inspect.py
Misc/NEWS
Python/ast.c

index 35a3b060ff1973556662775ee663a6176e2976d3..794e4fa43d425177284e22d769cdf0ebbfaabb38 100644 (file)
@@ -239,7 +239,7 @@ class TestDecorators(GetSourceBase):
     fodderFile = mod2
 
     def test_wrapped_decorator(self):
-        self.assertSourceEqual(mod2.wrapped, 16, 17)
+        self.assertSourceEqual(mod2.wrapped, 14, 17)
 
     def test_replacing_decorator(self):
         self.assertSourceEqual(mod2.gone, 9, 10)
index 1a3ae21d7af18218442d900eb8b865aa8839a015..3d9f4189a79c0b76d93658a9462d6c21fa7f4b59 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -363,6 +363,8 @@ Core and Builtins
 Library
 -------
 
+- inspect.getsource() includes the decorators again.
+
 - Issue #1916. Added isgenerator() and isgeneratorfunction() to inspect.py.
 
 - #1224: Fixed bad url parsing when path begins with double slash.
index 97486c55155f071c5208232b9adb645f8dc3a0dc..8b68182582dc6792f61175095a0c19dd5157e550 100644 (file)
@@ -1015,6 +1015,12 @@ ast_for_decorated(struct compiling *c, const node *n)
     } else if (TYPE(CHILD(n, 1)) == classdef) {
       thing = ast_for_classdef(c, CHILD(n, 1), decorator_seq);
     }
+    /* we count the decorators in when talking about the class' or
+     * function's line number */
+    if (thing) {
+        thing->lineno = LINENO(n);
+        thing->col_offset = n->n_col_offset;
+    }
     return thing;
 }