Skip to content

Commit bce8b54

Browse files
authored
Get pip working again (#1532)
1 parent 4a11332 commit bce8b54

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Src/IronPython/Runtime/Bytes.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,10 @@ public IEnumerator<byte> GetEnumerator() {
11631163
#region IEnumerable Members
11641164

11651165
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
1166+
// workaround for https://github.com/IronLanguages/ironpython3/issues/1519
1167+
if (GetType() != typeof(Bytes) && PythonTypeOps.TryInvokeUnaryOperator(DefaultContext.Default, this, "__iter__", out object? iter)) {
1168+
return new PythonEnumerator(iter);
1169+
}
11661170
return _bytes.GetEnumerator();
11671171
}
11681172

Tests/test_iterator.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,22 @@ def test_discarded_indexer_reduces_empty(self):
306306
with self.assertRaises(StopIteration):
307307
it.__next__()
308308

309+
def test_loop_over_iterable_bytes_subclass(self):
310+
# part of https://github.com/IronLanguages/ironpython3/issues/1519
311+
312+
data = list(range(3))
313+
class test(bytes):
314+
def __iter__(self):
315+
return iter(data)
316+
317+
# enumerate with for loop
318+
res = []
319+
for x in test():
320+
res.append(x)
321+
322+
self.assertEqual(res, data)
323+
324+
# enumerate with list
325+
self.assertEqual(list(test()), data)
326+
309327
run_test(__name__)

0 commit comments

Comments
 (0)