Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Boolean evaluation #23

Closed
ccaapton opened this issue Aug 2, 2024 · 5 comments
Closed

Incorrect Boolean evaluation #23

ccaapton opened this issue Aug 2, 2024 · 5 comments

Comments

@ccaapton
Copy link

ccaapton commented Aug 2, 2024

The result of below code evaluation should be true, but it returns False instead.

from plusminus import BaseArithmeticParser

parser = BaseArithmeticParser()
parser.evaluate('False or False or True')
@ptmcg
Copy link
Member

ptmcg commented Aug 2, 2024

Sure enough! I had tried to implement short-circuiting logic. Better to use Python's any and all builtins instead.

@ptmcg
Copy link
Member

ptmcg commented Aug 2, 2024

I have a working fix - are you doing more testing, or do you need it immediately and I'll push out 0.8.1?

@ccaapton
Copy link
Author

ccaapton commented Aug 3, 2024

I have a working fix - are you doing more testing, or do you need it immediately and I'll push out 0.8.1?

I wrote something like below, works for this test case, but not sure if good for all. Can you give me the fix as well?

class MyBinaryLogicalOr(BinaryLogicalOperator):
    opns_map = {
        "||": operator.or_
    }
    def left_associative_evaluate(self, oper_fn_map):
        with _trimming_exception_traceback():
            last = bool(self.tokens[0].evaluate())
            ret = False
            for oper, operand in zip(self.tokens[1::2], self.tokens[2::2]):
                next_ = bool(operand.evaluate())
                ret = ret or oper_fn_map[oper](last, next_)
                if ret:
                    return ret
                last = next_
            return ret

@ptmcg
Copy link
Member

ptmcg commented Aug 3, 2024

I just uploaded the fixed version to pypi, version 0.8.1

@ptmcg
Copy link
Member

ptmcg commented Aug 3, 2024

Fixed in version 0.8.1

@ptmcg ptmcg closed this as completed Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants