|
1 | 1 | use crossbeam_utils::atomic::AtomicCell;
|
2 |
| -use num_traits::ToPrimitive; |
3 | 2 | use std::fmt;
|
4 | 3 |
|
5 |
| -use super::objint::PyIntRef; |
6 | 4 | use super::objiter;
|
7 | 5 | use super::objtype::PyTypeRef;
|
8 | 6 | use crate::common::hash::PyHash;
|
| 7 | +use crate::function::OptionalArg; |
9 | 8 | use crate::pyobject::{
|
10 | 9 | self, BorrowValue, Either, IdProtocol, IntoPyObject, PyArithmaticValue, PyClassImpl,
|
11 |
| - PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, |
12 |
| - TypeProtocol, |
| 10 | + PyComparisonValue, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, |
13 | 11 | };
|
14 | 12 | use crate::sequence::{self, SimpleSeq};
|
15 | 13 | use crate::sliceable::PySliceableSequence;
|
16 | 14 | use crate::slots::{Comparable, Hashable, PyComparisonOp};
|
17 | 15 | use crate::vm::{ReprGuard, VirtualMachine};
|
18 |
| -use crate::{bytesinner::PyBytesInner, function::OptionalArg}; |
19 | 16 |
|
20 | 17 | /// tuple() -> empty tuple
|
21 | 18 | /// tuple(iterable) -> tuple initialized from iterable's items
|
@@ -69,25 +66,6 @@ impl PyTuple {
|
69 | 66 | pub(crate) fn fast_getitem(&self, idx: usize) -> PyObjectRef {
|
70 | 67 | self.elements[idx].clone()
|
71 | 68 | }
|
72 |
| - |
73 |
| - // TODO: more generic way to do so |
74 |
| - pub(crate) fn to_bytes_inner(&self, vm: &VirtualMachine) -> PyResult<PyBytesInner> { |
75 |
| - let mut elements = Vec::<u8>::with_capacity(self.borrow_value().len()); |
76 |
| - for elem in self.borrow_value().iter() { |
77 |
| - let py_int = PyIntRef::try_from_object(vm, elem.clone()).map_err(|_| { |
78 |
| - vm.new_type_error(format!( |
79 |
| - "'{}' object cannot be interpreted as an integer", |
80 |
| - elem.class().name |
81 |
| - )) |
82 |
| - })?; |
83 |
| - let result = py_int |
84 |
| - .borrow_value() |
85 |
| - .to_u8() |
86 |
| - .ok_or_else(|| vm.new_value_error("bytes must be in range (0, 256)".to_owned()))?; |
87 |
| - elements.push(result); |
88 |
| - } |
89 |
| - Ok(elements.into()) |
90 |
| - } |
91 | 69 | }
|
92 | 70 |
|
93 | 71 | pub type PyTupleRef = PyRef<PyTuple>;
|
|
0 commit comments