/// <summary> /// Special equals because none of the special cases in Ops.Equals /// are applicable here, and the reference equality check breaks some tests. /// </summary> private static bool RefEquals(object x, object y, IEqualityComparer comparer) { CodeContext context; if (comparer != null && comparer is PythonContext.PythonEqualityComparer) { context = ((PythonContext.PythonEqualityComparer)comparer).Context.SharedContext; } else { context = DefaultContext.Default; } object ret; if (PythonTypeOps.TryInvokeBinaryOperator(context, x, y, "__eq__", out ret) && ret != NotImplementedType.Value) { return((bool)ret); } if (PythonTypeOps.TryInvokeBinaryOperator(context, y, x, "__eq__", out ret) && ret != NotImplementedType.Value) { return((bool)ret); } if (comparer != null) { return(comparer.Equals(x, y)); } return(x.Equals(y)); }
private static bool IsLessThan(CodeContext /*!*/ context, object x, object y) { object ret; if (PythonTypeOps.TryInvokeBinaryOperator(context, x, y, "__lt__", out ret) && !Object.ReferenceEquals(ret, NotImplementedType.Value)) { return(Converter.ConvertToBoolean(ret)); } else if (PythonTypeOps.TryInvokeBinaryOperator(context, y, x, "__le__", out ret) && !Object.ReferenceEquals(ret, NotImplementedType.Value)) { return(!Converter.ConvertToBoolean(ret)); } else { return(context.LanguageContext.LessThan(x, y)); } }
public bool TryGetValue(object key, out object value) { if (_storage.TryGetValue(key, out value)) { return(true); } // we need to manually look up a slot to get the correct behavior when // the __missing__ function is declared on a sub-type which is an old-class if (GetType() != typeof(PythonDictionary) && PythonTypeOps.TryInvokeBinaryOperator(DefaultContext.Default, this, key, "__missing__", out value)) { return(true); } return(false); }