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.

classification
Title: inspect.getsource returns invalid source for non-newline-ending module
Type: behavior Stage:
Components: Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, hpk
Priority: normal Keywords: patch

Created on 2010-05-21 14:34 by hpk, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
inspect.patch hpk, 2010-05-21 14:34
Messages (4)
msg106245 - (view) Author: holger krekel (hpk) Date: 2010-05-21 14:34
Executing the attached "inspect_failure.py" under python2.6 or python3.1 results in an assertion error: Python fails to obtain the source code of a function that is defined at the end of a module whose last line does not contain a line ending character. 

After brief analysis i think there are two approaches to fixing it: normalizing newlines in inspect.findsource (see attached inspect.patch file against r312) or performing normalization in linecache.updatecache which does it already for source code obtained from PEP302 loaders. Or any other ideas?
msg106268 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-05-21 21:32
Fixed in r81432 by making linecache smarter.
msg106285 - (view) Author: holger krekel (hpk) Date: 2010-05-22 07:46
Great. Also to be backported to 2.x?

holger

On Fri, May 21, 2010 at 11:32 PM, Benjamin Peterson
<report@bugs.python.org> wrote:
>
> Benjamin Peterson <benjamin@python.org> added the comment:
>
> Fixed in r81432 by making linecache smarter.
>
> ----------
> nosy: +benjamin.peterson
> resolution:  -> fixed
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue8782>
> _______________________________________
>
msg106304 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-05-22 12:40
2010/5/22 holger krekel <report@bugs.python.org>:
>
> holger krekel <holger.krekel@gmail.com> added the comment:
>
> Great. Also to be backported to 2.x?

That is 2.x.
History
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 53028
2010-05-22 12:40:21benjamin.petersonsetmessages: + msg106304
2010-05-22 07:46:52hpksetmessages: + msg106285
2010-05-21 21:32:01benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg106268

resolution: fixed
2010-05-21 14:34:07hpkcreate