[issue9284] inspect.findsource() cannot find source for doctest code

2011-06-11 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset 527c40add91d by Benjamin Peterson in branch '2.7':
allow "fake" filenames in findsource (closes #9284)
http://hg.python.org/cpython/rev/527c40add91d

New changeset 6cc4579dca02 by Benjamin Peterson in branch '3.2':
allow "fake" filenames in findsource (closes #9284)
http://hg.python.org/cpython/rev/6cc4579dca02

New changeset f05affb0bb2a by Benjamin Peterson in branch 'default':
merge 3.2 (#9284)
http://hg.python.org/cpython/rev/f05affb0bb2a

--
nosy: +python-dev
resolution:  -> fixed
stage: test needed -> committed/rejected
status: open -> closed

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2011-06-09 Thread Dirkjan Ochtman

Changes by Dirkjan Ochtman :


Removed file: http://bugs.python.org/file22270/issue9284.diff

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2011-06-09 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

Here's a fresh patch.

--
Added file: http://bugs.python.org/file22297/issue9284.diff

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2011-06-09 Thread Benjamin Peterson

Benjamin Peterson  added the comment:

2011/6/9 Dirkjan Ochtman :
>
> Dirkjan Ochtman  added the comment:
>
> I'm fine with moving the test; I put it in doctest because the inspect 
> behavior we're relying upon here seems somewhat doctest-specific, and the 
> test itself is a doctest. Do you want me to move it? I'll fix up the other 
> things as well.

I would prefer that if the bug is somehow reintroduced, test_inspect
instead of test_doctest fails.

--

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2011-06-09 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

I'm fine with moving the test; I put it in doctest because the inspect behavior 
we're relying upon here seems somewhat doctest-specific, and the test itself is 
a doctest. Do you want me to move it? I'll fix up the other things as well.

--

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2011-06-09 Thread Benjamin Peterson

Benjamin Peterson  added the comment:

- First line should be directly after the docstring
- One import per line
- Shouldn't this test be in test_inspect, since that's what you're changing?

--

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2011-06-09 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

Would it still be possible to get this into 2.7.2? It's a 2.6-2.7 regression, 
would be nice to fix, and it seems fairly low-impact.

--
nosy: +benjamin.peterson

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2011-06-07 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

Here's an attempted patch against 2.7. It seemed nice to put the test in 
test_doctest, but maybe it belongs in inspect...

--
keywords: +needs review, patch
Added file: http://bugs.python.org/file22270/issue9284.diff

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2010-07-17 Thread R. David Murray

R. David Murray  added the comment:

Oh, right, I remember that now.  Thanks.

--

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2010-07-17 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

Because doctest also monkeypatches linecache, and without monkeypatching 
linecache this also fails in 2.6.

--

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2010-07-17 Thread R. David Murray

R. David Murray  added the comment:

I don't understand why monkey patching linecache produces a valid test case.  
Can you explain?

Since I believe the same code/bugfix is in 3.x, I'm adding those versions.

--
stage: needs patch -> unit test needed
versions: +Python 3.1, Python 3.2

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2010-07-17 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

Here's a test case that doesn't require doctest trickery:

import inspect, linecache
fn, source = '', 'def x(): pass\n'
getlines = linecache.getlines
def monkey(filename, module_globals=None):
 if filename == fn:
 return source.splitlines(True)
 else:
 return getlines(filename, module_globals)
linecache.getlines = monkey
exec compile(source, fn, 'single') in globals()
inspect.getsource(x)

--

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2010-07-17 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

After chatting with Dirkjan, I misunderstood the impact of the patch. It only 
occurs when inspect.getsource() is called from a doctest, which isn't a very 
common situation.

--
priority: critical -> normal

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2010-07-17 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
priority: normal -> critical

___
Python tracker 

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



[issue9284] inspect.findsource() cannot find source for doctest code

2010-07-17 Thread Dirkjan Ochtman

New submission from Dirkjan Ochtman :

The fix for issue4050 broke some of my doctests. Minimal test:

import doctest, inspect
def test():
'''
>>> def x(): pass
>>> inspect.getsource(x)
'def x(): pass\\n'
'''
doctest.run_docstring_examples(test, globals())

This works in 2.6, but not in 2.7. Reason is that inspect.getsourcefile() finds 
the fake filename '', which it doesn't understand. In 2.6, 
inspect.getmodule() is also tried, which first looks at obj.__module__, and the 
filename can be derived from that. I suggest that inspect.getsourcefile() grows 
some code to use this trick if the filename seems fake (f[0] + f[-1] == '<>').

--
components: Library (Lib)
messages: 110551
nosy: ajaksu2, brodie, djc, pitrou, r.david.murray
priority: normal
severity: normal
stage: needs patch
status: open
title: inspect.findsource() cannot find source for doctest code
type: behavior
versions: Python 2.7

___
Python tracker 

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