Neal Norwitz schrieb: > I assume this is not the desired behaviour? > >>>> class F: > ... def __dir__(self): > ... return [5] > ... >>>> dir(F()) > [5] >>>> f = F() >>>> dir(f) > [5] >>>> def __dir__(): return [10] > ... >>>> f.__dir__ = __dir__ >>>> dir(f) > [5] > > I think the problem is in _dir_object() > > + PyObject * dirfunc = PyObject_GetAttrString((PyObject*)obj->ob_type, > + "__dir__"); > > Shouldn't the first arg just be obj, not obj->ob_type?
This is modeled after the principle that for new-style objects, __special__ methods are looked up on the type, not the instance. > I also wanted to point out that in the example below__dir__() is > returning non-strings. Is that ok, even though attributes must be > strings? Yes, I have already put an XXX in the code asking if the returned list should be checked for string-only entries. I wasn't sure whether it is worth the effort. >> +" for an other object: its attributes, its class's attributes, and\n" >> +" recursively the attributes of its class's base classes."); > > 'for an other object' should that be for *any* other object? There > might have been other stuff, this patch was too hard to read. Fixed, thanks. Georg _______________________________________________ Python-3000-checkins mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000-checkins
