r47061 - use type() instead
hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Thu, 24 Mar 2016 02:08:36 -0600 (MDT)
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Thu Mar 24 02:08:24 2016
New Revision: 47061
Modified:
branches/oldstyle-decorator-8244/twisted/python/_oldstyle.py
branches/oldstyle-decorator-8244/twisted/test/test_nooldstyle.py
Log:
use type() instead
Modified: branches/oldstyle-decorator-8244/twisted/python/_oldstyle.py
==============================================================================
--- branches/oldstyle-decorator-8244/twisted/python/_oldstyle.py (original)
+++ branches/oldstyle-decorator-8244/twisted/python/_oldstyle.py Thu Mar 24 02:08:24 2016
@@ -72,10 +72,5 @@
"""
_ensureOldClass(cls)
- class OverwrittenClass(cls, object):
- __doc__ = cls.__doc__
-
- OverwrittenClass.__name__ = cls.__name__
- OverwrittenClass.__module__ = cls.__module__
-
+ OverwrittenClass = type(cls.__name__, (object,), cls.__dict__)
return OverwrittenClass
Modified: branches/oldstyle-decorator-8244/twisted/test/test_nooldstyle.py
==============================================================================
--- branches/oldstyle-decorator-8244/twisted/test/test_nooldstyle.py (original)
+++ branches/oldstyle-decorator-8244/twisted/test/test_nooldstyle.py Thu Mar 24 02:08:24 2016
@@ -30,6 +30,10 @@
"""
I am a docstring!
"""
+ bar = "baz"
+
+ def func(self):
+ return "hi"
@@ -48,12 +52,13 @@
def test_makesNewStyle(self):
"""
L{_oldStyle} wraps an old-style class and returns a new-style class
- that descends from the old-style one.
+ that has the same functions, attributes, etc.
"""
self.assertEqual(type(SomeOldStyleClass), types.ClassType)
updatedClass = _oldStyle(SomeOldStyleClass)
self.assertEqual(type(updatedClass), type)
- self.assertIn(SomeOldStyleClass, updatedClass.__bases__)
+ self.assertEqual(updatedClass().func(), "hi")
+ self.assertEqual(updatedClass().bar, "baz")
def test_carriesAttributes(self):