Why keep identity-based equality comparison?

M

Mike Meyer

Antoon Pardon said:
I'm not going to bother with that.

Since you're being vague about what you want, and won't provide
examples to show why you want things to behave whatever way you want,
I can't really say much else about it.

<mike
 
A

Antoon Pardon

Op 2006-01-11 said:
Since you're being vague about what you want,

I would like some consistency. Either all comparisons between objects
of different types throw an exception by default or none does.
and won't provide
examples to show why you want things to behave whatever way you want,
I can't really say much else about it.

Did you see examples that show why Guido wants things to behave whatever
way he wants? I didn't and I didn't see examples from you either.

Guido's idea is a change from current behaviour. Each time I saw some
argue a change here, people seem to expect a use case from that person.
So why ask a use case of me and just accepy Guido's idea.
 
M

Mike Meyer

Antoon Pardon said:
I would like some consistency. Either all comparisons between objects
of different types throw an exception by default or none does.

That's a very silly thing to ask for. It presumes that all types are
the same. They aren't. It also presumes that all comparisons are the
same. They aren't. To use an overworked analogy, you might as well ask
that you either have to peel all fruit, or that you never have to peel
a fruit.

In any case, the proposeed behavior *is* consistent. The behavior for
all builtin types will be that comparisons that don't make sense will
throw exceptions. Since we're talking about Py3K here, there is no
"default" behavior. User-defined classes all inherit from builtin
types, and will get the behavior of their comparison operators from
those types. In particular, those that inherit from object will get
objects behavior, which means they'll get equality as identity.
Did you see examples that show why Guido wants things to behave whatever
Guido's idea is a change from current behaviour. Each time I saw some
argue a change here, people seem to expect a use case from that person.
So why ask a use case of me and just accepy Guido's idea.

For one thing, Guido has a long history of doing excellent Python
design work. For another, this issue was thrashout out at length in
comp.lang.python some years ago. What Guido proposed is inline with
the conclusions of those discussions.

<mike
 
S

Steven Bethard

Mike said:
Pretty much everything I do has heterogenous containers of some sort
or another.

Sorry, I should have been a little more specific. I meant heterogeneous
containers where you've used the "in" operator.
SQL queries made to DP API compliant modules return
homogenous lists of heterogenous containers. The cgi module turns the
request string into a dictionary-like container of objects with values
of different types.

Are the keys of different types too? Because if the keys are all the
same types, then using the "in" operator here wouldn't raise an
exception. Unless, of course, you used the "in" operator on the
..values() of the dictionary...
The last thing I did that was both more than a script and didn't use
either a database or a web front end was (IIRC) a media player for
multiple media types. It revolved around lists of things to play, and
the "things" in question could be any "playable" object - video or
audio files, track on a CD, or a DVD, or even a playlist.

That seems pretty reasonable. Your code used the "in" operator with
these lists?
Come to think of it, recursive data structures of this type - a
container that contains a heterogenous list of things, possibly
including instances of the container type itself - are pretty
common.

Sure. I have a number of tree-like containers, and in at least a few
implementations, BranchNode and LeafNode are different classes. But I
haven't needed the "in" operator with these. With the
raise-exceptions-between-objects-of-different-types proposal, it would
probably raise an exception if you tried, but I can't decide whether
that's a good or a bad thing...
The other proposal - if I have it right - would not change the
behavior of equality comparisons between objects of the same class,
but would make comparisons between objects of different classes raise
an exception instead of returning false by default.

Perhaps, given duck-typing, a better proposal would be to raise an
exception if the objects have different interfaces. Of course, at the
moment, I can't think of any even vaguely efficient way of checking
that. ;-)

STeVe
 
M

Mike Meyer

Steven Bethard said:
Sorry, I should have been a little more specific. I meant
heterogeneous containers where you've used the "in" operator.

Fair enough. But the problem occurs with more than just the "in"
operator. Anytime you want to do comparisons on objects in a
heterogenous container, you have to deal with this. This includes
other methods on the container, like list index and remove
moethods. It also means that application-level code that does these
kinds of things have to deal with the possible exceptions as
non-exceptional occurences.

Yeah, there's an easy fix. But it's ugly.
Are the keys of different types too? Because if the keys are all the
same types, then using the "in" operator here wouldn't raise an
exception. Unless, of course, you used the "in" operator on the
.values() of the dictionary...

Nope, not different keys. The canonical example of that would be the
many "memoize" decorators. Note that *inserting* something into such a
dictionary can cause problems, as if two objects hash to the same
value, they get compared for equality.
That seems pretty reasonable. Your code used the "in" operator with
these lists?

I don't really recall - it's been a while. I know I provided searching
facillities, but don't recall if it did a search by doing object
comparisons or not.
Sure. I have a number of tree-like containers, and in at least a few
implementations, BranchNode and LeafNode are different classes. But I
haven't needed the "in" operator with these. With the
raise-exceptions-between-objects-of-different-types proposal, it would
probably raise an exception if you tried, but I can't decide whether
that's a good or a bad thing...

Ugh. That's *ugly*. That means you have to do a complete pass over the
data to figure out if two objects are "different types" or not so you
can decide to raise the exception.

Whether you want to make a seperate "check the type" pass or try doing
equality tests at the same time will depend on the data. If you're
checking a set of 10-million element lists, you *don't* want to check
them all if you can avoid it. Either that, or make the results of the
in operator (and related methods, etc.) depend on the comparison
order. That might be acceptable for lists, but it's really not for
sets or dictionaries.

Actually, that's not sufficient to make the results reliable. If some
objects are allowed to *not* throw exceptions and do
equality-based-on-identity, then the results of a == b won't be the
same as the results of b == a, so looking for a in a container that
has b in it will give different results than looking for b in a
container that has a in it.
Perhaps, given duck-typing, a better proposal would be to raise an
exception if the objects have different interfaces. Of course, at the
moment, I can't think of any even vaguely efficient way of checking
that. ;-)

Yup. This *really* looks like trying to enforce static typing in a
language that doesn't do anything like it now.

<mike
 
A

Antoon Pardon

Op 2006-01-11 said:
That's a very silly thing to ask for. It presumes that all types are
the same. They aren't.

It doesn't presume anything like that.
It also presumes that all comparisons are the same. They aren't.

It doesn't presume that either.
To use an overworked analogy, you might as well ask
that you either have to peel all fruit, or that you never have to peel
a fruit.

Bad analogy since a fruit is not a relationship.
In any case, the proposeed behavior *is* consistent. The behavior for
all builtin types will be that comparisons that don't make sense will
throw exceptions.

It is only consistent if you start from an inconsistent view and then
check for how consistently this view is followed. There is nothing
consistent in telling that 1 == (1,3) makes sense and 1 < (1,3)
doesn't make sense. Set theoretically both 1 and (1,3) are sets.

There is a use case for things like 1 < (1,3) making sense and denoting
a total order. When you have a hetergenous list, having a total order
makes it possible to sort the list which will make it easier to
weed out duplicates. So why don't you demand a use case for the
new behaviour to counter this use case?

IMO it would be better if it was possible to associate some kind
of order function with the container. Because the order most usefull
for comparing between two instances doesn't need to be the most usefull
order in finding an element from a container.

I could impose a total order on sets, so that I can use a bisection
algorithm on a container of them, but such an order is in general
less usefull than the superset ordering when you are manipulating
sets.
Since we're talking about Py3K here, there is no
"default" behavior. User-defined classes all inherit from builtin
types, and will get the behavior of their comparison operators from
those types. In particular, those that inherit from object will get
objects behavior, which means they'll get equality as identity.

But if this makes any behaviour defined on objects consistent by
definition, because the only criteria you seem to have for consistency
is the inherited behaviour from object. If object would use a
random function to decide that would be consistent too, because it
would be the behaviour inherited by other classes. I don't find this
a usefull way to measure consistency.
For one thing, Guido has a long history of doing excellent Python
design work. For another, this issue was thrashout out at length in
comp.lang.python some years ago. What Guido proposed is inline with
the conclusions of those discussions.

Then it should be easy to come up with the use cases and arguments pro
this idea presented then. If this idea of Guido was the result of his
briliance in language design, surely there should be arguments and
use cases to confirm that.
 
P

Paul Rubin

Antoon Pardon said:
There is a use case for things like 1 < (1,3) making sense and denoting
a total order. When you have a hetergenous list, having a total order
makes it possible to sort the list which will make it easier to
weed out duplicates. So why don't you demand a use case for the
new behaviour to counter this use case?

This could easily be handled with an alternate comparison function
that you pass to the sort function.
 
A

Antoon Pardon

Op 2006-01-12 said:
This could easily be handled with an alternate comparison function
that you pass to the sort function.

Yes that is true and will be all that is needed in most cases.
But in the case where new items are regularly added, one might
prefer to use the bisect module for something like this. The
bisect module doesn't have an alternate comparison function
neither has the heapqueue module.

