diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2019-06-02 13:48:22 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-06-02 13:48:22 +0200 |
commit | 42c21d6088add3b6fe1920cc9f3072afb9e7217c (patch) | |
tree | 96bbf71c080868dd1d3cb7a7aaec55233504c2e9 /astroid/rebuilder.py | |
parent | 6f8f4747aadc00e684e39303148dc23829b821bd (diff) | |
download | astroid-git-42c21d6088add3b6fe1920cc9f3072afb9e7217c.tar.gz |
Set the line number of decorated functions for python 3.8
Python 3.8 sets the line number of a decorated function
to be the actual line number of the function, but the
previous versions expected the decorator's line number instead.
We reset the function's line number to that of the
first decorator to maintain backward compatibility.
It's not ideal but this discrepancy was baked into
the framework for *years*.
Diffstat (limited to 'astroid/rebuilder.py')
-rw-r--r-- | astroid/rebuilder.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py index a60785c4..64485eec 100644 --- a/astroid/rebuilder.py +++ b/astroid/rebuilder.py @@ -40,6 +40,7 @@ REDIRECT = { PY3 = sys.version_info >= (3, 0) PY34 = sys.version_info >= (3, 4) PY37 = sys.version_info >= (3, 7) +PY38 = sys.version_info >= (3, 8) def _binary_operators_from_module(module): @@ -580,7 +581,20 @@ class TreeRebuilder: """visit an FunctionDef node to become astroid""" self._global_names.append({}) node, doc = self._get_doc(node) - newnode = cls(node.name, doc, node.lineno, node.col_offset, parent) + + lineno = node.lineno + if PY38: + # Python 3.8 sets the line number of a decorated function + # to be the actual line number of the function, but the + # previous versions expected the decorator's line number instead. + # We reset the function's line number to that of the + # first decorator to maintain backward compatibility. + # It's not ideal but this discrepancy was baked into + # the framework for *years*. + if node.decorator_list: + lineno = node.decorator_list[0].lineno + + newnode = cls(node.name, doc, lineno, node.col_offset, parent) if node.decorator_list: decorators = self.visit_decorators(node, newnode) else: |