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年06月21日 18:01 by acapnotic, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| inspectLineNumber.py | acapnotic, 2012年06月21日 18:01 | reproduction example | ||
| 15128-inspect-source-linenum.diff | acapnotic, 2012年06月21日 21:38 | patch against python 2.7 | review | |
| Messages (4) | |||
|---|---|---|---|
| msg163355 - (view) | Author: Kevin M. Turner (acapnotic) * | Date: 2012年06月21日 18:01 | |
The attached example shows how inspect.findsource fails when given a stack frame that points to a non-existent source line, and how inspect.getframeinfo and getinnerframes do not handle that failure. On the one hand, yes, this code was asking for it by building such a broken frame. On the other hand, having code that examines tracebacks result in tracebacks of its own sucks a whole bunch. The inspect find&get source methods are documented as returning IOError if they cannot find the source, and the calling code handles that case, so that's probably what should happen here. (Actually, that seems straightforward enough, I can make a patch for that shortly.) This may help with issue #1628987 as well. |
|||
| msg163370 - (view) | Author: Kevin M. Turner (acapnotic) * | Date: 2012年06月21日 21:38 | |
patch attached (against python 2.7 tip) |
|||
| msg182890 - (view) | Author: Jyrki Pulliainen (nailor) * | Date: 2013年02月24日 20:10 | |
Use of IOError might be a bit problematic. The find & get return IOError if they can't find the source, but for mismatch if the line is not found is not to me an IOError. Btw, to be able to merge your patch, you need to sign the contributor agreement in here: http://www.python.org/psf/contrib/contrib-form-python/ |
|||
| msg377129 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2020年09月18日 17:30 | |
I think this was fixed by now:
I changed the script to print the result:
******************************************
import inspect, sys
# /etc/hostname is one line, but our source has multiple lines
code = compile('\n\n\n1/0', '/etc/hostname', 'exec')
try:
exec(code, {})
except Exception:
tb = sys.exc_info()[2]
else:
assert False, "unreachable, exec should always raise exception"
# this fails with an IndexError
print(inspect.getinnerframes(tb))
******************************************
and I got this output:
C:\Users\User\src\cpython>python.bat x.py
Running Release|Win32 interpreter...
[FrameInfo(frame=<frame at 0x01140DF0, file 'C:\\Users\\User\\src\\cpython\\x.py', line 14, code <module>>, filename='C:\\Users\\User\\src\\cpython\\x.py', lineno=7, function='<module>', code_context=[' exec(code, {})\n'], index=0), FrameInfo(frame=<frame at 0x011CA758, file '/etc/hostname', line 4, code <module>>, filename='/etc/hostname', lineno=4, function='<module>', code_context=None, index=None)]
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:31 | admin | set | github: 59333 |
| 2020年11月04日 02:16:18 | iritkatriel | set | status: open -> closed resolution: out of date stage: resolved |
| 2020年09月18日 17:30:36 | iritkatriel | set | nosy:
+ iritkatriel messages: + msg377129 |
| 2013年02月24日 20:10:00 | nailor | set | nosy:
+ nailor messages: + msg182890 |
| 2012年06月21日 21:38:41 | acapnotic | set | files:
+ 15128-inspect-source-linenum.diff keywords: + patch messages: + msg163370 |
| 2012年06月21日 18:01:07 | acapnotic | create | |