Unpythonic? Impossible??

Felipe Almeida Lessa felipe.lessa at gmail.com
Sun Mar 19 13:17:17 EST 2006


Em Dom, 2006-03-19 às 08:54 -0800, Scott David Daniels escreveu:
>      class A(object):
>          def __new__(class_, *args, **kwargs):
>              if class_ is A:
>                  if want_a_B1(*args, **kwargs):
>                      return B1(*args, **kwargs)
>                  elif want_a_B2(*args, **kwargs):
>                      return B2(*args, **kwargs)
>              return object.__new__(class_) # Use *a,... except for object
> 
>      class B1(A):
>          def __new__(class_, *args, **kwargs):
>              if class_ is B1:
>                  if want_a_B1(*args, **kwargs):
>                      return B1(*args, **kwargs)
>                  elif want_a_B2(*args, **kwargs):
>                      return B2(*args, **kwargs)
>              return super(B1, class_).__new__(class_, *args, **kwargs)

Why you have that if on B1.__new__? B1 will be created only by
A.__new__, which already did a check.

-- 
Felipe.




More information about the Python-list mailing list