summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@canonical.com>2023-03-02 13:43:00 +0000
committerGitHub <noreply@github.com>2023-03-02 13:43:00 +0000
commit27ee700bdd906c130daf17cbeb53ca028f870319 (patch)
tree4fbb97495929739991ecf1ec51a59ed6b8ab77e8
parente34cc5bcf73493d63ff62b1ef681b9bc4305428f (diff)
parent66d0c3d72b7066783762218c7e6b4c933d275a30 (diff)
downloadzope-security-27ee700bdd906c130daf17cbeb53ca028f870319.tar.gz
Merge pull request #95 from cjwatson/pep-3114
Use PEP 3114 __next__ methods
-rw-r--r--CHANGES.rst4
-rw-r--r--src/zope/security/_proxy.c6
-rw-r--r--src/zope/security/proxy.py1
-rw-r--r--src/zope/security/tests/test_checker.py2
-rw-r--r--src/zope/security/tests/test_proxy.py9
5 files changed, 12 insertions, 10 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 7391d96..7d9d8b3 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -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)
================
diff --git a/src/zope/security/_proxy.c b/src/zope/security/_proxy.c
index 6d9f298..d38eaeb 100644
--- a/src/zope/security/_proxy.c
+++ b/src/zope/security/_proxy.c
@@ -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);
@@ -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);
@@ -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);
diff --git a/src/zope/security/proxy.py b/src/zope/security/proxy.py
index 8b7ebf5..66a4cb7 100644
--- a/src/zope/security/proxy.py
+++ b/src/zope/security/proxy.py
@@ -274,7 +274,6 @@ for name in ['__call__',
'__delitem__',
'__iter__',
'__next__',
- 'next',
'__contains__',
'__neg__',
'__pos__',
diff --git a/src/zope/security/tests/test_checker.py b/src/zope/security/tests/test_checker.py
index a0ee8bd..22e9a1e 100644
--- a/src/zope/security/tests/test_checker.py
+++ b/src/zope/security/tests/test_checker.py
@@ -586,8 +586,6 @@ class CheckerTestsBase(QuietWatchingChecker):
finally:
self.index += 1
- next = __next__
-
def __length_hint__(self):
self.hint_called = True
return self.hint
diff --git a/src/zope/security/tests/test_proxy.py b/src/zope/security/tests/test_proxy.py
index 38126fc..90e9fc3 100644
--- a/src/zope/security/tests/test_proxy.py
+++ b/src/zope/security/tests/test_proxy.py
@@ -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):
@@ -1535,7 +1537,6 @@ class Something:
def __next__(self):
return 42 # Infinite sequence
- next = __next__
def __len__(self):
return 42
@@ -1651,10 +1652,10 @@ class ProxyFactoryTests(unittest.TestCase):
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))