Commit add17cc3 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Wow, I did not think that descriptors would apply here

parent 85501a49
...@@ -402,7 +402,10 @@ extern "C" Box* sliceNew(Box* cls, Box* start, Box* stop, Box** args) { ...@@ -402,7 +402,10 @@ extern "C" Box* sliceNew(Box* cls, Box* start, Box* stop, Box** args) {
} }
Box* instancemethodRepr(BoxedInstanceMethod* self) { Box* instancemethodRepr(BoxedInstanceMethod* self) {
return boxStrConstant("<bound instancemethod object>"); if (self->obj)
return boxStrConstant("<bound instancemethod object>");
else
return boxStrConstant("<unbound instancemethod object>");
} }
Box* sliceRepr(BoxedSlice* self) { Box* sliceRepr(BoxedSlice* self) {
......
...@@ -4,21 +4,25 @@ ...@@ -4,21 +4,25 @@
# Descriptors get processed when fetched as part of a dunder lookup # Descriptors get processed when fetched as part of a dunder lookup
class D(object): class D(object):
def __init__(self, n):
self.n = n
def __get__(self, obj, cls): def __get__(self, obj, cls):
print "__get__()", obj is None print "__get__()", obj is None, self.n
def desc(): def desc(*args):
print "desc()" print "desc()", len(args)
return 1 return self.n
return desc return desc
def __call__(self): def __call__(self):
print "D.call" print "D.call"
return 2 return self.n
class C(object): class C(object):
__hash__ = D() __hash__ = D(1)
__add__ = D(2)
c = C() c = C()
print C.__hash__() print C.__hash__()
print c.__hash__() print c.__hash__()
print hash(c) print hash(c)
print c + c
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment