[New-bugs-announce] [issue46133] Unclear whether one can (or how to) provide source to exec-generated code

Matt B report at bugs.python.org
Sun Dec 19 11:17:53 EST 2021


New submission from Matt B <eb3f73+python+org at yaymail.com>:

Unless I missed it, looking at https://github.com/python/cpython/blob/main/Lib/pdb.py, https://github.com/python/cpython/blob/main/Lib/inspect.py, and https://docs.python.org/3/library/pdb.html doesn't give much of a clue how to provide sources to exec-generated code.

I may have misread, but pdb *seems* to lean on inspect.findsource which eventually excludes sources that match `^<.*>$` (like `<string>`).

Running attached test_case.py:

% python test_case.py
> <string>(4)foo()
(Pdb) l
[EOF]
(Pdb) c
inspect.getfile(<function foo at 0x10b735160>): <string>
calling inspect.findsource(<function foo at 0x10b735160>) ...
Traceback (most recent call last):
  File "/Users/matt/Documents/dev/numerary/test_case.py", line 12, in <module>
    foo()
  File "/Library/Frameworks/MacPorts-20200907/Python.framework/Versions/3.9/lib/python3.9/inspect.py", line 835, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

----------
files: test_case.py
messages: 408910
nosy: posita
priority: normal
severity: normal
status: open
title: Unclear whether one can (or how to) provide source to exec-generated code
Added file: https://bugs.python.org/file50502/test_case.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46133>
_______________________________________


More information about the New-bugs-announce mailing list