Author: Carl Friedrich Bolz <[email protected]>
Branch: list-strategies
Changeset: r47675:7a5ec2a053fd
Date: 2011-09-29 10:45 +0200
http://bitbucket.org/pypy/pypy/changeset/7a5ec2a053fd/
Log: start implementing the new is behaviour
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -445,12 +445,27 @@
return self.int_w(l_w[0]), self.int_w(l_w[1]), self.int_w(l_w[2])
def is_(self, w_one, w_two):
- if w_one is w_two:
- return self.w_True
- return self.w_False
+ return self.newbool(self.is_w(w_one, w_two))
- # short-cut
def is_w(self, w_one, w_two):
+ # cannot use self.is_w here to not get infinite recursion
+ w_typeone = self.type(w_one)
+ if w_typeone is self.w_int:
+ return (self.type(w_two) is self.w_int and
+ self.int_w(w_one) == self.int_w(w_two))
+ elif w_typeone is self.w_float:
+ return (self.type(w_two) is self.w_float and
+ self.float_w(w_one) == self.float_w(w_two))
+ elif w_typeone is self.w_long:
+ return (self.type(w_two) is self.w_long and
+ self.bigint_w(w_one).eq(self.bigint_w(w_two)))
+ # XXX complex?
+ elif w_typeone is self.w_str:
+ return (self.type(w_two) is self.w_str and
+ self.str_w(w_one) is self.str_w(w_two))
+ elif w_typeone is self.w_unicode:
+ return (self.type(w_two) is self.w_unicode and
+ self.unicode_w(w_one) is self.unicode_w(w_two))
return w_one is w_two
def is_true(self, w_obj):
diff --git a/pypy/objspace/std/test/test_obj.py
b/pypy/objspace/std/test/test_obj.py
--- a/pypy/objspace/std/test/test_obj.py
+++ b/pypy/objspace/std/test/test_obj.py
@@ -4,12 +4,18 @@
class AppTestObject:
def setup_class(cls):
+ from pypy.interpreter import gateway
import sys
cpython_behavior = (not option.runappdirect
or not hasattr(sys, 'pypy_translation_info'))
cls.w_cpython_behavior = cls.space.wrap(cpython_behavior)
cls.w_cpython_version = cls.space.wrap(tuple(sys.version_info))
+ space = cls.space
+
+ def w_unwrap_wrap_unicode(space, w_obj):
+ return space.wrap(space.unicode_w(w_obj))
+ cls.w_unwrap_wrap_unicode =
space.wrap(gateway.interp2app(w_unwrap_wrap_unicode))
def test_hash_builtin(self):
if not self.cpython_behavior:
@@ -102,3 +108,25 @@
def __repr__(self):
return 123456
assert A().__str__() == 123456
+
+ def test_object_identity(self):
+ assert 1 is 1
+ x = 1000000
+ assert x + 1 is int(str(x + 1))
+ assert 1 is not 1.0
+ assert 1 is not 1l
+ assert 1l is not 1.0
+ assert 1.1 is 1.1
+ for x in range(10):
+ assert x + 0.1 is x + 0.1
+ for x in range(10):
+ assert x + 1L is x + 1L
+ #for x in range(10):
+ # assert x+1j is x+1j
+ l = [1]
+ assert l[0] is l[0]
+ l = ["a"]
+ assert l[0] is l[0]
+ u = u"a"
+ assert self.unwrap_wrap_unicode(u) is u
+
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit