[Python-Dev] co_firstlineno on decorated functions
Alexander Belopolsky
alexander.belopolsky at gmail.com
Tue Aug 3 18:21:47 CEST 2010
On Tue, Aug 3, 2010 at 9:05 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> .. While I'd agree with you for a
> clean slate definition, that's not what we're dealing with here:
> "co_firstlineno" has an existing meaning, and it *isn't* "the line
> containing the def keyword", it's "the first line of the function,
> including any decorator lines". The decision could (and arguably
> should) have gone the other way when decorator syntax was first added,
> but changing our minds now would be making the situation worse rather
> than better.
I agree with Nick. What I see here is an ambiguity with good
arguments available either way. Since the decision has been made, it
is better to just stick to it and educate users through better
documentation.
Here is a copy of my private response to Eli a few days ago:
"""
I am not sure there is a bug there.
What is wrong with the following trace?
1: def d(x):
1: return x
1: @d
def f():
1: x = 0
6: for i in range(5):
5: x += 2
1: f()
Arguably, the "def" line should show up in coverage, but it is
not that dissimilar from
1: def \
f():
1: x = 0
6: for i in range(5):
5: x += 2
1: f()
If you think of decorator syntax as a part of the "def" line, the first
trace makes as much sense as the second.
"""
More information about the Python-Dev
mailing list