This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zsolt
Recipients RafeSacks, belopolsky, ggenellina, zsolt
Date 2008-12-09.07:58:03
SpamBayes Score 9.8492325e-09
Marked as misclassified No
Message-id <1228809486.15.0.16851144522.issue4335@psf.upfronthosting.co.za>
In-reply-to
Content
We are also using inspect.getsourceline() in a large system at my
company and we observed some unreliable behavior in the past which we
never had time to analyze till today. Interesting coincidence, but today
we finally took the effort and traced the issue, and we found that:

getsourceline() does not report the last line of a class definition body
_IF_:
  (1) that line is the last line of the file, _AND_
  (2) that line is not terminated with a newline (\n)

This also answers Alexandre's question: yes, the problem happens only if
the line is unterminated.

I understand that an unterminated line may be non-conforming per Python
specs, but my WingIDE happily saved the file, so I suspect other editors
may just do the same, and I do agree with Rafe that it would be nice if
inspect would be resilient against the missing \n. I assume there would
be no harm, and it could eliminate some angst (it is really not obvious
first why it fails).

I would really love to see this fixed in a patch release on the 2.5+
lines. Any chance?
History
Date User Action Args
2008-12-09 07:58:06zsoltsetrecipients: + zsolt, belopolsky, ggenellina, RafeSacks
2008-12-09 07:58:06zsoltsetmessageid: <1228809486.15.0.16851144522.issue4335@psf.upfronthosting.co.za>
2008-12-09 07:58:05zsoltlinkissue4335 messages
2008-12-09 07:58:04zsoltcreate