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

Fix "flip" of arguments in relational expressions #30

Merged
merged 3 commits into from
Jan 22, 2016
Merged

Conversation

skirpichev
Copy link
Collaborator

see sympy/sympy#7951 and https://bugs.python.org/issue22052

  • verbose commit messages
  • better docstring for BaseSymbol (i.e. document why we need this)

This fixes "flip" of arguments in relational expressions,
mentioned in the issue sympy/sympy#7951.

The docs says [1] (see also [2]) about relational ops:
There are no swapped-argument versions of these methods (to be used when
the left argument does not support the operation but the right argument
does); rather, __lt__() and __gt__() are each other’s reflection,
__le__() and __ge__() are each other’s reflection, and __eq__() and
__ne__() are their own reflection.  If the operands are of different
types, and right operand’s type is a direct or indirect subclass of the
left operand’s type, the reflected method of the right operand has
priority, otherwise the left operand’s method has priority.

So, if B is a subclass of A, we can't avoid calling the "reflected"
method.  For example, A() < B() will be silently transformed to
B() > A().  Only know workaround per se - avoid subclassing of "public"
classes.  For example, old class hierarchy for symbols is forbidden:

                    Symbol
                   /      \
                 Dummy    Wild

In this patch, common base class for symbols was implemented.

References
==========

.. [1] https://docs.python.org/3.5/reference/datamodel.html#object.__lt__
.. [2] https://bugs.python.org/issue22052
.. [3] sympy/sympy#7951
skirpichev added a commit that referenced this pull request Jan 22, 2016
Fix "flip" of arguments in relational expressions
@skirpichev skirpichev merged commit dc859ac into master Jan 22, 2016
@skirpichev skirpichev deleted the rel-flip branch January 22, 2016 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant