Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r47724:298dc7122a7f Date: 2011-09-30 14:06 -0400 http://bitbucket.org/pypy/pypy/changeset/298dc7122a7f/
Log: list.pop should call __int__ on its argument. diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py --- a/pypy/objspace/std/listobject.py +++ b/pypy/objspace/std/listobject.py @@ -386,7 +386,11 @@ if len(items)== 0: raise OperationError(space.w_IndexError, space.wrap("pop from empty list")) - idx = space.int_w(w_idx) + if space.isinstance_w(w_idx, space.w_float): + raise OperationError(space.w_TypeError, + space.wrap("integer argument expected, got float") + ) + idx = space.int_w(space.int(w_idx)) try: return items.pop(idx) except IndexError: diff --git a/pypy/objspace/std/test/test_listobject.py b/pypy/objspace/std/test/test_listobject.py --- a/pypy/objspace/std/test/test_listobject.py +++ b/pypy/objspace/std/test/test_listobject.py @@ -705,6 +705,20 @@ l.pop() assert l == range(9) + def test_pop_custom_int(self): + class A(object): + def __init__(self, x): + self.x = x + + def __int__(self): + return self.x + + l = range(10) + x = l.pop(A(-1)) + assert x == 9 + assert l == range(9) + raises(TypeError, range(10).pop, 1.0) + def test_remove(self): c = list('hello world') c.remove('l') _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit