[issue37166] inspect.findsource doesn't handle shortened files gracefully

2019-06-05 Thread Michael Bejda


Change by Michael Bejda :


--
keywords: +patch
pull_requests: +13727
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/13850

___
Python tracker 
<https://bugs.python.org/issue37166>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37166] inspect.findsource doesn't handle shortened files gracefully

2019-06-28 Thread Michael Bejda


Michael Bejda  added the comment:

I do not believe it is specific to the way we package things:

$ cat a.py:
import inspect








def foo(): pass

inspect.getsource(foo)
$ python3 -m compileall -b a.py
$ black a.py  # to remove the empty lines
$ python3 a.pyc  # Index error
Traceback (most recent call last):
  File "a.py", line 12, in 
  File "/usr/local/fbcode/gcc-5-glibc-2.23/lib/python3.6/inspect.py", line 968, 
in getsource
lines, lnum = getsourcelines(object)
  File "/usr/local/fbcode/gcc-5-glibc-2.23/lib/python3.6/inspect.py", line 955, 
in getsourcelines
lines, lnum = findsource(object)
  File "/usr/local/fbcode/gcc-5-glibc-2.23/lib/python3.6/inspect.py", line 828, 
in findsource
if pat.match(lines[lnum]): break
IndexError: list index out of range


You are correct, the heuristic may not return the correct function. However, if 
we are, for any reason, unable to detect the source mismatch, it would be 
better to return 0 line (for the beginning of the module) or raise a 
SystemError instead of an IndexError (which the user does not expect).

--
nosy: +mib

___
Python tracker 
<https://bugs.python.org/issue37166>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37166] inspect.findsource doesn't handle shortened files gracefully

2019-06-28 Thread Michael Bejda


Michael Bejda  added the comment:

I don't think linecache.checkcache helps here. In your example, it would detect 
the modification, but I don't see how it could persist data if the compilation 
and execution are different processes.

--

___
Python tracker 
<https://bugs.python.org/issue37166>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com