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

Allow operator definition syntax to be used for Python operators #675

Open
evhub opened this issue Oct 6, 2022 · 1 comment
Open

Allow operator definition syntax to be used for Python operators #675

evhub opened this issue Oct 6, 2022 · 1 comment
Labels

Comments

@evhub
Copy link
Owner

evhub commented Oct 6, 2022

Should compile

class A:
    def a + b: ...

to

class A:
    def __add__(a, b): ...
@evhub evhub added the feature label Oct 6, 2022
@evhub evhub added this to the v2.1.0 milestone Oct 6, 2022
@evhub evhub removed this from the v2.1.0 milestone Oct 15, 2022
@yggdr
Copy link

yggdr commented Apr 16, 2023

Would that be made to interoperate with custom operators? Would, in a definition like

operator ~~
def left ~~ right = dostuff(right) - dostuff(left)
class A:
    def left ~~ right: dostuff(right) - left._optimised_dostuff()

the operator defining function (line 2; or rather what it gets compiled down to) be able to first check for the existence of the operator method on left (and then maybe the i-method on right, however that would work syntactically) and call that before falling back to the generic function? Would that maybe even work without line 2, such that there would always be the default operator implementation that checks for such operator methods on its operands, and raises an Exception otherwise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants