summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-04-30 15:39:57 -0400
committerBenjamin Peterson <benjamin@python.org>2014-04-30 15:39:57 -0400
commit0421377397d459303640325911dc672b699434f3 (patch)
treef1fc7782554187ffa6d955422b2db1a1dd0ff1c2
parente290bb4c84e25bd4642e7c902ff2731b0e91a1ba (diff)
parent4cb424949c41729ca8556851a66b124f02f247f1 (diff)
downloadsix-0421377397d459303640325911dc672b699434f3.tar.gz
Merged in harlowja/six (pull request #32)
Add a wraps helper
-rw-r--r--CHANGES7
-rw-r--r--CONTRIBUTORS2
-rw-r--r--documentation/index.rst6
-rw-r--r--six.py19
-rw-r--r--test_six.py1
5 files changed, 34 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 5489adc..d9a2bf1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,13 @@ This file lists the changes in each six version.
Development version
-------------------
+- Pull request #35: Improve add_metaclass, so that it doesn't end up inserting
+ another class into the hierarchy.
+
+- Pull request #34: Add import mappings for dummy_thread.
+
+- Pull request #33: Add import mappings for UserDict and UserList.
+
- Pull request #31: Select the implementations of dictionary iterator routines
at import time for a 20% speed boost.
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index c828a3d..67d1d8c 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -8,10 +8,12 @@ Ned Batchelder
Jason R. Coombs
Julien Danjou
Ben Darnell
+Ben Davis
Alexander Lukanin
James Mills
Sridhar Ratnakumar
Erik Rose
+Peter Ruibal
Miroslav Shubernetskiy
If you think you belong on this list, please let me know! --Benjamin
diff --git a/documentation/index.rst b/documentation/index.rst
index 3d7828b..4f0a08e 100644
--- a/documentation/index.rst
+++ b/documentation/index.rst
@@ -477,6 +477,8 @@ Supported renames:
+------------------------------+-------------------------------------+-------------------------------------+
| ``dbm_gnu`` | :func:`py2:gdbm` | :class:`py3:dbm.gnu` |
+------------------------------+-------------------------------------+-------------------------------------+
+| ``_dummy_thread`` | :mod:`py2:dummy_thread` | :mod:`py3:_dummy_thread` |
++------------------------------+-------------------------------------+-------------------------------------+
| ``email_mime_multipart`` | :mod:`py2:email.MIMEMultipart` | :mod:`py3:email.mime.multipart` |
+------------------------------+-------------------------------------+-------------------------------------+
| ``email_mime_text`` | :mod:`py2:email.MIMEText` | :mod:`py3:email.mime.text` |
@@ -563,6 +565,10 @@ Supported renames:
+------------------------------+-------------------------------------+-------------------------------------+
| ``urllib_robotparser`` | :mod:`py2:robotparser` | :mod:`py3:urllib.robotparser` |
+------------------------------+-------------------------------------+-------------------------------------+
+| ``UserDict`` | :class:`py2:UserDict.UserDict` | :class:`py3:collections.UserDict` |
++------------------------------+-------------------------------------+-------------------------------------+
+| ``UserList`` | :class:`py2:UserList.UserList` | :class:`py3:collections.UserList` |
++------------------------------+-------------------------------------+-------------------------------------+
| ``UserString`` | :class:`py2:UserString.UserString` | :class:`py3:collections.UserString` |
+------------------------------+-------------------------------------+-------------------------------------+
| ``winreg`` | :mod:`py2:_winreg` | :mod:`py3:winreg` |
diff --git a/six.py b/six.py
index 56a64d0..a417a8d 100644
--- a/six.py
+++ b/six.py
@@ -186,6 +186,8 @@ _moved_attributes = [
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("StringIO", "StringIO", "io"),
+ MovedAttribute("UserDict", "UserDict", "collections"),
+ MovedAttribute("UserList", "UserList", "collections"),
MovedAttribute("UserString", "UserString", "collections"),
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
@@ -195,6 +197,7 @@ _moved_attributes = [
MovedModule("configparser", "ConfigParser"),
MovedModule("copyreg", "copy_reg"),
MovedModule("dbm_gnu", "gdbm", "dbm.gnu"),
+ MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread"),
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
MovedModule("http_cookies", "Cookie", "http.cookies"),
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
@@ -644,7 +647,21 @@ else:
def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
- return meta("NewBase", bases, {})
+ # This requires a bit of explanation: the basic idea is to make a
+ # dummy metaclass for one level of class instantiation that replaces
+ # itself with the actual metaclass. Because of internal type checks
+ # we also need to make sure that we downgrade the custom metaclass
+ # for one level to something closer to type (that's why __call__ and
+ # __init__ comes back from type etc.).
+ class metaclass(meta):
+ __call__ = type.__call__
+ __init__ = type.__init__
+ def __new__(cls, name, this_bases, d):
+ if this_bases is None:
+ return type.__new__(cls, name, (), d)
+ return meta(name, bases, d)
+ return metaclass('temporary_class', None, {})
+
def add_metaclass(metaclass):
"""Class decorator for creating a class with a metaclass."""
diff --git a/test_six.py b/test_six.py
index 371ee81..a520a83 100644
--- a/test_six.py
+++ b/test_six.py
@@ -634,6 +634,7 @@ def test_with_metaclass():
assert type(X) is Meta
assert issubclass(X, Base)
assert issubclass(X, Base2)
+ assert X.__mro__ == (X, Base, Base2, object)
def test_wraps():