There is something I do not understand about the lineno offset that's being calculated by the ast module. Usually when I get the lineno of some ast object, it gives me the first line the object is encountered.
For example in the below case, the foo's lin
st='def foo():\n print "hello"'
import ast
print ast.parse(st).body[0].lineno
print ast.parse(st).body[0].body[0].lineno
would return 1 for function foo and return 2 for the hello world printout
However, if I parse a multi-line docstring (ast.Expr) the lineno provided is the last line.
st='def foo():\n """\n Test\n """'
import ast
print ast.parse(st).body[0].lineno
print ast.parse(st).body[0].body[0].lineno
The result would still be line 1 for the function but it would be line 4 for the docstring. I would have expected it to be on line 2 since that is when the docstring begins.
I guess what I am asking is if there is a way to always get the first lineno of all ast objects including ast.Expr .