[py-svn] py-trunk commit d699a5f29cdd: tentative fix to py3's dependency on a filename->module->__loader__ chain
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri May 14 23:24:24 CEST 2010
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User holger krekel <holger at merlinux.eu>
# Date 1273872387 -7200
# Node ID d699a5f29cdd04524f985568303a6918aaa5df8c
# Parent 0ce74aa42bd80db92d719b148df719497e9ab247
tentative fix to py3's dependency on a filename->module->__loader__ chain
for executing inspect.findsource ...
--- a/py/_code/source.py
+++ b/py/_code/source.py
@@ -2,6 +2,7 @@ from __future__ import generators
import sys
import inspect, tokenize
import py
+from types import ModuleType
cpy_compile = compile
try:
@@ -212,8 +213,15 @@ class Source(object):
else:
if flag & _AST_FLAG:
return co
- from types import ModuleType
lines = [(x + "\n") for x in self.lines]
+ if sys.version_info[0] >= 3:
+ # XXX py3's inspect.getsourcefile() checks for a module
+ # and a pep302 __loader__ ... we don't have a module
+ # at code compile-time so we need to fake it here
+ m = ModuleType("_pycodecompile_pseudo_module")
+ py.std.inspect.modulesbyfile[filename] = None
+ py.std.sys.modules[None] = m
+ m.__loader__ = 1
py.std.linecache.cache[filename] = (1, None, lines, filename)
return co
More information about the pytest-commit
mailing list