Re: [Python-3000] guessing a rule of thumb for methods on object

2006-07-28 Thread Greg Ewing
Steven Bethard wrote: > I thought about this for a while, and I think maybe a good rule of > thumb (and something like what Python seems to follow) is: "If it's > there's an obvious default implementation of a protocol that would be > generally useful, it should go on all objects." Please, no! O

Re: [Python-3000] Detecting conflicts in dict displays

2006-07-28 Thread Josiah Carlson
"Stian Soiland" <[EMAIL PROTECTED]> wrote: > > On 7/11/06, Terry Reedy <[EMAIL PROTECTED]> wrote: > > > >>> d={1:'one', 1.0:'one'} > > >>> d > > {1: 'one'} > > This highlights the problem. Imagine that you don't type out the > actual objects, but just receive them: > > def make_dict(x, y, obj)

Re: [Python-3000] Detecting conflicts in dict displays

2006-07-28 Thread Stian Soiland
On 7/11/06, Terry Reedy <[EMAIL PROTECTED]> wrote: > >>> d={1:'one', 1.0:'one'} > >>> d > {1: 'one'} This highlights the problem. Imagine that you don't type out the actual objects, but just receive them: def make_dict(x, y, obj): return {x: obj, y: obj} x1 = x2 = "fish" d = make_dict(x1, x

[Python-3000] guessing a rule of thumb for methods on object

2006-07-28 Thread Steven Bethard
On 7/27/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 7/27/06, Steven Bethard <[EMAIL PROTECTED]> wrote: > > [1] It might get you something for __hash__() if object.__hash__() is > > not removed, but that debate still seems to be in progress and I'm not > > sure it's worth the added complexi

Re: [Python-3000] callable()

2006-07-28 Thread Guido van Rossum
On 7/28/06, Andrew Koenig <[EMAIL PROTECTED]> wrote: > Methinks that the suggestion includes defining hashable(x) in such a way as > to give the right answer, irrespective of how x.__hash__ is defined. I'm getting tired of this discussion, so I'm just going to stop reading this thread. -- --Guid

Re: [Python-3000] callable()

2006-07-28 Thread Josiah Carlson
Nick Coghlan <[EMAIL PROTECTED]> wrote: > Use cases for a "may be hashable" pretest are much weaker (and typically > hypothetical), but there are cases where it makes a certain amount of sense. > For example, if you have a set-based fast path if all the objects being > handled are hashable, and

Re: [Python-3000] object.__hash__()

2006-07-28 Thread Nick Coghlan
Steven Bethard wrote: > If object.__hash__() disappeared, the hash(obj) versions would fail, > but the same results seem to be available as hash(id(obj)). Not in Jython - Jython's id() is expensive so the default hash() doesn't use it. Last time the idea of getting rid of object.__hash__() came u

Re: [Python-3000] callable()

2006-07-28 Thread Nick Coghlan
Andrew Koenig wrote: > I note in PEP 3000 the proposal to remove callable(), with the comment "just > call the object and catch the exception." > > I think that's a bad idea, because it takes away the ability to separate the > callability test from the first call. As a simple example, suppose you

Re: [Python-3000] callable()

2006-07-28 Thread Nick Coghlan
Marcin 'Qrczak' Kowalczyk wrote: > Stefan Behnel <[EMAIL PROTECTED]> writes: > >> So, if hashable() returns True, it means that a) the designer didn't >> care about switching it off or b) there are cases where it works, so >> it makes sense to try calling it. > > If the code can successfully work

Re: [Python-3000] callable()

2006-07-28 Thread Andrew Koenig
> Guido van Rossum wrote: > > So how about we change callable() and add hashable(), iterable() and > > whatever else makes sense so that these all become like this: > > > > def callable(x): > > return getattr(x, "__call__", None) is not None > This *still* doesn't fully solve the problem in

Re: [Python-3000] callable()

2006-07-28 Thread Marcin 'Qrczak' Kowalczyk
Stefan Behnel <[EMAIL PROTECTED]> writes: > So, if hashable() returns True, it means that a) the designer didn't > care about switching it off or b) there are cases where it works, so > it makes sense to try calling it. If the code can successfully work with either hashable or non-hashable object

Re: [Python-3000] callable()

2006-07-28 Thread Stefan Behnel
Marcin 'Qrczak' Kowalczyk wrote: > Stefan Behnel <[EMAIL PROTECTED]> writes: > >> It just says: I support the protocol, so it makes sense to apply the >> protocol operations to me if you need to. >> >> I think that's perfectly reasonable semantics for the three functions. > > I see no essential

Re: [Python-3000] callable()

2006-07-28 Thread Marcin 'Qrczak' Kowalczyk
Stefan Behnel <[EMAIL PROTECTED]> writes: > It just says: I support the protocol, so it makes sense to apply the > protocol operations to me if you need to. > > I think that's perfectly reasonable semantics for the three functions. I see no essential difference between an object which doesn't sup