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 2010年07月17日 13:16 by djc, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue9284.diff | djc, 2011年06月09日 16:30 | |||
| Messages (13) | |||
|---|---|---|---|
| msg110551 - (view) | Author: Dirkjan Ochtman (djc) * (Python committer) | Date: 2010年07月17日 13:16 | |
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 '<docTest NoName[0]>', 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] == '<>'). |
|||
| msg110553 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2010年07月17日 13:43 | |
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. |
|||
| msg110557 - (view) | Author: Dirkjan Ochtman (djc) * (Python committer) | Date: 2010年07月17日 14:24 | |
Here's a test case that doesn't require doctest trickery: import inspect, linecache fn, source = '<test>', '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) |
|||
| msg110579 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年07月17日 16:32 | |
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. |
|||
| msg110581 - (view) | Author: Dirkjan Ochtman (djc) * (Python committer) | Date: 2010年07月17日 16:37 | |
Because doctest also monkeypatches linecache, and without monkeypatching linecache this also fails in 2.6. |
|||
| msg110584 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2010年07月17日 17:00 | |
Oh, right, I remember that now. Thanks. |
|||
| msg137797 - (view) | Author: Dirkjan Ochtman (djc) * (Python committer) | Date: 2011年06月07日 09:49 | |
Here's an attempted patch against 2.7. It seemed nice to put the test in test_doctest, but maybe it belongs in inspect... |
|||
| msg137940 - (view) | Author: Dirkjan Ochtman (djc) * (Python committer) | Date: 2011年06月09日 07:38 | |
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. |
|||
| msg137980 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2011年06月09日 14:52 | |
- 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? |
|||
| msg137991 - (view) | Author: Dirkjan Ochtman (djc) * (Python committer) | Date: 2011年06月09日 15:38 | |
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. |
|||
| msg137992 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2011年06月09日 15:40 | |
2011年6月9日 Dirkjan Ochtman <report@bugs.python.org>: > > Dirkjan Ochtman <dirkjan@ochtman.nl> 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. |
|||
| msg138009 - (view) | Author: Dirkjan Ochtman (djc) * (Python committer) | Date: 2011年06月09日 16:30 | |
Here's a fresh patch. |
|||
| msg138183 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2011年06月11日 20:56 | |
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 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:03 | admin | set | github: 53530 |
| 2011年06月11日 20:56:16 | python-dev | set | status: open -> closed nosy: + python-dev messages: + msg138183 resolution: fixed stage: test needed -> resolved |
| 2011年06月09日 16:31:05 | djc | set | files: - issue9284.diff |
| 2011年06月09日 16:30:51 | djc | set | files:
+ issue9284.diff messages: + msg138009 |
| 2011年06月09日 15:40:51 | benjamin.peterson | set | messages: + msg137992 |
| 2011年06月09日 15:38:56 | djc | set | messages: + msg137991 |
| 2011年06月09日 14:52:53 | benjamin.peterson | set | messages: + msg137980 |
| 2011年06月09日 07:38:08 | djc | set | nosy:
+ benjamin.peterson messages: + msg137940 |
| 2011年06月07日 09:49:16 | djc | set | keywords:
+ patch, needs review files: + issue9284.diff messages: + msg137797 |
| 2010年07月17日 17:00:47 | r.david.murray | set | messages: + msg110584 |
| 2010年07月17日 16:37:37 | djc | set | messages: + msg110581 |
| 2010年07月17日 16:32:46 | r.david.murray | set | stage: needs patch -> test needed messages: + msg110579 versions: + Python 3.1, Python 3.2 |
| 2010年07月17日 14:24:45 | djc | set | messages: + msg110557 |
| 2010年07月17日 13:43:43 | pitrou | set | priority: critical -> normal messages: + msg110553 |
| 2010年07月17日 13:19:31 | pitrou | set | priority: normal -> critical |
| 2010年07月17日 13:16:55 | djc | create | |