constructor of subclass and base's tp_new() (was: subclassing a new-style (C) extension type: help!)

Maciej Kalisiak mac at die.spammer.die.dgp.toronto.edu
Wed Mar 26 22:37:20 CET 2003


* Maciej Kalisiak <mac at die.spammer.die.dgp.toronto.edu>:
>  ,----
> | from State import State
> | class StateOfSize5(State):
> |     def __init__(self):
> |         State.__init__(self, 5)
> |     
> | s = State(5)          # this runs OK
> | s = StateOfSize5()    # ERROR
> | s = StateOfSize5(5)   # a workaround, but undermines the purpose of subclass
>  `----

I forgot to mention, to get the workaround to work, the  constructor must be
modified, like this:

  class StateOfSize5(State):
      def __init__(self, dummy):
          State.__init__(self, dummy)

So the workaround undermines the purpose of subclass *and* is horribly ugly. :)




More information about the Python-list mailing list