O.K. lets try to get at this from a more constructive direction.
Python will get the behaviour that 1 < (1,3) will throw an exception.
What can python do to help for cases like the above.

1) Python could provide a seperare total ordering, maybe with operators
like '<|' and '|>' and function operator.rank (with functionlity
similar to cmp)

2) Python could make it possible to associate a ranking with a
container. This ranking is used by default by methods and
modules like sort, bisect and heapqueue.

3) Python could provide the possibility of providing an alternate
comparison function with heapqueue, bisect and similar modules.


These options are not meant to be exclusive. But if a choice is
to be made I would prefer (2) (a little) over (1) over (3).
 
P

Paul Rubin

Antoon Pardon said:
The bisect module doesn't have an alternate comparison function
neither has the heapqueue module.

They could be extended. Care to enter a feature request?
1) Python could provide a seperare total ordering, maybe with operators
like '<|' and '|>' and function operator.rank (with functionlity
similar to cmp)

Based on experience that I'm sure you understand, anything like that
is going to be awfully hard to sell.
3) Python could provide the possibility of providing an alternate
comparison function with heapqueue, bisect and similar modules.

That's probably the best bet.
 
A

Antoon Pardon

Op 2006-01-12 said:
They could be extended. Care to enter a feature request?

Not really because IMO this is the wrong approach.
Based on experience that I'm sure you understand, anything like that
is going to be awfully hard to sell.


That's probably the best bet.

But IMO not very helpfull. When I use a heapqueue I need to use
it with the same comparison function through its whole lifetime.
It doesn't make sense to work with a heapqueue that has a variable
comparison function. So having to provide this comparison function
with each operation strikes me as much to cumbersome and error prone.
Especially if you are working with multiple heaps each with its
own comparison function.

Writing my own heapqueue class that takes a comparison function as
a parameter to the __init__ method to associate with that particular
heapqueue seems a more rational solution than extending (or letting
others do so) the stdlib packages with such a parameter.

IMO letting python associate such a function with an arbitrary container
is the most usefull option. It would allow the programmer to easily define
what they need.

Do you only care about identity, provide a comparison function that
works on identy.

Do you want lst.index(1) to return the index of 1.0 and decimal("1")
or not. You would be able to specify this just how you want by
just associating a new comparison function with the container.

Now off course I could write a subclass of list which would do
all this, but that would mean writing a lot of the functionality
that is basically already there.
 
M

Mike Meyer

Antoon Pardon said:
It doesn't presume anything like that.

Yes it does. It presumes that all operators of all types either always
make sense, or there are always situations where they don't
It doesn't presume that either.

Yes it does. It presumes that all operators either always make sesne,
or there are always situations where they don't.
Bad analogy since a fruit is not a relationship.

I suggest you look up the meaning of the word "analogy".
It is only consistent if you start from an inconsistent view and then
check for how consistently this view is followed. There is nothing
consistent in telling that 1 == (1,3) makes sense and 1 < (1,3)
doesn't make sense. Set theoretically both 1 and (1,3) are sets.

Of course there are types for which the given behaviors don't make
sense. However, we're not talking about user-defined relations on
user-defined types with syntax that isn't supported by the
language. We're talking about the builtin relationships defined on the
builtin types.
There is a use case for things like 1 < (1,3) making sense and denoting
a total order. When you have a hetergenous list, having a total order
makes it possible to sort the list which will make it easier to
weed out duplicates. So why don't you demand a use case for the
new behaviour to counter this use case?

Yes, there is. And you are perfectly free to implement a type that
behaves that way if you want to. I don't need a use case to "counter"
this one; I just need to show that this use case can be reasonably
covered by the proposed mechanism.
IMO it would be better if it was possible to associate some kind
of order function with the container. Because the order most usefull
for comparing between two instances doesn't need to be the most usefull
order in finding an element from a container.

No, it wouldn't. Order relationships are a property of the type, not
the container. The order relationships are right where they belong -
attached to the type. That notwithstanding, it's often practical to be
able to override the order function for some specific method (and
would be even if the order function were associated with the container
instead of the type), so some of the methods that use order allow you
to provide a function to use for them. If you really want a container
type that has an order function associated with it, you can write
one. If you want it made part of the language, you'll have to provide
a use case.
I could impose a total order on sets, so that I can use a bisection
algorithm on a container of them, but such an order is in general
less usefull than the superset ordering when you are manipulating
sets.

And you're free to implement a subclass of sets that does that. If you
want to argue that the builtin sets should do that, you can - but
that's unrelated to the question of how the comparison operators
behave for the rest of the bulitin types. At least, it doesn't matter
unless you try and force all the types and operators to be the same.
But if this makes any behaviour defined on objects consistent by
definition, because the only criteria you seem to have for consistency
is the inherited behaviour from object. If object would use a
random function to decide that would be consistent too, because it
would be the behaviour inherited by other classes. I don't find this
a usefull way to measure consistency.

But you can use a random function to decide no matter *how* the
bulitin relationships behave. That's part of the powero of Python - it
doesn't impose arbitrary constraints on what you can do. You seem to
think we should either disallow comparison operators from throwing
exceptions, or force them to throw exceptions under some unstated
conditions. But not all types are the same; some may not *have*
conditions under which all relational operators need to throw an
exception. And not all comparisons are the same; some may not *have*
conditions under which they need to throw an exception.
Then it should be easy to come up with the use cases and arguments pro
this idea presented then. If this idea of Guido was the result of his
briliance in language design, surely there should be arguments and
use cases to confirm that.

It's no easier for me to find them than for you to find them. And I'm
not guido - if you want his thoughts, you'll have to ask him.

<mike
 
A

Antoon Pardon

[ BIG CUT ]

I'm going to drop this part. I disagree with you and think
I can show some of your argument invalid. Hoever I also doubt
something fruitfull can come from continuing this. Lets agree
to disagree.
No, it wouldn't. Order relationships are a property of the type, not
the container. The order relationships are right where they belong -
attached to the type.

Order relationships are only a property of the type in a particular
sense. There certainly is not a one on one relationship between
order relationships and types. A type can have multiple order relationships
all usefull in different circumstances. If a specific order is
only usefull in the context of a spefic container I see no problem
with associating the order with the container.
That notwithstanding, it's often practical to be
able to override the order function for some specific method (and
would be even if the order function were associated with the container
instead of the type), so some of the methods that use order allow you
to provide a function to use for them. If you really want a container
type that has an order function associated with it, you can write
one. If you want it made part of the language, you'll have to provide
a use case.

Fair enough. Take the heapqueue module. The times that I had need
for a heapqueue this module was useless to me. The reason always
boiled down to the fact that the order defined on the object
(as far as there was one) was not the order in which I wanted
the objects processed. e.g. I want a heapqueue of sets that gives
priority according to the number of elements in the set. Or I have
two heapqueues each of intervals. The first gives priority according
to the low value, the second gives priority according the the high
value.
And you're free to implement a subclass of sets that does that.

But that is not usefull to me. Take sets. It's been a while so
I'm not sure I can dig it back up, but I once had an algorithm
manipulating sets, where this manipulation would involve the
normal superset order. This algorithm had two charateristics.

1) Manipulating certain sets, made the manipulation of other
sets unnecessary.

2) Manipulating smaller sets was faster than manipulating
larger sets.

3) Sets were constantly added and removed from the manipulating
pool.

These characteristics made this a natuaral candidate for a heapqueue
that used the number of elements as (inverse) priority.

However the manipulation of a single set needed the normal
superset relationship as order relation.

So making a subclass of sets with an order usefull for the
heapqueue would only be a marginal improvement to the
existing situation.
If you
want to argue that the builtin sets should do that, you can - but
that's unrelated to the question of how the comparison operators
behave for the rest of the bulitin types.

What I argue is that there is no single order for a specific type.
There can be an order that is most usefull in general but which order
is usefull at a specific point depends on the context. Sometimes
this context is the container that the types belongs to, like
a heapqueue. Associating that order with the container seems to
most natural to treat this kind of circumstances.
 
M

Mike Meyer

Antoon Pardon said:
What I argue is that there is no single order for a specific type.

I think that depends on your definition of type, but let it go.
There can be an order that is most usefull in general but which order
is usefull at a specific point depends on the context.

Yes. So what? Does this fact suggest some change to Python that would
improve it? If so, you need to mention it. If not, why bring it up at
all?

<mike
 
N

Noam Raphael

Mike said:
This isn't "easy". It's an ugly hack you have to use everytime you
want to iterate through a heterogenous set doing equality tests.

I wouldn't define this as an "ugly hack". These are four simple line,
which state clearly and precisely what you mean, and always work. I have
seen ugly hacks in my life, and they don't look like this.
You're replacing "false" with an "emphathetic false", that *all*
containers to change for the worse to deal with it.
I don't see how they change for the worse if they have exactly the same
functionality and a few added lines of implementation.
Except that we now need four versions of internal data structures,
instead of two: list, tuple, idlist, idtuple; set, idset, frozenset,
frozenidset, and so on. What's wrong with this is that it's ugly.

