Yes, this return statement is redundant. Only when type not None is return.
From the object.__exit__() documentation :
If an exception is thrown and the method wants to suppress the exception (i.e., prevent its propagation), it should return the true value. Otherwise, the exception will usually be processed after exiting this method.
Note that true value will suppress the exception; therefore 1 or "Handled!" will also work, not just True .
Removing this return line will return None , and the functionality will remain unchanged. However, readability will be improved because this return type == None just confused at several levels (why not use type is None , for example?).
source share