]> granicus.if.org Git - python/commitdiff
When __slots__ are set to a unicode string, make it work the same as
authorNeal Norwitz <nnorwitz@gmail.com>
Sat, 14 Apr 2007 05:25:50 +0000 (05:25 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sat, 14 Apr 2007 05:25:50 +0000 (05:25 +0000)
setting a plain string, ie don't expand to single letter identifiers.

Lib/test/test_descr.py
Misc/NEWS
Objects/typeobject.c

index 41c0bdf968f5a943d7ed58e5545bec5951b4f701..eda96a6bd9991eead57f1794c6e5fd434d474956 100644 (file)
@@ -1225,13 +1225,29 @@ def slots():
         raise TestFailed, "[''] slots not caught"
     class C(object):
         __slots__ = ["a", "a_b", "_a", "A0123456789Z"]
+    # XXX(nnorwitz): was there supposed to be something tested
+    # from the class above?
+
+    # Test a single string is not expanded as a sequence.
+    class C(object):
+        __slots__ = "abc"
+    c = C()
+    c.abc = 5
+    vereq(c.abc, 5)
 
     # Test unicode slot names
     try:
-        unichr
+        unicode
     except NameError:
         pass
     else:
+        # Test a single unicode string is not expanded as a sequence.
+        class C(object):
+            __slots__ = unicode("abc")
+        c = C()
+        c.abc = 5
+        vereq(c.abc, 5)
+
         # _unicode_to_string used to modify slots in certain circumstances 
         slots = (unicode("foo"), unicode("bar"))
         class C(object):
index db0c8dc41caa1b2402c574c1007c48450b4f7408..b84d0b555a137ba235df8eb305f780a9eba3b345 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
 Core and builtins
 -----------------
 
+- When __slots__ are set to a unicode string, make it work the same as 
+  setting a plain string, ie don't expand to single letter identifiers.
+
 - Request #1191699:  Slices can now be pickled.
 
 - Request #1193128:  str.translate() now allows a None argument for
index 0ce7f8286148477a35029ed5bfb36f65342d71fa..285bd67fccd24a7c575eb82b7c51aaee2236062e 100644 (file)
@@ -1816,7 +1816,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
                /* Have slots */
 
                /* Make it into a tuple */
-               if (PyString_Check(slots))
+               if (PyString_Check(slots) || PyUnicode_Check(slots))
                        slots = PyTuple_Pack(1, slots);
                else
                        slots = PySequence_Tuple(slots);