<html><head><style type="text/css" media="screen">Body{font-family: Verdana;font-size:.75em;}h4{font-size:.9em;}a{color: #3a62a6;}.digest .toc {margin-bottom: 15px; padding-bottom:8px; border-bottom: 1px solid #ccc;}.digest .tocItem {margin-bottom: 15px;}.tocItem a{color:#000;text-decoration: none;}.tocItem a:hover{color: #3a62a6;text-decoration: underline;}.topic{padding-bottom: 8px;margin-bottom: 20px; border-bottom: 1px solid #ccc;}.topicHeader{margin-bottom:10px;}.topicTitle{font-weight: bold;}.replies p{margin:0;padding:0;}.replies hr{width: 15%;text-align: left;margin: 0 auto 5px 0;border: none 0;border-top: 1px solid #ccc;height: 1px;}.reply{margin-bottom: 6px;padding-bottom: 4px;}.anchorMarker{color: #3a62a6;}.footer{color: gray;}</style></head><body><div class="digest"><p>Hi ironpython,</p><p>Here's your Daily Digest of new issues for project "<a href="http://ironpython.codeplex.com/">IronPython</a>".</p><p>In today's digest:</p><h4>ISSUES</h4><div class="toc"><div class="tocItem"><a href="#toc_issue_1">1. <span class="tocTitle">[New issue] IronPython ignores overridden TryUnaryOperation of DynamicObject that overrides TryUnaryOperation</span> <span class="anchorMarker">↓</span></a></div></div><h4>ISSUES</h4><div class="topic"><a name="toc_issue_1"></a><div class="topicHeader"><span class="topicTitle">1. [New issue] IronPython ignores overridden TryUnaryOperation of DynamicObject that overrides TryUnaryOperation</span> <a href="http://ironpython.codeplex.com/workitem/33978">view online</a></div><p>User Rauhotz has proposed the issue:</p><p>"IronPython (2.7.3) seems to not check the TryUnaryOperation with ExpressionType.IsFalse and ExpressionType.IsTrue for performing short-circuit evaluation of the logical AND and OR operations.<br />
<br />
Here's an example that uses a class that inherits from DynamicObject. In C#, it works perfectly, but produces a wrong result if used in an IronPython expression. Is that behavior expected or a bug? How can i get IronPython to behave the same way as C#?<br />
<br />
<strong>The class:</strong><br />
<pre><code>public class Dyn : DynamicObject
{
    private readonly string text;

    public Dyn(string text)
    {
        this.text = text;
    }

    public override string ToString()
    {
        return this.text;
    }

    public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
    {
        result = new Dyn(this + " " + binder.Operation + " " + arg);
        return true;
    }

    public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
    {
        switch (binder.Operation)
        {
            case ExpressionType.IsFalse:
            case ExpressionType.IsTrue:
                result = false;
                return true;
        }

        return base.TryUnaryOperation(binder, out result);
    }
}</code></pre>

<strong>The usage:</strong><br />
<pre><code>dynamic a = new Dyn("a");
dynamic b = new Dyn("b");
dynamic c = new Dyn("c");

var correct = a && b || c;

var engine = Python.CreateEngine();
var scope = engine.CreateScope();
scope.SetVariable("a", a);
scope.SetVariable("b", b);
scope.SetVariable("c", c);
var incorrect = engine.Execute("a and b or c", scope);

Console.WriteLine("Correct: " + correct);
Console.WriteLine("Incorrect: " + incorrect);</code></pre>

<strong>Prints:</strong><br />
<pre><code>Correct: a And b Or c
Incorrect: b</code><"</p></div><div class="footer"><p>You are receiving this email because you subscribed to notifications on CodePlex.</p><p>To report a bug, request a feature, or add a comment, visit <a href="http://ironpython.codeplex.com/workitem/list/basic">IronPython Issue Tracker</a>. You can <a href="http://ironpython.codeplex.com/subscriptions/workitem/project/edit">unsubscribe or change your issue notification settings</a> on CodePlex.com.</p></div></div></body></html>