Message157417
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 |
|
Date |
User |
Action |
Args |
2012-04-03 13:51:54 | Sean.Grider | set | recipients:
+ Sean.Grider |
2012-04-03 13:51:54 | Sean.Grider | set | messageid: <1333461114.24.0.345526771392.issue14483@psf.upfronthosting.co.za> |
2012-04-03 13:51:53 | Sean.Grider | link | issue14483 messages |
2012-04-03 13:51:53 | Sean.Grider | create | |
|