[pypy-svn] pypy default: CPython doesn't allow assigning to threading.local.__dict__, now neither do we. This paves the way for making __dict__ a jit.loop_invariant.

alex_gaynor commits-noreply at bitbucket.org
Mon Jan 17 22:16:16 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r40819:147d075532d7
Date: 2011-01-17 15:15 -0600
http://bitbucket.org/pypy/pypy/changeset/147d075532d7/

Log:	CPython doesn't allow assigning to threading.local.__dict__, now
	neither do we. This paves the way for making __dict__ a
	jit.loop_invariant.

diff --git a/pypy/module/thread/os_local.py b/pypy/module/thread/os_local.py
--- a/pypy/module/thread/os_local.py
+++ b/pypy/module/thread/os_local.py
@@ -38,14 +38,6 @@
             space.threadlocals.atthreadexit(space, finish_thread, self)
         return w_dict
 
-    def setdict(self, space, w_dict):
-        if not space.is_true(space.isinstance(w_dict, space.w_dict)):
-            raise OperationError(space.w_TypeError,
-                                space.wrap("setting dictionary to a non-dict"))
-        self.getdict()   # force a dict to exist first
-        ident = thread.get_ident()
-        self.dicts[ident] = w_dict
-
     def descr_local__new__(space, w_subtype, __args__):
         local = space.allocate_instance(Local, w_subtype)
         Local.__init__(local, space, __args__)
@@ -61,8 +53,7 @@
                         __doc__ = "Thread-local data",
                         __new__ = interp2app(Local.descr_local__new__.im_func),
                         __init__ = interp2app(Local.descr_local__init__),
-                        __dict__ = GetSetProperty(descr_get_dict,
-                                                  descr_set_dict, cls=Local),
+                        __dict__ = GetSetProperty(descr_get_dict, cls=Local),
                         )
 
 def getlocaltype(space):

diff --git a/pypy/module/thread/test/test_local.py b/pypy/module/thread/test/test_local.py
--- a/pypy/module/thread/test/test_local.py
+++ b/pypy/module/thread/test/test_local.py
@@ -74,14 +74,14 @@
     def test_local_setdict(self):
         import thread
         x = thread._local()
+        # XXX: On Cpython these are AttributeErrors
         raises(TypeError, "x.__dict__ = 42")
+        raises(TypeError, "x.__dict__ = {}")
+
         done = []
         def f(n):
             x.spam = n
             assert x.__dict__["spam"] == n
-            x.__dict__ = {"bar": n+1}
-            assert x.bar == n+1
-            assert not hasattr(x, "spam")
             done.append(1)
         for i in range(5):
             thread.start_new_thread(f, (i,))


More information about the Pypy-commit mailing list