[Python-Dev] dir, part 2 (original) (raw)
tomer filiba tomerfiliba at gmail.com
Mon Nov 6 16:02:51 CET 2006
- Previous message: [Python-Dev] Status of pairing_heap.py?
- Next message: [Python-Dev] __dir__, part 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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: () builtin_dir calls PyObject_Dir 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:
() builtin_dir, if called without an argument, returns the frame's locals
() otherwise, it calls PyObject_Dir(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 PyObject_Dir does today)
() builtin_dir would take care of sorting the list returned by PyObject_Dir
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
- Previous message: [Python-Dev] Status of pairing_heap.py?
- Next message: [Python-Dev] __dir__, part 2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]