[New-bugs-announce] [issue33211] lineno and col_offset are wrong on function definitions with decorators
report at bugs.python.org
Tue Apr 3 01:13:29 EDT 2018
New submission from Gil Forcada <gil.gnome at gmail.com>:
Given the following code:
def my_function(self): pass
Parsing it with ast module, the lineno and col_offset of the ast.FunctionDef is reported to be where the decorator starts (i.e. line 3 column 4) rather than where the actual def statement is (i.e. line 4 column 4).
This is due to the decorator that is part of the ast.FunctionDef, but as there can be multiple decorators (which they don't provide their own lineno and col_offset arguments) and they can span across multiple lines, there is no reliable way to actually know where the actual def statement starts physically.
See this bug report on flake8-builtins plugin (I'm the author) reported by @dhood user on github:
components: Library (Lib)
title: lineno and col_offset are wrong on function definitions with decorators
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce