Commits

Alex Gaynor committed 8d941ba

Fix a silly type from 2 years ago. Maintain string identity in {set,get,del}attr when calling __{set,get,del}attr__.

Comments (0)

Files changed (2)

pypy/module/__builtin__/operation.py

     # space.{get,set,del}attr()...
     # Note that if w_name is already a string (or a subclass of str),
     # it must be returned unmodified (and not e.g. unwrapped-rewrapped).
-    if not space.is_true(space.is_(w_name, space.w_str)):
+    if not space.is_w(space.type(w_name), space.w_str):
         name = space.str_w(w_name)    # typecheck
         w_name = space.wrap(name)     # rewrap as a real string
     return w_name
                             the sentinal.
 """
     if w_sentinel is None:
-        return space.iter(w_collection_or_callable) 
+        return space.iter(w_collection_or_callable)
     else:
         return iter_sentinel(space, w_collection_or_callable, w_sentinel)
 

pypy/objspace/std/test/test_dictmultiobject.py

         w_d = space.newdict(from_strdict_shared=d)
         assert self.space.eq_w(space.getitem(w_d, w("a")), w(1))
         assert self.space.eq_w(space.getitem(w_d, w("b")), w(2))
-        
+
     def test_initialize_from_strdict_really_shared(self):
         space = self.space
         w = space.wrap
         cls.w_on_pypy = cls.space.wrap("__pypy__" in sys.builtin_module_names)
 
     def test_equality(self):
-        d = {1:2} 
-        f = {1:2} 
+        d = {1:2}
+        f = {1:2}
         assert d == f
         assert d != {1:3}
 
         d = {1:2, 3:4}
         d.clear()
         assert len(d) == 0
-                         
+
     def test_copy(self):
         d = {1:2, 3:4}
         dd = d.copy()
         assert d == dd
         assert not d is dd
-        
+
     def test_get(self):
         d = {1:2, 3:4}
         assert d.get(1) == 2
         assert result == 44
         assert len(dd) == 1
         raises(KeyError, dd.pop, 33)
-    
+
     def test_has_key(self):
         d = {1:2, 3:4}
         assert d.has_key(1)
         assert not d.has_key(33)
-    
+
     def test_items(self):
         d = {1:2, 3:4}
         its = d.items()
         its.sort()
         assert its == [(1,2),(3,4)]
-    
+
     def test_iteritems(self):
         d = {1:2, 3:4}
         dd = d.copy()
             assert v == dd[k]
             del dd[k]
         assert not dd
-    
+
     def test_iterkeys(self):
         d = {1:2, 3:4}
         dd = d.copy()
         for k in d.iterkeys():
             del dd[k]
         assert not dd
-    
+
     def test_itervalues(self):
         d = {1:2, 3:4}
         values = []
         for k in d.itervalues():
             values.append(k)
         assert values == d.values()
-    
+
     def test_keys(self):
         d = {1:2, 3:4}
         kys = d.keys()
         kys.sort()
         assert kys == [1,3]
-    
+
     def test_popitem(self):
         d = {1:2, 3:4}
         it = d.popitem()
         d = dict(a=33, b=44)
         assert d == {'a':33, 'b':44}
         d = dict({'a':33, 'b':44})
-        assert d == {'a':33, 'b':44}        
+        assert d == {'a':33, 'b':44}
         try: d = dict(23)
         except (TypeError, ValueError): pass
         else: self.fail("dict(23) should raise!")
         assert d3['x'] == 42
         assert d3['y'] == 42
 
-    def test_overridden_setitem_customkey(self):        
+    def test_overridden_setitem_customkey(self):
         class D(dict):
             def __setitem__(self, key, value):
                 dict.__setitem__(self, key, 42)
                 assert v1 == v2
             else:
                 assert False, 'Expected KeyError'
-        
+
     def test_del_keyerror_unpacking(self):
         d = {}
         for v1 in ['Q', (1,)]:
         setattr(a, s, 42)
         key = a.__dict__.keys()[0]
         assert key == s
+        assert key is not s
         assert type(key) is str
         assert getattr(a, s) == 42
 
+    def test_setattr_string_identify(self):
+        attrs = []
+        class A(object):
+            def __setattr__(self, attr, value):
+                attrs.append(attr)
+
+        a = A()
+        s = "abc"
+        setattr(a, s, 123)
+        assert attrs[0] is s
+
 class AppTestDictViews:
     def test_dictview(self):
         d = {1: 2, 3: 4}