private object GetIndex(CodeContext context, object index) { if (index is string strIndex) { PythonTypeSlot dts; if (_dt.TryLookupSlot(context, strIndex, out dts)) { if (dts is PythonTypeUserDescriptorSlot uds) { return(uds.Value); } return(dts); } } throw PythonOps.KeyError(index.ToString()); }
private bool TryLookupInBase(CodeContext context, PythonType pt, string name, object self, out object value) { PythonTypeSlot dts; if (pt.OldClass == null) { // new-style class, or reflected type, lookup slot if (pt.TryLookupSlot(context, name, out dts) && dts.TryGetValue(context, self, DescriptorContext, out value)) { return true; } } else { // old-style class, lookup attribute OldClass dt = pt.OldClass; if (PythonOps.TryGetBoundAttr(context, dt, name, out value)) { value = OldClass.GetOldStyleDescriptor(context, value, self, DescriptorContext); return true; } } value = null; return false; }
private static bool LookupValue(PythonType dt, object instance, SymbolId name, out object value) { PythonTypeSlot dts; if (dt.TryLookupSlot(DefaultContext.Default, name, out dts) && dts.TryGetValue(DefaultContext.Default, instance, dt, out value)) { return true; } value = null; return false; }
public static object Get__doc__(CodeContext/*!*/ context, PythonType self) { PythonTypeSlot pts; object res; if (self.TryLookupSlot(context, Symbols.Doc, out pts) && pts.TryGetValue(context, null, self, out res)) { return res; } else if (self.IsSystemType) { return PythonTypeOps.GetDocumentation(self.UnderlyingSystemType); } return null; }