[Python-3000] __special__ attrs looked up on the type, not instance
Neal Norwitz
nnorwitz at gmail.com
Wed Mar 14 04:19:23 CET 2007
---------- Forwarded message from python-3000-checkins ----------
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?
[Georg]
This is modeled after the principle that for new-style objects, __special__
methods are looked up on the type, not the instance.
-----
1) I didn't remember this, do we have it documented somewhere?
2) Assuming #1 is correct, is this rule consistently applied?
3) How does (should) this affect 2.6 and migration to 3.0, if at all?
n
More information about the Python-3000
mailing list