[Python-Dev] dir, part 2 (original) (raw)

Guido van Rossum guido at python.org
Mon Nov 6 17:07:07 CET 2006


Sounds like a good plan, though I'm not sure if it's worth doing in 2.6 -- I'd be happy with doing this just in 3k.

I'm not sure what you mean by "adding a method slot" -- certainly it's possible to define a method foo and call it directly without having a special tp_foo in the type object, and I recommend doing it that way since the tp_foo slots are just there to make things fast; in this case I don't see a need for dir() to be fast.

--Guido

On 11/6/06, tomer filiba <tomerfiliba at gmail.com> wrote:

so, if you remember, i suggested adding dir to objects, so as to make dir() customizable, remove the deprecated methods and members, and make it symmetrical to other built-in functions.

you can see the original post here: http://mail.python.org/pipermail/python-dev/2006-July/067095.html which was generally accepted by the forum: http://mail.python.org/pipermail/python-dev/2006-July/067139.html so i went on, now that i have some spare time, to research the issue. the current dir() works as follows: (*) builtindir calls PyObjectDir to do the trick (*) if the object is NULL (dir with no argument), return the frame's locals (*) if the object is a module, we're just using it's dict (*) if the object is a type, we're using it's dict and bases, but not class (so as not to show the metaclass) (*) otherwise, it's a "normal object", so we take it's dict, along with methods, members, and dir(class) (*) create a list of keys from the dict, sort, return we'll have to change that if we were to introduce dir. my design is: (*) builtindir, if called without an argument, returns the frame's locals (*) otherwise, it calls PyObjectDir(self), which would dispatch self.dir() (*) if self doesn't have dir, default to object.dir(self) (*) the default object.dir implementation would do the same as today: collect dict, members, methods, and dir(class). by py3k, we'll remove looking into methods and members. (*) type objects and module objects would implement dir to their liking (as PyObjectDir does today) (*) builtindir would take care of sorting the list returned by PyObjectDir so first i'd want you people to react on my design, maybe you'd find flaws whatever. also, should this become a PEP? and last, how do i add a new method slot? does it mean i need to change all type-object definitions throughout the codebase? do i add it to some protocol? or directly to the "object protocol"?

-tomer


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list