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) {
}
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) {
......
......@@ -4,21 +4,25 @@
# Descriptors get processed when fetched as part of a dunder lookup
class D(object):
def __init__(self, n):
self.n = n
def __get__(self, obj, cls):
print "__get__()", obj is None
def desc():
print "desc()"
return 1
print "__get__()", obj is None, self.n
def desc(*args):
print "desc()", len(args)
return self.n
return desc
def __call__(self):
print "D.call"
return 2
return self.n
class C(object):
__hash__ = D()
__hash__ = D(1)
__add__ = D(2)
c = C()
print C.__hash__()
print c.__hash__()
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