polymorphism w/out signatures?

Robert Brewer fumanchu at amor.org
Fri May 7 11:50:02 EDT 2004


Peter Otten wrote:
> Larry Bates wrote:
> 
> > I use type() quite a lot.  I poked around and couldn't
> > find where it was being deprecated.  I did see that
> > types module is slated for deprecation.  Maybe I
> > overlooked it?
> > 
> > I use:
> > 
> > class foo:
> >     _stringtype=type('')
> >     _tupletype=type(())
> >     _listtype=type([])
> > 
> >     def __init__(self, variable):
> >     if type(variable) == _stringtype:
> >         self.variable=variable # check for string type
> >     if type(variable) in (_listtype, tupletype):
> >         self.variable=str(variable) # check for list/tuple
> 
> I would change that to
> 
>     def __init__(self, v):
>         self.variable = str(v)

If only that worked for datetime types ;)

>>> d = datetime.date(2004, 1, 1)
>>> d2 = datetime.date(d)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: function takes exactly 3 arguments (1 given)

D'oh! One of these days, I'm going to file a bug for that.


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list