[Python-Dev] co_firstlineno on decorated functions

Nick Coghlan ncoghlan at gmail.com
Tue Aug 3 15:05:53 CEST 2010


On Tue, Aug 3, 2010 at 10:48 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Furthermore, co_firstlineno is an attribute of the code object, not the
> function object, so it shouldn't ideally depend on whether a decorator
> was applied or not.

You cut the part about the inspect module (and no doubt other code)
relying on the current meaning, though. 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.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list