Commits

holger krekel committed c5f9906

fix issue1 - make py.error.* instances pickleable

  • Participants
  • Parent commits 9e9f978

Comments (0)

Files changed (4)

 Changes between 1.4.0 and 1.4.1
 ==================================================
 
+- fix issue1 - py.error.* classes to be pickleable
+
 - fix (pytest-) issue10 and refine assertion reinterpretation
   to avoid breaking if the __nonzero__ of an object fails
 
 
 from py import _apipkg
 
+# so that py.error.* instances are picklable
+import sys
+sys.modules['py.error'] = _apipkg.AliasModule("py.error", "py._error", 'error')
+
 _apipkg.initpkg(__name__, attr={'_apipkg': _apipkg}, exportdefs={
     # access to all standard lib modules
     'std': '._std:std',
     },
 
 })
+
 import sys
 from types import ModuleType
 
-__version__ = '1.2.dev5'
+__version__ = '1.2.dev6'
 
 def initpkg(pkgname, exportdefs, attr=dict()):
     """ initialize given package from the export definitions. """
     __dict__ = property(__dict__)
 
 
-def AliasModule(modname, modpath):
+def AliasModule(modname, modpath, attrname=None):
     mod = []
 
     def getmod():
         if not mod:
-            mod.append(importobj(modpath, None))
+            x = importobj(modpath, None)
+            if attrname is not None:
+                x = getattr(x, attrname)
+            mod.append(x)
         return mod[0]
 
     class AliasModule(ModuleType):
 
         def __repr__(self):
-            return '<AliasModule %r for %r>' % (modname, modpath)
+            x = modpath
+            if attrname:
+                x += "." + attrname
+            return '<AliasModule %r for %r>' % (modname, x)
 
         def __getattribute__(self, name):
             return getattr(getmod(), name)

testing/root/test_error.py

         assert issubclass(x, py.error.Error)
         assert issubclass(x, EnvironmentError)
 
+def test_picklability_issue1():
+    e1 = py.error.ENOENT()
+    s = py.std.pickle.dumps(e1)
+    e2 = py.std.pickle.loads(s)
+    assert isinstance(e2, py.error.ENOENT)
+
 def test_unknown_error():
     num = 3999
     cls = py.error._geterrnoclass(num)