◐ Shell
clean mode source ↗

PyWrapperDescrObject and rewrite toggle_slot by youknowone · Pull Request #6536 · RustPython/RustPython

/// Extract the raw function pointer from a SlotFunc if it matches this accessor's type pub fn extract_from_slot_func(&self, slot_func: &SlotFunc) -> bool { match self { // Type slots Self::TpHash => matches!(slot_func, SlotFunc::Hash(_)), Self::TpRepr => matches!(slot_func, SlotFunc::Repr(_)), Self::TpStr => matches!(slot_func, SlotFunc::Str(_)), Self::TpCall => matches!(slot_func, SlotFunc::Call(_)), Self::TpIter => matches!(slot_func, SlotFunc::Iter(_)), Self::TpIternext => matches!(slot_func, SlotFunc::IterNext(_)), Self::TpInit => matches!(slot_func, SlotFunc::Init(_)), Self::TpDel => matches!(slot_func, SlotFunc::Del(_)), Self::TpGetattro => matches!(slot_func, SlotFunc::GetAttro(_)), Self::TpSetattro => { matches!(slot_func, SlotFunc::SetAttro(_) | SlotFunc::DelAttro(_)) } Self::TpDescrGet => matches!(slot_func, SlotFunc::DescrGet(_)), Self::TpDescrSet => { matches!(slot_func, SlotFunc::DescrSet(_) | SlotFunc::DescrDel(_)) } Self::TpRichcompare => matches!(slot_func, SlotFunc::RichCompare(_, _)),
// Number - Power (ternary) Self::NbPower | Self::NbInplacePower => { matches!(slot_func, SlotFunc::NumTernary(_)) } // Number - Boolean Self::NbBool => matches!(slot_func, SlotFunc::NumBoolean(_)), // Number - Unary Self::NbNegative | Self::NbPositive | Self::NbAbsolute | Self::NbInvert | Self::NbInt | Self::NbFloat | Self::NbIndex => matches!(slot_func, SlotFunc::NumUnary(_)), // Number - Binary Self::NbAdd | Self::NbSubtract | Self::NbMultiply | Self::NbRemainder | Self::NbDivmod | Self::NbLshift | Self::NbRshift | Self::NbAnd | Self::NbXor | Self::NbOr | Self::NbFloorDivide | Self::NbTrueDivide | Self::NbMatrixMultiply | Self::NbInplaceAdd | Self::NbInplaceSubtract | Self::NbInplaceMultiply | Self::NbInplaceRemainder | Self::NbInplaceLshift | Self::NbInplaceRshift | Self::NbInplaceAnd | Self::NbInplaceXor | Self::NbInplaceOr | Self::NbInplaceFloorDivide | Self::NbInplaceTrueDivide | Self::NbInplaceMatrixMultiply => matches!(slot_func, SlotFunc::NumBinary(_)),
// Sequence Self::SqLength => matches!(slot_func, SlotFunc::SeqLength(_)), Self::SqConcat | Self::SqInplaceConcat => matches!(slot_func, SlotFunc::SeqConcat(_)), Self::SqRepeat | Self::SqInplaceRepeat => matches!(slot_func, SlotFunc::SeqRepeat(_)), Self::SqItem => matches!(slot_func, SlotFunc::SeqItem(_)), Self::SqAssItem => matches!(slot_func, SlotFunc::SeqAssItem(_)), Self::SqContains => matches!(slot_func, SlotFunc::SeqContains(_)),
// Mapping Self::MpLength => matches!(slot_func, SlotFunc::MapLength(_)), Self::MpSubscript => matches!(slot_func, SlotFunc::MapSubscript(_)), Self::MpAssSubscript => matches!(slot_func, SlotFunc::MapAssSubscript(_)),
// New and reserved slots Self::TpNew => false, _ => false, // Reserved slots } }