[IronPython] Issues with Silly Module Tricks
Jeff Hardy
jdhardy at gmail.com
Wed Nov 28 04:40:23 CET 2007
Hi,
The following code is adapted from the Pygments library:
automod_test.py
import types
class _automodule(types.ModuleType):
"""Automatically import lexers."""
def __getattr__(self, name):
return "blah"
import sys
oldmod = sys.modules['automod_test']
newmod = _automodule('automod_test')
newmod.__dict__.update(oldmod.__dict__)
sys.modules['automod_test'] = newmod
del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types
When run, I get the following results:
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import automod_test
>>> automod_test.blah
'blah'
IronPython console: IronPython 2.0A6 (2.0.11102.00) on .NET 2.0.50727.312
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import automod_test
>>> automod_test.blah
Traceback (most recent call last):
File , line 0, in ##268
AttributeError: 'module' object has no attribute 'blah'
I'm not sure whether the issue is with replacing sys.modules, or if it
is related to the __getattr__ issues that were reported a while back.
Either way, it prevents Pygments from getting past even the first
round of tests.
-Jeff
More information about the Ironpython-users
mailing list