Again, "ugly" is a personal definition. I may call this "explicitness".
By the way, what's the "and so on" - I think that these are the only
built-in containers.
Yes you can, and it's even easy. All you have to do is use custom
classes that raise an exception if they don't

You can't create a general container with my proposed == behaviour.
That's what I meant.
Yes you can. Just use the "is" operator.

Sorry, I wasn't clear enough. In "treating" I meant how containers treat
the objects they contain. For example, you can't easily map a value to a
specific instance of a list - dict only lets you map a value to a
specific *value* of a list. Another example - you can't search for a
specific list object in another list.
Note that this behavior also has the *highly* pecular behavior that a
doesn't necessarily equal a by default.

Again, "peculiar" is your aesthethic sense. I would like to hear
objections based on use cases that are objectively made more difficult.
Anyway, I don't see why someone should even try checking if "a==a", and
if someone does, the exception can say "this type doesn't support value
comparison. Use the "is" operator".
I will point out why your example usages aren't really usefull if
you'll repeat your post with newlines.
Here they are:

* Things like "Decimal(3.0) == 3.0" will make more sense (raise an
exception which explains that decimals should not be compared to
floats, instead of returning False).
* You won't be able to use objects as keys, expecting them to be
compared by value, and causing a bug when they don't. I recently wrote
a sort-of OCR program, which contains a mapping from a numarray array
of bits to a character (the array is the pixel-image of the char).
Everything seemed to work, but the program didn't recognize any
characters. I discovered that the reason was that arrays are hashed
according to their identity, which is a thing I had to guess. If
default == operator were not defined, I would simply get a TypeError
immediately.
* It is more forward compatible - when it is discovered that two types
can sensibly be compared, the comparison can be defined, without
changing an existing behaviour which doesn't raise an exception.

The third example applies to the Decimal==float use case, and for every
type that currently has the default identity-based comparison and that
may benefit from a value-based comparison. Take the class

class Circle(object):
def __init__(self, center, radius):
self.center = center
self.radius = radius

Currently, it's equal only to itself. You may decide to define an
equality operator which checks whether both the center and the radius
are the same, but since you already have a default equality operator,
that change would break backwards-compatibility.

Noam
 
M

Mike Meyer

Noam Raphael said:
Sorry, I wasn't clear enough. In "treating" I meant how containers
treat the objects they contain. For example, you can't easily map a
value to a specific instance of a list - dict only lets you map a
value to a specific *value* of a list.

Wrong. All you have to do is create a list type that uses identity
instead of value for equality testing. This is easier than mapping an
exception to false.
Another example - you can't
search for a specific list object in another list.

Your proposed == behavior doesn't change that at all.
Here they are:
* Things like "Decimal(3.0) == 3.0" will make more sense (raise an
exception which explains that decimals should not be compared to
floats, instead of returning False).

While I agree that Decimal(3.0) == 3.0 returning false doesn't make
sense, having it raise an exception doesn't make any more sense. This
should be fixed, but changing == doesn't fix it.
* You won't be able to use objects as keys, expecting them to be
compared by value, and causing a bug when they don't. I recently wrote
a sort-of OCR program, which contains a mapping from a numarray array
of bits to a character (the array is the pixel-image of the char).
Everything seemed to work, but the program didn't recognize any
characters. I discovered that the reason was that arrays are hashed
according to their identity, which is a thing I had to guess. If
default == operator were not defined, I would simply get a TypeError
immediately.

This isn't a use case. You don't get correct code with either version
of '=='. While there is some merit to doing things that make errors
easier to find, Python in general rejects the idea of adding
boilerplate to do so. Your proposal would generate lots of boilerplate
for many practical situations.
* It is more forward compatible - when it is discovered that two types
can sensibly be compared, the comparison can be defined, without
changing an existing behaviour which doesn't raise an exception.

Sorry, but that doesn't fly. If you have code that relies on the
exception being raised when two types are compared, changing it to
suddenly return a boolean will break that code.

<mike
 
N

Noam Raphael

Mike said:
Wrong. All you have to do is create a list type that uses identity
instead of value for equality testing. This is easier than mapping an
exception to false.
You're suggesting a workaround, which requires me to subclass everything
that I want to lookup by identity (and don't think it's simple - I will
have to wrap a lot of methods that return a list to return a list with a
modified == operator).

