MyClass which is defined below accepts a single argument arg.
class MyClass(object):
def __init__(self, arg):
super(MyClass, self).__init__()
if not isinstance(arg, int):
return None
else:
self.arg = arg
If the incoming argument arg is not an integer I would like to return None instead of the instance of MyClass.
a = MyClass(arg='Text Argument')
But even while MyClass constructor __init__ returns None when the arg is not an integer the resulting variable a is still an instance of MyClass:
print a
<__main__.MyClass object at 0x0000000001FDEFD0>
How to make sure the variable a remains None if MyClass is given a non-integer argument?