[Tutor] use of __new__

Kent Johnson kent37 at tds.net
Fri Jun 12 15:05:35 CEST 2009


On Fri, Jun 12, 2009 at 8:37 AM, Lie Ryan<lie.1296 at gmail.com> wrote:
>>>> class Normal(object):
> ...     def __new__(cls, arg):
> ...         if arg:
> ...             return Special(arg)
> ...         else:
> ...             ret = super(Normal, cls).__new__(cls)
> ...             ret.__init__(arg)
> ...             return ret

I think the else case should be
  ret = super(Normal, cls).__new__(cls, arg)
  return ret

i.e. pass the same args to super.__new__() and don't explicitly call __init__().

Kent


More information about the Tutor mailing list