Skip to content

Commit dd773b3

Browse files
author
Young
committed
Support tuple type also for memoryview shape arg
1 parent 3f2bab6 commit dd773b3

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

Lib/test/test_base64.py

-23
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def test_decodestring_warns(self):
2626
with self.assertWarns(DeprecationWarning):
2727
base64.decodestring(b"d3d3LnB5dGhvbi5vcmc=\n")
2828

29-
# TODO: RUSTPYTHON
30-
@unittest.expectedFailure
3129
def test_encodebytes(self):
3230
eq = self.assertEqual
3331
eq(base64.encodebytes(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=\n")
@@ -47,8 +45,6 @@ def test_encodebytes(self):
4745
eq(base64.encodebytes(array('B', b'abc')), b'YWJj\n')
4846
self.check_type_errors(base64.encodebytes)
4947

50-
# TODO: RUSTPYTHON
51-
@unittest.expectedFailure
5248
def test_decodebytes(self):
5349
eq = self.assertEqual
5450
eq(base64.decodebytes(b"d3d3LnB5dGhvbi5vcmc=\n"), b"www.python.org")
@@ -133,9 +129,6 @@ def check_nonbyte_element_format(self, f, data):
133129
int_data = memoryview(bytes_data).cast('I')
134130
self.assertEqual(f(int_data), f(bytes_data))
135131

136-
137-
# TODO: RUSTPYTHON
138-
@unittest.expectedFailure
139132
def test_b64encode(self):
140133
eq = self.assertEqual
141134
# Test default alphabet
@@ -186,8 +179,6 @@ def test_b64encode(self):
186179
b'\xd3V\xbeo\xf7\x1d', b'01a-b_cd')
187180
self.check_encode_type_errors(base64.urlsafe_b64encode)
188181

189-
# TODO: RUSTPYTHON
190-
@unittest.expectedFailure
191182
def test_b64decode(self):
192183
eq = self.assertEqual
193184

@@ -284,8 +275,6 @@ def test_b64decode_invalid_chars(self):
284275
self.assertEqual(base64.b64decode(b'++[[//]]', b'[]'), res)
285276
self.assertEqual(base64.urlsafe_b64decode(b'++--//__'), res)
286277

287-
# TODO: RUSTPYTHON
288-
@unittest.expectedFailure
289278
def test_b32encode(self):
290279
eq = self.assertEqual
291280
eq(base64.b32encode(b''), b'')
@@ -299,8 +288,6 @@ def test_b32encode(self):
299288
self.check_other_types(base64.b32encode, b'abcd', b'MFRGGZA=')
300289
self.check_encode_type_errors(base64.b32encode)
301290

302-
# TODO: RUSTPYTHON
303-
@unittest.expectedFailure
304291
def test_b32decode(self):
305292
eq = self.assertEqual
306293
tests = {b'': b'',
@@ -375,8 +362,6 @@ def test_b32decode_error(self):
375362
with self.assertRaises(binascii.Error):
376363
base64.b32decode(data.decode('ascii'))
377364

378-
# TODO: RUSTPYTHON
379-
@unittest.expectedFailure
380365
def test_b16encode(self):
381366
eq = self.assertEqual
382367
eq(base64.b16encode(b'\x01\x02\xab\xcd\xef'), b'0102ABCDEF')
@@ -415,8 +400,6 @@ def test_b16decode(self):
415400
# Incorrect "padding"
416401
self.assertRaises(binascii.Error, base64.b16decode, '010')
417402

418-
# TODO: RUSTPYTHON
419-
@unittest.expectedFailure
420403
def test_a85encode(self):
421404
eq = self.assertEqual
422405

@@ -467,8 +450,6 @@ def test_a85encode(self):
467450
eq(base64.a85encode(b' '*6, foldspaces=True, adobe=False), b'y+<U')
468451
eq(base64.a85encode(b' '*5, foldspaces=True, adobe=False), b'y+9')
469452

470-
# TODO: RUSTPYTHON
471-
@unittest.expectedFailure
472453
def test_b85encode(self):
473454
eq = self.assertEqual
474455

@@ -503,8 +484,6 @@ def test_b85encode(self):
503484
self.check_other_types(base64.b85encode, b"www.python.org",
504485
b'cXxL#aCvlSZ*DGca%T')
505486

506-
# TODO: RUSTPYTHON
507-
@unittest.expectedFailure
508487
def test_a85decode(self):
509488
eq = self.assertEqual
510489

@@ -550,8 +529,6 @@ def test_a85decode(self):
550529
self.check_other_types(base64.a85decode, b'GB\\6`E-ZP=Df.1GEb>',
551530
b"www.python.org")
552531

553-
# TODO: RUSTPYTHON
554-
@unittest.expectedFailure
555532
def test_b85decode(self):
556533
eq = self.assertEqual
557534

vm/src/builtins/memory.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{
2-
PyBytes, PyBytesRef, PyInt, PyListRef, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef, PyTypeRef,
2+
PyBytes, PyBytesRef, PyInt, PyList, PyListRef, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef,
3+
PyTypeRef,
34
};
45
use crate::common::{
56
borrow::{BorrowedValue, BorrowedValueMut},
@@ -629,6 +630,16 @@ impl PyMemoryView {
629630
));
630631
}
631632

633+
let tup = shape.payload_if_subclass::<PyTuple>(vm);
634+
let list = shape.payload_if_subclass::<PyList>(vm);
635+
636+
let l = tup.map(|t| PyList::from(t.as_slice().iter().cloned().collect_vec()));
637+
let list_from_tuple = l.as_ref();
638+
639+
let shape = list.xor(list_from_tuple).ok_or_else(|| {
640+
vm.new_type_error("memoryview: must be a list or a tuple".to_owned())
641+
})?;
642+
632643
let shape_vec = shape.borrow_vec();
633644
let shape_ndim = shape_vec.len();
634645
// TODO: MAX_NDIM
@@ -865,7 +876,7 @@ struct CastArgs {
865876
#[pyarg(any)]
866877
format: PyStrRef,
867878
#[pyarg(any, optional)]
868-
shape: OptionalArg<PyListRef>,
879+
shape: OptionalArg<PyObjectRef>,
869880
}
870881

871882
enum SubscriptNeedle {

0 commit comments

Comments
 (0)