Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit463b516

Browse files
authored
Implement number protocol forPyBytes (#3903)
1 parentdb6fd16 commit463b516

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

‎vm/src/builtins/bytes.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use crate::{
1313
function::Either,
1414
function::{ArgBytesLike,ArgIterable,OptionalArg,OptionalOption,PyComparisonValue},
1515
protocol::{
16-
BufferDescriptor,BufferMethods,PyBuffer,PyIterReturn,PyMappingMethods,
16+
BufferDescriptor,BufferMethods,PyBuffer,PyIterReturn,PyMappingMethods,PyNumberMethods,
1717
PySequenceMethods,
1818
},
1919
sliceable::{SequenceIndex,SliceableSequenceOp},
2020
types::{
21-
AsBuffer,AsMapping,AsSequence,Callable,Comparable,Constructor,Hashable,IterNext,
22-
IterNextIterable,Iterable,PyComparisonOp,Unconstructible,
21+
AsBuffer,AsMapping,AsNumber,AsSequence,Callable,Comparable,Constructor,Hashable,
22+
IterNext,IterNextIterable,Iterable,PyComparisonOp,Unconstructible,
2323
},
2424
AsObject,Context,Py,PyObject,PyObjectRef,PyPayload,PyRef,PyResult,
2525
TryFromBorrowedObject,TryFromObject,VirtualMachine,
@@ -108,7 +108,8 @@ impl PyBytes {
108108
Comparable,
109109
AsBuffer,
110110
Iterable,
111-
Constructor
111+
Constructor,
112+
AsNumber
112113
)
113114
)]
114115
implPyBytes{
@@ -606,6 +607,17 @@ impl AsSequence for PyBytes {
606607
};
607608
}
608609

610+
implAsNumberforPyBytes{
611+
constAS_NUMBER:PyNumberMethods =PyNumberMethods{
612+
remainder:Some(|number, other, vm|{
613+
Self::number_downcast(number)
614+
.mod_(other.to_owned(), vm)
615+
.to_pyresult(vm)
616+
}),
617+
..PyNumberMethods::NOT_IMPLEMENTED
618+
};
619+
}
620+
609621
implHashableforPyBytes{
610622
#[inline]
611623
fnhash(zelf:&crate::Py<Self>,vm:&VirtualMachine) ->PyResult<PyHash>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp