[Python-Dev] introducing dir? (original) (raw)
tomer filiba tomerfiliba at gmail.com
Thu Jul 6 19:22:51 CEST 2006
- Previous message: [Python-Dev] what can we do to hide the 'file' type?
- Next message: [Python-Dev] introducing __dir__?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
i'd guess this has been brought up before, but i'm not aware of it.
anyway -- by what i've gathered, today's dir() "collects" the attributes of the object from dict, methods, members, and ultimately class. also, if i understood correctly, methods and members are deprecated. moreover, they are sequence objects, rather than callbale functions. that means my code can't
my suggestion is simple -- replace this mechanism with a dir - a special method that returns the list of attributes of the object.
rationale:
- remove deprecated methods, etc.
- symmetry -- just like hex() calls hex, etc.
- methods and members are lists rather than callable objects, which means they cannot be updated on-demand
and the reason for bringing this up in the first place -- allowing proxy objects to show the attributes of the internal object. for example, in rpyc, i had to override builtin.dir to achieve this functionallity, which is of course not the optimal sollution.
implementation: very straight forward and similar to the rest of the special methods:
- dir() - returns the current scope
- dir(obj) - retuns obj.dir(); if the object does not provide dir, uses the current mechanism as a fallback, or something similar
the ultimate object type would grow a default dir method that uses the same modus operandi as today's dir, which deriving classes could override to provide custom listings. therefore, i don't expect any backward-compatibility issues.
aye or nay?
-tomer
- Previous message: [Python-Dev] what can we do to hide the 'file' type?
- Next message: [Python-Dev] introducing __dir__?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]