I'm suggesting the use of another container class: iddict instead of
dict. That's all.
I don't think that mapping an exception to false is so hard (certainly
simpler than subclassing a list in that way), and the average user won't
have to do it, anyway - it's the list implementation that will do it.
Your proposed == behavior doesn't change that at all.

It does - *use idlist*.
While I agree that Decimal(3.0) == 3.0 returning false doesn't make
sense, having it raise an exception doesn't make any more sense. This
should be fixed, but changing == doesn't fix it.
No, it can't be fixed your way. It was decided on purpose that Decimal
shouldn't be comparable to float, to prevent precision errors. I'm
saying that raising an exception will make it clearer.
This isn't a use case. You don't get correct code with either version
of '=='. While there is some merit to doing things that make errors
easier to find, Python in general rejects the idea of adding
boilerplate to do so. Your proposal would generate lots of boilerplate
for many practical situations.
I would say that there's a lot of merit to doing things that make errors
easier to find. That's what exceptions are for.

Please say what those practical situations are - that what I want.
(I understand. You think that added containers and a try...except fro
time to time aren't worth it. I think they are. Do you have any other
practical situations?)
Sorry, but that doesn't fly. If you have code that relies on the
exception being raised when two types are compared, changing it to
suddenly return a boolean will break that code.
You are right, but that's the case for every added language feature (if
you add a method, you break code that relies on an AttributeError...)
You are right that I'm suggesting a try...except when testing if a list
contains an object, but a case when you have a list with floats and
Decimals, and you rely on "Decimal("3.0") in list1" to find only
Decimals seems to me a little bit far-fetched. If you have another
example, please say it.

Noam
 
M

Mike Meyer

Noam Raphael said:
You're suggesting a workaround, which requires me to subclass
everything that I want to lookup by identity (and don't think it's
simple - I will have to wrap a lot of methods that return a list to
return a list with a modified == operator).

No, I'm suggesting a general solution that works for *every* case
where you want something other than the standard equality case.
I'm suggesting the use of another container class: iddict instead of
dict. That's all.

You're suggesting adding a new builtin type to the language that deals
with one special case. Is this special case really that common? I
don't recall seeing anyone else ask for it in the last 10 years or so.
I don't think that mapping an exception to false is so hard (certainly
simpler than subclassing a list in that way), and the average user
won't have to do it, anyway - it's the list implementation that will
do it.

I disagree with both your assessments. Subclassing is trivial. And
every user who wants to compare elements in a container that might
include heterogenous types has to deal with this issue. That's more
than just lists, even if you only pay atttention to builtin
types. Nuts - you have to deal with it when you're adding elements to
a dictionary.
It does - *use idlist*.

You're mixing two proposals into the same thread. You'll forgive me
for referring to the original proposal.
No, it can't be fixed your way. It was decided on purpose that Decimal
shouldn't be comparable to float, to prevent precision errors. I'm
saying that raising an exception will make it clearer.

So how come I can compare decimals to floats?
False

Are you proposing we should break this, which currently functions
correctly?

You're correct that this can't be fixed by "fixing" decimal alone. It
requires more work than that. It may not be possible to fix this
properly before Py3K. But your proposal can't be done until then
anyway. I've already started the process of proposing a proper fix.
I would say that there's a lot of merit to doing things that make
errors easier to find. That's what exceptions are for.

Exceptions are for finding *programming errors*? That's a rather
unusual view of exceptions.
Please say what those practical situations are - that what I want.
(I understand. You think that added containers and a try...except fro
time to time aren't worth it. I think they are. Do you have any other
practical situations?)

That try...except is the boilerplate I'm talking about.
You are right that I'm suggesting a try...except when testing if a
list contains an object, but a case when you have a list with floats
and Decimals, and you rely on "Decimal("3.0") in list1" to find only
Decimals seems to me a little bit far-fetched. If you have another
example, please say it.

But you're suggesting changing *far more* than just decimals, and have
made multiple suggestions. Exactly what are you looking for an example
of?

<mike
 
A

Antoon Pardon

Op 2006-01-14 said:
I think that depends on your definition of type, but let it go.


Yes. So what? Does this fact suggest some change to Python that would
improve it? If so, you need to mention it. If not, why bring it up at
all?

I did mention it, you even asked a use case and I gave it. What more
do you want?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,276
Messages
2,571,384
Members
48,073
Latest member
ImogenePal

Latest Threads

Top