Bug or Feature?

David Eppstein eppstein at ics.uci.edu
Tue Nov 25 01:05:51 CET 2003

In article <mailman.1042.1069714432.702.python-list at python.org>,
 "Delaney, Timothy C (Timothy)" <tdelaney at avaya.com> wrote:

> > From: David Eppstein
> > 
> > It is very useful that ImmutableSet is closed under set operations.
> > By making the set operations copy the types of their arguments, the 
> > author of sets.py was able to achieve this without 
> > duplicating each set 
> > operation's implementation.  If you don't like this behavior you can 
> > always override it...
> So what happens when I make a set subclass that takes no parameters (other 
> than self) to   init  ?

What do you expect to happen in general when you define a class that 
does not adhere to some protocol, and then use it in that protocol 

>>> import sets
>>> class FunkySet(sets.Set):
...   def __init__(self):
...     sets.Set.__init__(self)
>>> f=FunkySet()
>>> f.add(1)
>>> g=FunkySet()
>>> g.add(2)
>>> g.add(3)
>>> f&g
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ets.py", line 205, in __and__
    return self.__class__(common)
TypeError: __init__() takes exactly 1 argument (2 given)

David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science

More information about the Python-list mailing list