cause __init__ to return a different class?

Matthew Pounsett matt.pounsett at gmail.com
Thu Sep 15 10:45:12 EDT 2011


On Sep 15, 1:54 am, Ryan Kelly <r... at rfk.id.au> wrote:
> The above will do exactly what you want, but it's generally bad style
> unless you have a very specific use-case.  Is there a particular reason
> you need to "magically" return a subclass, rather than making this
> explicit in the code?
>
> To be friendlier to others reading your code, I would consider using a
> classmethod to create an alternative constructor:

Yeah, I was considering doing this as well, particularly if I couldn't
have made the other work.   The reason I'm not too concerned about
anyone misinterpreting what's going on is that in this case the base
class is actually named for being a constructor, and any rare case
where I want a specific subclass the subclass will be created
directly.

Thanks very much for your help!



More information about the Python-list mailing list