summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenrick Everett <31653115+Kenrick0@users.noreply.github.com>2022-06-21 16:18:12 +1000
committerGitHub <noreply@github.com>2022-06-21 07:18:12 +0100
commitc416c7cb2159cc43f9461d96721aeaaa8f9f4714 (patch)
tree05874ec7153e372d558cf94a5a4b7b102479eb58
parenta7d98eeafac9aaaa8825fd471be38172ee0b259c (diff)
downloadcython-c416c7cb2159cc43f9461d96721aeaaa8f9f4714.tar.gz
Fix bytearray iteration in 0.29.x (#4108)
By explicitly setting the result type
-rw-r--r--Cython/Compiler/ExprNodes.py4
-rw-r--r--tests/run/bytearray_iter.py15
2 files changed, 19 insertions, 0 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index 9162eaad9..4a8ce5dca 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -2876,6 +2876,10 @@ class NextNode(AtomicExprNode):
iterator_type = self.iterator.infer_type(env)
if iterator_type.is_ptr or iterator_type.is_array:
return iterator_type.base_type
+ elif self.iterator.sequence.type is bytearray_type:
+ # This is a temporary work-around to fix bytearray iteration in 0.29.x
+ # It has been fixed properly in master, refer to ticket: 3473
+ return py_object_type
elif iterator_type.is_cpp_class:
item_type = env.lookup_operator_for_types(self.pos, "*", [iterator_type]).type.return_type
if item_type.is_reference:
diff --git a/tests/run/bytearray_iter.py b/tests/run/bytearray_iter.py
new file mode 100644
index 000000000..4beb8e285
--- /dev/null
+++ b/tests/run/bytearray_iter.py
@@ -0,0 +1,15 @@
+# mode: run
+# ticket: 3473
+
+def test_bytearray_iteration(src):
+ """
+ >>> src = b'123'
+ >>> test_bytearray_iteration(src)
+ 49
+ 50
+ 51
+ """
+
+ data = bytearray(src)
+ for elem in data:
+ print(elem)