Created
May 17, 2017 21:46
-
-
Save milesrout/6f016f1058a93f5fb67d0aef8ae83bef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
class Dedent: | |
@classmethod | |
def method(cls, f=None, *, name=None): | |
def decorator(f): | |
setattr(cls, name if name is not None else f.__name__, f) | |
if f is not None: | |
decorator(f) | |
else: | |
return decorator | |
class Point(Dedent): | |
pass | |
@Point.method | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
@Point.method(name='__matmul__') | |
def dot(p, q): | |
return p.x * q.x + p.y * q.y | |
print(Point(1, 1) @ Point(1, -1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment