Re: [Python-Dev] __dir__, part 2

2006-11-10 Thread Fredrik Lundh
Guido van Rossum wrote:

> No objection on targetting 2.6 if other developers agree. Seems this
> is well under way. good work!

given that dir() is used extensively by introspection tools, I'm
not sure I'm positive to a __dir__ that *overrides* the standard
dir() behaviour.  *adding* to the default dir() list is okay, re- 
placing it is a lot more questionable.

(what about vars(), btw?)



___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] __dir__, part 2

2006-11-10 Thread Guido van Rossum
On 11/10/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Guido van Rossum wrote:
>
> > No objection on targetting 2.6 if other developers agree. Seems this
> > is well under way. good work!
>
> given that dir() is used extensively by introspection tools, I'm
> not sure I'm positive to a __dir__ that *overrides* the standard
> dir() behaviour.  *adding* to the default dir() list is okay, re-
> placing it is a lot more questionable.

I think that ought to go into the guidlines for what's an acceptable
__dir__ implementation. We don't try to stop people from overriding
__add__ as subtraction either.

> (what about vars(), btw?)

Interesting question! Right now vars() and dir() don't seem to use the
same set of keys; e.g.:

>>> class C: pass
...
>>> c = C()
>>> c.foo = 42
>>> vars(c)
{'foo': 42}
>>> dir(c)
['__doc__', '__module__', 'foo']
>>>

It makes some sense for vars(x) to return something like

  dict((name, getattr(x, name)) for name in dir(x) if hasattr(x, name))

and for the following equivalence to hold between vars() and dir() without args:

  dir() == sorted(vars().keys())

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] __dir__, part 2

2006-11-10 Thread Thomas Heller
Fredrik Lundh schrieb:
> Guido van Rossum wrote:
> 
>> No objection on targetting 2.6 if other developers agree. Seems this
>> is well under way. good work!
> 
> given that dir() is used extensively by introspection tools, I'm
> not sure I'm positive to a __dir__ that *overrides* the standard
> dir() behaviour.  *adding* to the default dir() list is okay, re- 
> placing it is a lot more questionable.

One part that *I* would like about a complete overridable __dir__ implementation
is that it would be nice to customize what help(something) prints.

Thomas

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] __dir__, part 2

2006-11-10 Thread Fredrik Lundh
Thomas Heller wrote:

>>> No objection on targetting 2.6 if other developers agree. Seems this
>>> is well under way. good work!
 >>
>> given that dir() is used extensively by introspection tools, I'm
>> not sure I'm positive to a __dir__ that *overrides* the standard
>> dir() behaviour.  *adding* to the default dir() list is okay, re- 
>> placing it is a lot more questionable.
> 
> One part that *I* would like about a complete overridable __dir__ 
> implementation
> is that it would be nice to customize what help(something) prints.

I don't think you should confuse reliable introspection with the help 
system, though.  introspection is used for a lot more than implementing 
help().



___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] __dir__, part 2

2006-11-10 Thread Fredrik Lundh
Guido van Rossum wrote:

> I think that ought to go into the guidlines for what's an acceptable
> __dir__ implementation. We don't try to stop people from overriding
> __add__ as subtraction either.

to me, overriding dir() is a lot more like overriding id() than over- 
riding "+".  I don't think an object should be allowed to lie to the 
introspection mechanisms.



___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] __dir__, part 2

2006-11-10 Thread Guido van Rossum
On 11/10/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Guido van Rossum wrote:
>
> > I think that ought to go into the guidlines for what's an acceptable
> > __dir__ implementation. We don't try to stop people from overriding
> > __add__ as subtraction either.
>
> to me, overriding dir() is a lot more like overriding id() than over-
> riding "+".  I don't think an object should be allowed to lie to the
> introspection mechanisms.

Why not? You can override __class__ already. With a metaclass you can
probably override inspection of the class, too.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com