Commit 38d0c5b8 authored by Stefan Behnel's avatar Stefan Behnel Committed by GitHub

Merge pull request #2684 from fkohlgrueber/func_decorator_co_firstlineno_fix

fix co_firstlineno for functions that have decorators
parents e233427b 097ff5e3
......@@ -3367,7 +3367,7 @@ def _reject_cdef_modifier_in_py(s, name):
def p_def_statement(s, decorators=None, is_async_def=False):
# s.sy == 'def'
pos = s.position()
pos = decorators[0].pos if decorators else s.position()
# PEP 492 switches the async/await keywords on in "async def" functions
if is_async_def:
s.enter_async()
......
......@@ -7,5 +7,5 @@ class Pyclass(object):
pass
_ERRORS = """
6:4: cfunc directive is not allowed here
5:4: cfunc directive is not allowed here
"""
......@@ -7,5 +7,5 @@ def foo():
pass
_ERRORS = u"""
6:0: The autotestdict compiler directive is not allowed in function scope
5:0: The autotestdict compiler directive is not allowed in function scope
"""
......@@ -53,5 +53,5 @@ def pyfunc(x): # invalid
_ERRORS = """
44:22: Calling gil-requiring function not allowed without gil
45:24: Calling gil-requiring function not allowed without gil
49:0: Python functions cannot be declared 'nogil'
48:0: Python functions cannot be declared 'nogil'
"""
......@@ -11,8 +11,8 @@ def test():
_ERRORS = u"""
9:0: Expected path '//ComprehensionNode' not found in result tree
9:0: Expected path '//ComprehensionNode//FuncDefNode' not found in result tree
9:0: Unexpected path '//NameNode' found in result tree
9:0: Unexpected path '//SimpleCallNode' found in result tree
5:0: Expected path '//ComprehensionNode' not found in result tree
5:0: Expected path '//ComprehensionNode//FuncDefNode' not found in result tree
5:0: Unexpected path '//NameNode' found in result tree
5:0: Unexpected path '//SimpleCallNode' found in result tree
"""
......@@ -242,7 +242,7 @@ _WARNINGS = """
218:29: Ambiguous types in annotation, ignoring
# BUG:
46:6: 'pytypes_cpdef' redeclared
121:0: 'struct_io' redeclared
156:0: 'struct_convert' redeclared
175:0: 'exception_default' redeclared
120:0: 'struct_io' redeclared
149:0: 'struct_convert' redeclared
168:0: 'exception_default' redeclared
"""
......@@ -391,3 +391,22 @@ cdef class TestOptimisedBuiltinMethod:
def call(self, arg, obj=None):
(obj or self).append(arg+1) # optimistically optimised => uses fast fallback method call
def do_nothing(f):
"""Dummy decorator for `test_firstlineno_decorated_function`"""
return f
@do_nothing
@do_nothing
def test_firstlineno_decorated_function():
"""
check that `test_firstlineno_decorated_function` starts 5 lines below `do_nothing`
>>> test_firstlineno_decorated_function()
5
"""
l1 = do_nothing.__code__.co_firstlineno
l2 = test_firstlineno_decorated_function.__code__.co_firstlineno
return l2 - l1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment