On Wed, Apr 28, 2010 at 6:03 PM, Chris G <[email protected]> wrote:

>
> If so, you need to do a check in the class's __new__:
>>
>> class MyClass(object):
>>    def __new__(cls, *args):
>>        if badArgs(args):
>>           return None
>>        return super(MyClass, cls).__new__(cls)
>>
>>    def __init__(self, *args):
>>       # do normal init stuff...
>>
>
> Yikes, this is pure evil IMO.  In this case I would recommend a factory
> function instead.
>
> .. of course there are legit reasons to use __new__ like when you need to
generate classes on the fly.  I just mean for the simple case of
error-checking on creation of an object you should really use exceptions or
a None return from a factory function to keep things reasonably pythonic.

- Chris

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to