@@ -10,12 +10,12 @@ use crate::{
1010 convert:: { ToPyObject , TransmuteFromObject } ,
1111 function:: { ArgSize , FuncArgs , OptionalArg , PyArithmeticValue , PyComparisonValue } ,
1212 iter:: PyExactSizeIterator ,
13- protocol:: { PyIterReturn , PyMappingMethods , PySequenceMethods } ,
13+ protocol:: { PyIterReturn , PyMappingMethods , PyNumberMethods , PySequenceMethods } ,
1414 recursion:: ReprGuard ,
1515 sequence:: { OptionalRangeArgs , SequenceExt } ,
1616 sliceable:: { SequenceIndex , SliceableSequenceOp } ,
1717 types:: {
18- AsMapping , AsSequence , Comparable , Constructor , Hashable , IterNext , Iterable ,
18+ AsMapping , AsNumber , AsSequence , Comparable , Constructor , Hashable , IterNext , Iterable ,
1919 PyComparisonOp , Representable , SelfIter ,
2020 } ,
2121 utils:: collection_repr,
@@ -260,7 +260,7 @@ impl<T> PyTuple<PyRef<T>> {
260260#[ pyclass(
261261 itemsize = core:: mem:: size_of:: <crate :: PyObjectRef >( ) ,
262262 flags( BASETYPE , SEQUENCE , _MATCH_SELF) ,
263- with( AsMapping , AsSequence , Hashable , Comparable , Iterable , Constructor , Representable )
263+ with( AsMapping , AsNumber , AsSequence , Hashable , Comparable , Iterable , Constructor , Representable )
264264) ]
265265impl PyTuple {
266266 #[ pymethod]
@@ -286,11 +286,6 @@ impl PyTuple {
286286 PyArithmeticValue :: from_option ( added. ok ( ) )
287287 }
288288
289- #[ pymethod]
290- const fn __bool__ ( & self ) -> bool {
291- !self . elements . is_empty ( )
292- }
293-
294289 #[ pymethod]
295290 fn count ( & self , needle : PyObjectRef , vm : & VirtualMachine ) -> PyResult < usize > {
296291 let mut count: usize = 0 ;
@@ -423,6 +418,19 @@ impl AsSequence for PyTuple {
423418 }
424419}
425420
421+ impl AsNumber for PyTuple {
422+ fn as_number ( ) -> & ' static PyNumberMethods {
423+ static AS_NUMBER : PyNumberMethods = PyNumberMethods {
424+ boolean : Some ( |number, _vm| {
425+ let zelf = number. obj . downcast_ref :: < PyTuple > ( ) . unwrap ( ) ;
426+ Ok ( !zelf. elements . is_empty ( ) )
427+ } ) ,
428+ ..PyNumberMethods :: NOT_IMPLEMENTED
429+ } ;
430+ & AS_NUMBER
431+ }
432+ }
433+
426434impl Hashable for PyTuple {
427435 #[ inline]
428436 fn hash ( zelf : & Py < Self > , vm : & VirtualMachine ) -> PyResult < PyHash > {
0 commit comments