[Python-Dev] co_firstlineno on decorated functions
Guido van Rossum
guido at python.org
Tue Aug 3 16:14:42 CEST 2010
On Tue, Aug 3, 2010 at 6:05 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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.
What are the use cases for co_firstlineno? Even if it is for
displaying the source code, I can find virtue for both sides of this
argument.
--
--Guido van Rossum (python.org/~guido)
More information about the Python-Dev
mailing list