Skip to content

Commit

Permalink
Merge pull request #95 from cjwatson/pep-3114
Browse files Browse the repository at this point in the history
Use PEP 3114 __next__ methods
  • Loading branch information
cjwatson committed Mar 2, 2023
2 parents e34cc5b + 66d0c3d commit 27ee700
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
6.2 (unreleased)
----------------

- Make ``next()`` on C proxies call ``__next__`` rather than ``next`` (see
PEP 3114), and drop support for the Python 2 ``next`` method name from
pure-Python proxies.


6.1 (2023-01-18)
================
Expand Down
6 changes: 3 additions & 3 deletions src/zope/security/_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ DECLARE_STRING(__getitem__);
DECLARE_STRING(__hash__);
DECLARE_STRING(__iter__);
DECLARE_STRING(__len__);
DECLARE_STRING(next);
DECLARE_STRING(__next__);
DECLARE_STRING(op_abs);
DECLARE_STRING(op_add);
DECLARE_STRING(op_and);
Expand Down Expand Up @@ -351,7 +351,7 @@ proxy_iternext(SecurityProxy *self)
{
PyObject *result = NULL;

if (check(self, str_check_getattr, str_next) >= 0)
if (check(self, str_check_getattr, str___next__) >= 0)
{
result = PyIter_Next(self->proxy.proxy_object);
PROXY_RESULT(self, result);
Expand Down Expand Up @@ -878,7 +878,7 @@ if((str_op_##S = INTERN("__" #S "__")) == NULL) return MOD_ERROR_VAL
INIT_STRING(__hash__);
INIT_STRING(__iter__);
INIT_STRING(__len__);
INIT_STRING(next);
INIT_STRING(__next__);
INIT_STRING_OP(abs);
INIT_STRING_OP(add);
INIT_STRING_OP(and);
Expand Down
1 change: 0 additions & 1 deletion src/zope/security/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ def __repr__(self):
'__delitem__',
'__iter__',
'__next__',
'next',
'__contains__',
'__neg__',
'__pos__',
Expand Down
2 changes: 0 additions & 2 deletions src/zope/security/tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,6 @@ def __next__(self):
finally:
self.index += 1

next = __next__

def __length_hint__(self):
self.hint_called = True
return self.hint
Expand Down
9 changes: 5 additions & 4 deletions src/zope/security/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,9 @@ class Checker:
unproxied_types = {str, }

def check_getattr(self, _object, name):
if name not in ("foo", "next", "__class__", "__name__", "__module__"):
if name in ("__class__", "__name__", "__module__"):
return
if not self.ok or name not in ("__next__", "foo"):
raise RuntimeError

def check_setattr(self, _object, name):
Expand Down Expand Up @@ -1535,7 +1537,6 @@ def __iter__(self):

def __next__(self):
return 42 # Infinite sequence
next = __next__

def __len__(self):
return 42
Expand Down Expand Up @@ -1651,10 +1652,10 @@ def testIterFail(self):
self.shouldFail(iter, self.p)

def testNextOK(self):
self.assertEqual(self.p.next(), 42)
self.assertEqual(next(self.p), 42)

def testNextFail(self):
self.shouldFail(self.p.next)
self.shouldFail(next, self.p)

def testHashOK(self):
self.assertEqual(hash(self.p), hash(self.x))
Expand Down

0 comments on commit 27ee700

Please sign in to comment.