Can a simple a==b 'hang' in and endless loop?

Christopher Subich csubich.spam.block at spam.subich.block.com
Thu Jan 19 12:15:57 EST 2006


Claudio Grondi wrote:

> The Python tutorial '3.2 The standard type hierarchy' says:
> """
> Ellipsis:  This type has a single value. There is a single object with 
> this value. This object is accessed through the built-in name Ellipsis. 
> It is used to indicate the presence of the "..." syntax in a slice. Its 
> truth value is true.
> """
> Not very helpful in understanding what it is, so it still belongs to the 
> dark unknown area of Python to me.
> Any hints towards enlightenment what this from the geometry known term 
> 'ellipsis' mean in Python? Googling shows, that I am not the first who 
> doesn't know what it is in context of Python, so probably there is 
> already a good explanation somewhere, but where?

Ellipsis has a very well-known meaning -- but it's not geometry at all 
(that's ellipse).  From Webster online:

Ellipsis (noun):
1 a : the omission of one or more words that are obviously understood 
but that must be supplied to make a construction grammatically complete 
b : a sudden leap from one topic to another
2 : marks or a mark (as ... or · or --) indicating an omission (as of 
words) or a pause

> Does it mean you reject to try to give a solution because of the reason 
> why I seek for it, or do you want to say, that there is to your 
> knowledge no possible solution except those you have already given?

Your problem is badly specified.  It seems to boil down to:

Given a and b as some combination of builtin types, is it possible for 
the equality comparison (a==b) to hang?

The answer, so far as I know, is 'no'.  That said, the answer is useless.

Firstly, you ignore the possiblity that '==' raises some form of error. 
  I don't know of any builtins that raise TypeError or the like on 
comparison, but you've already seen examples that generate recursion 
errors.  In fact, since the situations likely to lead to looping in == 
constructs use recursion anyway (calling == on members of structure 
types), your "infinite loop" becomes a stack depth error.

Secondly, you also ignore objects with overloaded or otherwise custom 
__eq__ methods -- the default and well-documented way of supplying 
equality comparisons to custom objects, which are first-class citizens 
in a Python environment.  (In fact, (1).__cmp__(1) [which provides a 
general comparison] works.)  Since these methods can contain arbitrary 
Python code, comparison in Python *can* cause an infinite loop, IO, or 
your grandmother to find out just what you've been hiding on your computer.

If you want to find out something about the principles behind Python, 
ask about the principles flat-out; don't construct a contrived case like 
this and wonder when the community's response is mostly confusion.



More information about the Python-list mailing list