[pypy-commit] pypy stdlib-2.7.12: a2d8b4680ef9 for old style classes: pass thru numeric subclasses
pjenvey
pypy.commits at gmail.com
Mon Oct 3 00:26:21 EDT 2016
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: stdlib-2.7.12
Changeset: r87535:72df4e872a46
Date: 2016-10-02 21:24 -0700
http://bitbucket.org/pypy/pypy/changeset/72df4e872a46/
Log: a2d8b4680ef9 for old style classes: pass thru numeric subclasses
returned from __trunc__
diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -571,6 +571,9 @@
return space.call_function(w_func)
w_truncated = space.trunc(self)
+ if (space.isinstance_w(w_truncated, space.w_int) or
+ space.isinstance_w(w_truncated, space.w_long)):
+ return w_truncated
# int() needs to return an int
try:
return space.int(w_truncated)
diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -502,12 +502,15 @@
assert int(TruncReturnsNonInt()) == 42
def test_trunc_returns_int_subclass(self):
- class TruncReturnsNonInt(object):
- def __trunc__(self):
- return True
- n = int(TruncReturnsNonInt())
- assert n == 1
- assert type(n) is bool
+ class Classic:
+ pass
+ for base in object, Classic:
+ class TruncReturnsNonInt(base):
+ def __trunc__(self):
+ return True
+ n = int(TruncReturnsNonInt())
+ assert n == 1
+ assert type(n) is bool
def test_int_before_string(self):
class Integral(str):
More information about the pypy-commit
mailing list