[issue27578] inspect.findsource raises exception with empty __init__.py

2020-11-13 Thread kernc


kernc  added the comment:

The proposed patch doesn't break any interfaces. 
`inspect.getsource/.getsourcelines()` still raise `OSError` if the source is 
unretrievable. `linecache.getlines()` is undocumented, but the change retains 
perfect compatibility with *docstrings* of both `linecache.getlines()` which is 
affected and `linecache.updatecache()` which is touched.

--

___
Python tracker 

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2020-07-06 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

I agree that getsource raising is a bug.  I would more at the behavior and doc 
for getlines before I decided about that.

--
nosy: +terry.reedy
versions:  -Python 2.7, Python 3.5, Python 3.6, Python 3.9

___
Python tracker 

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2020-06-11 Thread kernc


Change by kernc :


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

___
Python tracker 

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2020-06-11 Thread kernc


Change by kernc :


--
nosy: +kernc
versions: +Python 3.10, Python 3.9

___
Python tracker 

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2016-07-21 Thread R. David Murray

R. David Murray added the comment:

I think someone should propose a patch with tests and we'll evaluate it.  We 
prefer to retain backward compatibility even on undocumented interfaces, if 
possible, but yes they are more open to change (though only in a feature 
release, in general).

--

___
Python tracker 

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2016-07-21 Thread Antti Haapala

Antti Haapala added the comment:

It must be noted that `getlines` itself is not documented, and thus there is no 
backwards-compatibility to preserve really. `getline` returns '' for *any* 
erroneous line, so it wouldn't affect it.

--

___
Python tracker 

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2016-07-21 Thread Antti Haapala

Antti Haapala added the comment:

Or perhaps getlines should return [''] for empty regular files?

--
nosy: +ztane

___
Python tracker 

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2016-07-20 Thread R. David Murray

R. David Murray added the comment:

I agree that this is inconsistent.  It might be quite tricky to fix, though, 
unless we special case file.endswith('__init__.py'), which feels like a hack.  
But maybe it is appropriate.

--
nosy: +r.david.murray
versions: +Python 3.6

___
Python tracker 

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2016-07-20 Thread Alexander Todorov

New submission from Alexander Todorov:

$ python2
Python 2.7.5 (default, Oct 11 2015, 17:47:16) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> from pykickstart import handlers
>>> inspect.getsource(handlers)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib64/python2.7/inspect.py", line 701, in getsource
lines, lnum = getsourcelines(object)
  File "/usr/lib64/python2.7/inspect.py", line 690, in getsourcelines
lines, lnum = findsource(object)
  File "/usr/lib64/python2.7/inspect.py", line 538, in findsource
raise IOError('could not get source code')
IOError: could not get source code
>>> 

There is a `pykickstart/handlers/__init__.py` file which is empty and the above 
import works fine as you can see. However `inspect.findsource` raises an 
exception. The same problem exists in Python 3.5 as well. The error comes from 
here:

532 module = getmodule(object, file)
533 if module:
534 lines = linecache.getlines(file, module.__dict__)
535 else:
536 lines = linecache.getlines(file)
537 if not lines:
538 raise IOError('could not get source code')


At this point `lines` is an empty list and we raise the exception. I'm hitting 
this problem when using a mutation testing tool that relies on getsource (which 
calls findsource). 

One possible workaround is to add a comment in the __init__.py file and 
everything seems to be working then. Another one is to patch the tool I'm using 
to take into account empty __init__.py files.

--
components: Library (Lib)
messages: 270867
nosy: Alexander Todorov
priority: normal
severity: normal
status: open
title: inspect.findsource raises exception with empty __init__.py
type: behavior
versions: Python 2.7, Python 3.5

___
Python tracker 

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