From: Christian Heimes Date: Sat, 23 Feb 2008 15:01:06 +0000 (+0000) Subject: Patch from Georg Brandl: Fix co_lineno of decorated function and class objects. If... X-Git-Tag: v3.0a3~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=09aaa88328a5083469b2682230c7f3c62942afab;p=thirdparty%2FPython%2Fcpython.git Patch from Georg Brandl: Fix co_lineno of decorated function and class objects. If you see an error in test_inspect please delete all pyc files. --- diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 35a3b060ff19..794e4fa43d42 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 1a3ae21d7af1..3d9f4189a79c 100644 --- 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. diff --git a/Python/ast.c b/Python/ast.c index 97486c55155f..8b68182582dc 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -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; }