Issue 6700: inspect.getsource() returns incorrect source lines at the module level (original) (raw)
Created on 2009-08-14 04:19 by ggenellina, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Files | |||
---|---|---|---|
File name | Uploaded | Description | Edit |
inspect.diff | ggenellina,2009-08-14 04:19 | patch against trunk | review |
show_inspect_bug.py | ggenellina,2009-08-14 04:29 | ||
issue6700.patch | jamesls,2013-05-23 02:56 | review |
Pull Requests | |||
---|---|---|---|
URL | Status | Linked | Edit |
PR 8864 | merged | v2m,2018-08-23 00:34 | |
PR 8898 | merged | miss-islington,2018-08-24 14:18 | |
PR 8899 | merged | miss-islington,2018-08-24 14:18 | |
PR 8900 | merged | taleinat,2018-08-24 14:40 |
Messages (8) | ||
---|---|---|
msg91541 - (view) | Author: Gabriel Genellina (ggenellina) | Date: 2009-08-14 04:19 |
inspect.getsource(obj) returns incorrect results when obj is a traceback or frame object outside any function (that is, at the module level). This demo script shows the problem. The correct output should contain all source lines in the module, but it only returns the first two: D:\temp>type show_inspect_bug.py def foo(x): return y + z import inspect frame = inspect.currentframe() print inspect.getsource(frame) D:\temp>python show_inspect_bug.py def foo(x): return y + z The attached patch fixes the problem and adds some missing test cases. Originally reported by Juanjo Conti at the local Python group. | ||
msg102651 - (view) | Author: Daniel Diniz (ajaksu2) * ![]() |
Date: 2010-04-08 22:59 |
Confirmed in trunk and py3k. Also affects inspect.getsourcelines. | ||
msg189842 - (view) | Author: James Saryerwinnie (jamesls) * | Date: 2013-05-23 02:56 |
I confirmed the issue in tip. One of the issues with the original patch is that it modifies the tokeneater method used by getblock which won't work if the first token is any of the special cased tokens in the original patch ('@', 'def', 'class'). I've added additional tests that show where the original patch fails. An alternative approach is to check in getsourcelines whether or not we're dealing with a traceback or frame object in the module scope, and if so, return the lines of the entire module. I've attached an updated patch that implements this along with additional tests. | ||
msg324000 - (view) | Author: Tal Einat (taleinat) * ![]() |
Date: 2018-08-24 14:18 |
New changeset 91cb298f811961277fd4cc4a32211899d48bedcb by Tal Einat (Vladimir Matveev) in branch 'master': bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864) https://github.com/python/cpython/commit/91cb298f811961277fd4cc4a32211899d48bedcb | ||
msg324002 - (view) | Author: miss-islington (miss-islington) | Date: 2018-08-24 14:41 |
New changeset 0e707b4c6a47086d8e723c7a010c3f5cf8296946 by Miss Islington (bot) in branch '3.6': bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864) https://github.com/python/cpython/commit/0e707b4c6a47086d8e723c7a010c3f5cf8296946 | ||
msg324004 - (view) | Author: miss-islington (miss-islington) | Date: 2018-08-24 14:44 |
New changeset 3e6020c4ddf7acea91efdae770320c6ce06b93db by Miss Islington (bot) in branch '3.7': bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864) https://github.com/python/cpython/commit/3e6020c4ddf7acea91efdae770320c6ce06b93db | ||
msg324114 - (view) | Author: Tal Einat (taleinat) * ![]() |
Date: 2018-08-26 08:45 |
New changeset 491740f116755e220135e596ec802ea3a0f65596 by Tal Einat in branch '2.7': [2.7] bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864) https://github.com/python/cpython/commit/491740f116755e220135e596ec802ea3a0f65596 | ||
msg324115 - (view) | Author: Tal Einat (taleinat) * ![]() |
Date: 2018-08-26 08:47 |
Thanks for reporting this, Gabriel! Thanks for the PR, Vladimir! |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:51 | admin | set | github: 50949 |
2018-08-26 08:47:22 | taleinat | set | status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved |
2018-08-26 08:45:04 | taleinat | set | messages: + |
2018-08-24 14:44:50 | miss-islington | set | messages: + |
2018-08-24 14:41:43 | miss-islington | set | nosy: + miss-islingtonmessages: + |
2018-08-24 14:40:15 | taleinat | set | pull_requests: + <pull%5Frequest8371> |
2018-08-24 14🔞20 | miss-islington | set | pull_requests: + <pull%5Frequest8370> |
2018-08-24 14🔞14 | miss-islington | set | pull_requests: + <pull%5Frequest8369> |
2018-08-24 14🔞08 | taleinat | set | nosy: + taleinatmessages: + |
2018-08-23 09:40:09 | taleinat | set | versions: + Python 2.7 |
2018-08-23 08:51:55 | taleinat | set | versions: + Python 3.8, - Python 3.5 |
2018-08-23 00:34:56 | v2m | set | pull_requests: + <pull%5Frequest8338> |
2018-08-17 04:21:47 | Aivar.Annamaa | set | versions: + Python 3.6, Python 3.7title: inspect.getsource() returns incorrect source lines -> inspect.getsource() returns incorrect source lines at the module level |
2018-08-17 04:19:52 | Aivar.Annamaa | set | nosy: + Aivar.Annamaa |
2015-01-17 15:58:05 | Claudiu.Popa | set | nosy: + Claudiu.Popa, yselivanovversions: + Python 3.5, - Python 2.6, Python 3.1, Python 2.7, Python 3.2 |
2013-05-23 02:56:40 | jamesls | set | files: + issue6700.patchnosy: + jameslsmessages: + |
2010-04-08 22:59:18 | ajaksu2 | set | priority: normalnosy: + ajaksu2messages: + stage: patch review |
2009-08-14 04:29:20 | ggenellina | set | files: + show_inspect_bug.py |
2009-08-14 04:19:21 | ggenellina | create |