← Back to team overview

divmod-dev team mailing list archive

[Bug 879945] Re: Incorrect line numbers for decorated functions

 

The Python AST gives the line number where the function definition
starts, which includes the decorator. However, the fault isn't on that
line and the user cannot fix the issue by changing that line.

Given a FunctionDef node:

node.lineno # where the function definition starts
node.lineno + len(node.decorator_list) # where the function name is

-- 
You received this bug notification because you are a member of Divmod-
dev, which is the registrant for Pyflakes.
https://bugs.launchpad.net/bugs/879945

Title:
  Incorrect line numbers for decorated functions

Status in Pyflakes:
  New

Bug description:
  In the code:

  def decorator(func):
      return func

  
  @decorator
  def defined_twice():
      pass

  
  @decorator
  def defined_twice():
      pass

  Pyflakes gives the error: twice.py:10: redefinition of function
  'defined_twice' from line 5

  It ought to be: twice.py:11: redefinition of function 'defined_twice'
  from line 6

To manage notifications about this bug go to:
https://bugs.launchpad.net/pyflakes/+bug/879945/+subscriptions


References