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
Custom sorting key for substitute( ) #67
Conversation
…or elements in Multiset.
I think adding some global state is not a good idea, I would prefer changing the signature of the def substitute(expression: Union[Expression, Pattern], substitution: Substitution, sort_key=None: Optional[Callable[[Expression], Any]]) -> Replacement:
... That way the behavior of the function remains pure and does not depend on some global state. |
@Upabjojr I switch the build from Travis CI to Github Actions. If you rebase your changes, the pipeline should work better :) |
I am not very convinced about adding a parameter to Ideally after calling Otherwise, would about editing the |
What if you put a |
Well, that would solve the problem if users import Notice that redefining |
Isn't that a better approach then anyways? Relying on and modifying a private variable from outside is against Python conventions and seems like a very brittle solution. An alternative would be to have setter/getter for that global state, even though I would still prefer to make it explicit when calling the function.. |
…tom sorting of multiset elements.
Thank you for your contribution! 🎉👍 |
Substitute now accepts custom sorting key to specify custom sorting for elements in Multiset.
This should solve the compatibility problem with SymPy which does not allow comparison operators (
>
,>=
,<
,<=
) to be evaluated to booleans if the truth of the expression cannot be easily determined.