What's the preferred way and why for __exit__ method when it comes to returning value?
Should I write return False or no return at all since that will return None, I think behaviour in both cases will be the same but from what I can see people write it in both ways and I cannot see why.
class File:
def __init__(self, file_name: str, method: str) -> None:
self.file_obj = open(file_name, method)
def __enter__(self) -> File:
return self.file_obj
def __exit__(self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType]) -> bool:
self.file_obj.close()
return False
OR
class File:
def __init__(self, file_name: str, method: str) -> None:
self.file_obj = open(file_name, method)
def __enter__(self) -> File:
return self.file_obj
def __exit__(self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType]) -> None:
self.file_obj.close()