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.
Created on 2012年04月03日 13:51 by Sean.Grider, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg157417 - (view) | Author: Sean Grider (Sean.Grider) | Date: 2012年04月03日 13:51 | |
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 |
|||
| msg222245 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2014年07月04日 00:15 | |
@Sean we're sorry for the delay in getting back to you. |
|||
| msg283881 - (view) | Author: Sean Grider (Sean.Grider) | Date: 2016年12月23日 14:21 | |
I had forgotten all about this bug until I saw an email from Pam today. The appears to still be some delay. |
|||
| msg283894 - (view) | Author: Pam McA'Nulty (Pam.McANulty) * | Date: 2016年12月23日 18:37 | |
I just clicked "Random Issue" and it seemed to be an "easy" (ish) one - which is just what I'd like to tackle over xmas break :) |
|||
| msg283897 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2016年12月23日 19:22 | |
Well, there's nobody being paid for keeping track of bugs and responding, so things do slip through the cracks. Pinging an issue after there's been a lack of response for a while is appropriate, if you notice it yourself :) (Mark, while he was trying to be helpful, does not speak for the Python community.) As far as the question of is this intentional, the answer is yes. Presumably you are calling it on the 'main' function. If you call it on the module, you will get all source lines from that module. (You can't call it "on the file", the argument must be an object.) You'll see why it is intentional for the 'main' case if you consider that while in Python whitespace is syntactically significant, this is *not* true for Python comments indentation, because comments are treated as if they *are* whitespace. getsourcelines stops looking at sourcelines on the last line recorded in the lnotab for that function, so any subsequent comments are not considered part of the function. So, I'm closing this as "not a bug" since it works as expected for me in both python 2.7 and 3.6. Thanks for waking the issue up, Pam. You have contributed to python by getting an open issue closed, but you'll have to find something else to work on during the break I'm afraid. |
|||
| msg283898 - (view) | Author: Pam McA'Nulty (Pam.McANulty) * | Date: 2016年12月23日 19:38 | |
Yeah, I looked at the code and saw what you described, David. I think I'll see if there's a good place to mention this constraint in the docs and then I'll find another one (besides the macOS build issue I ran into when trying to build the latest master) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:28 | admin | set | github: 58688 |
| 2016年12月23日 19:38:41 | Pam.McANulty | set | messages: + msg283898 |
| 2016年12月23日 19:22:23 | r.david.murray | set | status: open -> closed nosy: + r.david.murray messages: + msg283897 resolution: not a bug stage: resolved |
| 2016年12月23日 18:37:34 | Pam.McANulty | set | messages: + msg283894 |
| 2016年12月23日 15:28:13 | BreamoreBoy | set | nosy:
- BreamoreBoy |
| 2016年12月23日 14:21:39 | Sean.Grider | set | messages: + msg283881 |
| 2016年12月23日 13:18:19 | Pam.McANulty | set | nosy:
+ Pam.McANulty |
| 2014年07月04日 00:15:15 | BreamoreBoy | set | nosy:
+ BreamoreBoy, yselivanov messages: + msg222245 |
| 2012年04月03日 14:07:02 | pitrou | set | nosy:
+ benjamin.peterson |
| 2012年04月03日 13:51:53 | Sean.Grider | create | |