[Checkins] SVN: martian/trunk/ Fix a bug where passing in __builtin__ could lead to errors.

Martijn Faassen faassen at infrae.com
Tue Nov 20 07:00:05 EST 2007


Log message for revision 81940:
  Fix a bug where passing in __builtin__ could lead to errors.
  

Changed:
  U   martian/trunk/CHANGES.txt
  U   martian/trunk/src/martian/scan.py

-=-
Modified: martian/trunk/CHANGES.txt
===================================================================
--- martian/trunk/CHANGES.txt	2007-11-19 22:44:48 UTC (rev 81939)
+++ martian/trunk/CHANGES.txt	2007-11-20 12:00:03 UTC (rev 81940)
@@ -4,8 +4,16 @@
 0.9.2 (unreleased)
 ==================
 
-* ...
+Bug fixes
+---------
 
+* scan.module_info_from_dotted_name() now has special behavior when it
+  runs into __builtin__. Previously, it would crash with an error. Now
+  it will return an instance of BuiltinModuleInfo. This is a very
+  simple implementation which provides just enough information to make
+  client code work. Typically this client code is test-related so that
+  the module context will be __builtin__.
+
 0.9.1 (2007-10-30)
 ==================
 

Modified: martian/trunk/src/martian/scan.py
===================================================================
--- martian/trunk/src/martian/scan.py	2007-11-19 22:44:48 UTC (rev 81939)
+++ martian/trunk/src/martian/scan.py	2007-11-20 12:00:03 UTC (rev 81940)
@@ -124,8 +124,40 @@
     def __repr__(self):
         return "<ModuleInfo object for '%s'>" % self.dotted_name
 
+class BuiltinDummyModule(object):
+    """Needed for BuiltinModuleInfo"""
+    pass
 
+class BuiltinModuleInfo(object):
+    implements(IModuleInfo)
+
+    def getModule(self):
+        return BuiltinDummyModule()
+    
+    def isPackage(self):
+        return False
+
+    def getSubModuleInfos(self):
+        return []
+
+    def getSubModuleInfo(self, name):
+        return None
+
+    def getResourcePath(self, name):
+        # XXX we break the contract here. We could return
+        # a link to some temp directory for testing purposes?
+        return None
+    
+    def getAnnotation(self, key, default):
+        return default
+        
 def module_info_from_dotted_name(dotted_name, exclude_filter=None):
+    if dotted_name == '__builtin__':
+        # in case of the use of individually grokking something during a
+        # test the dotted_name being passed in could be __builtin__
+        # in this case we return a special ModuleInfo that just
+        # implements enough interface to work
+        return BuiltinModuleInfo()
     module = resolve(dotted_name)
     return ModuleInfo(module.__file__, dotted_name, exclude_filter)
 



More information about the Checkins mailing list