[Python-3000-checkins] r54265 - in python/branches/p3yk: Doc/lib/libfuncs.tex Lib/test/test_builtin.py Misc/NEWS Objects/object.c Python/bltinmodule.c
Neal Norwitz
nnorwitz at gmail.com
Tue Mar 13 06:52:16 CET 2007
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?
> Modified: python/branches/p3yk/Python/bltinmodule.c
> ==============================================================================
> --- python/branches/p3yk/Python/bltinmodule.c (original)
> +++ python/branches/p3yk/Python/bltinmodule.c Sat Mar 10 23:13:27 2007
> @@ -427,15 +427,16 @@
> PyDoc_STRVAR(dir_doc,
> "dir([object]) -> list of strings\n"
> "\n"
> -"Return an alphabetized list of names comprising (some of) the attributes\n"
> -"of the given object, and of attributes reachable from it:\n"
> -"\n"
> -"No argument: the names in the current scope.\n"
> -"Module object: the module attributes.\n"
> -"Type or class object: its attributes, and recursively the attributes of\n"
> -" its bases.\n"
> -"Otherwise: its attributes, its class's attributes, and recursively the\n"
> -" attributes of its class's base classes.");
> +"If called without an argument, return the names in the current scope.\n"
> +"Else, return an alphabetized list of names comprising (some of) the attributes\n"
> +"of the given object, and of attributes reachable from it.\n"
> +"If the object supplies a method named __dir__, it will be used; otherwise\n"
> +"the default dir() logic is used and returns:\n"
> +" for a module object: the module's attributes.\n"
> +" for a class object: its attributes, and recursively the attributes\n"
> +" of its bases.\n"
> +" 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.
n
More information about the Python-3000-checkins
mailing list