[pypy-svn] r34957 - in pypy/dist/pypy: interpreter interpreter/test module/__builtin__
arigo at codespeak.net
arigo at codespeak.net
Sat Nov 25 13:57:13 CET 2006
Author: arigo
Date: Sat Nov 25 13:57:11 2006
New Revision: 34957
Modified:
pypy/dist/pypy/interpreter/mixedmodule.py
pypy/dist/pypy/interpreter/test/test_py.py
pypy/dist/pypy/module/__builtin__/__init__.py
Log:
Don't put a __file__ attribute in the __builtin__ module. This causes
all modules that don't otherwise have a __file__ (like __main__) to
believe their file is pypy/module/__builtin__/*.py.
Modified: pypy/dist/pypy/interpreter/mixedmodule.py
==============================================================================
--- pypy/dist/pypy/interpreter/mixedmodule.py (original)
+++ pypy/dist/pypy/interpreter/mixedmodule.py Sat Nov 25 13:57:11 2006
@@ -12,6 +12,7 @@
NOT_RPYTHON_ATTRIBUTES = ['loaders']
applevel_name = None
+ expose__file__attribute = True
def __init__(self, space, w_name):
""" NOT_RPYTHON """
@@ -84,7 +85,8 @@
for name, spec in cls.appleveldefs.items():
loaders[name] = getappfileloader(pkgroot, spec)
assert '__file__' not in loaders
- loaders['__file__'] = cls.get__file__
+ if cls.expose__file__attribute:
+ loaders['__file__'] = cls.get__file__
if '__doc__' not in loaders:
loaders['__doc__'] = cls.get__doc__
Modified: pypy/dist/pypy/interpreter/test/test_py.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_py.py (original)
+++ pypy/dist/pypy/interpreter/test/test_py.py Sat Nov 25 13:57:11 2006
@@ -91,3 +91,16 @@
pass
assert e," expected failure"
assert e.err.splitlines()[-1] == 'KeyError: <normalized>'
+
+
+def test_no__file__in_main():
+ tmpfilepath = udir.join("test_py_script.py")
+ tmpfilepath.write(str(py.code.Source("""
+ try:
+ print __file__
+ except NameError:
+ print 'no __file__.'
+ """)))
+ output = py.process.cmdexec( '''"%s" "%s" "%s" ''' %
+ (sys.executable, pypypath, tmpfilepath) )
+ assert 'no __file__.\n' in output
Modified: pypy/dist/pypy/module/__builtin__/__init__.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/__init__.py (original)
+++ pypy/dist/pypy/module/__builtin__/__init__.py Sat Nov 25 13:57:11 2006
@@ -4,6 +4,7 @@
class Module(MixedModule):
"""Built-in functions, exceptions, and other objects."""
+ expose__file__attribute = False
appleveldefs = {
'quit' : 'app_help.exit',
More information about the Pypy-commit
mailing list