-
Notifications
You must be signed in to change notification settings - Fork 66
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 unary operators #237
Fix unary operators #237
Conversation
Likewise, the above applies for |
@lyskov If you have a suggestion as to how to make the To be clear, I change
The issue is that dummy int C++ post-increment operator requires is taken literally by binder so |
@zwimer thank you for reporting this! Re proposed solution: i thought about this and have rather mixed feeling about it: technically it possible to provide value for this dummy parameter (and for operator to use it) (see https://en.cppreference.com/w/cpp/language/operator_incdec). So why it might be more "pythonic" to avoid user to specify it, it in the same time disallow us to fully use the C++ code. Of course we could probably all agree that using this dummy int as parameter in C++ code is probably a bad idea in the first place... but as usual in such cases when we disallow such usage it will break someone workflow. (btw this point is nicely illustrate in https://xkcd.com/1172/) |
@lyskov I think I was unclear. Right now, if you bind both
This PR changes that to
I think it would be beneficial to somehow instead do:
That is to say. Currently in python we have: My problem is that I do not know how to go from what this PR does to the better solution of not requiring a dummy argument in the first place. While I do think the current PR is better than what is on master, if it is an easy fix to make this other improvement, I think that is best. Thoughts? |
Oh, no, I think I see your point. Hmm, is it possible / a good idea to let that be a CLI flag? Or bind both? |
-- let me think about this. Right now my take is that both naming ( |
@lyskov For now I'll split this into 2 PRs. One that just fixes the bugs, and one that does this renaming. |
|
||
{"operator->", "arrow"}, // | ||
}; | ||
// Return the python operator that maps to the C++ operator; returns "" if no mapping exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please update comments, particularly elaborate on how selection of correct name from the vector will be correlated to number of arguments C++ operator have? Thanks,
source/function.cpp
Outdated
if (vec.size() == 1) { return vec[0]; } | ||
const auto n = F.getNumParams(); | ||
if (vec.size() > n) { | ||
return vec[n]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered approach:
const auto n = F.getNumParams();
return n < vec.size() ? vec[n] : vec.back();
- that way operators with non-standard type signature (more then two arguments, operator with default arguments) will also be bound and could be used in Python by calling corresponding magic-method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will work as well, before if you wanted a catch all you would just put it as the sole argument but I can update it to this. I don't think it would make a difference since I don't recall C++ allowing additional operator parameters besides the ones I coded, but I suppose this is safer in case I missed anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! - Thank you for putting this together @zwimer !
This fixes: #225
It also addresses #226 by renaming
plus_plus
topre_increment
orpost_increment
depending on which is called. It unfortunately does not fix the issue that the post increment operator requires an integer argument. I'm not sure how to fix that. If this is not ok, I can undo this fix and only let this PR address #225