New submission from Sean Grider :
I have a custom parser that generates html files to describe what python
scripts do depending on their source comments. I use inspect.getsourcelines to
parse out different comments styles (I use #@, #@@ and #$ to signal custom
comments)
I recently found that getsource and getsourcelines return nothing if the file
contains nothing other than a def main and it's comments.
It seems that getsource stops reading after the last non-comment line. For
example:
def main():
""" description """
#comment1
#comment2
#comment3
getsource on the above file will return def main and the doc_string but nothing
else.
if however I change it to:
def main():
""" description """
#comment1
#comment2
#comment3
return
I now get the entire file, but just doing the following:
def main():
""" description """
#comment1
my_var = 123
#comment2
#comment3
will now give me def main, the doc_string and comment1, but nothing else.
Is this expected behavior? I would think that the parser should not care if the
source is comments or code, I just want to read whatever is in the file.
This behavior is present on 2.7.2 on both Windows 7x64 and RedHat
2.6.39.4-2.fc12.x86_64
--
messages: 157417
nosy: Sean.Grider
priority: normal
severity: normal
status: open
title: inspect.getsource fails to read a file of only comments
type: behavior
versions: Python 2.7
___
Python tracker
<http://bugs.python.org/issue14483>
___
___
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com