I am trying to emulate the idea of ok and err variants from rust in python, here is a result class
from typing import Any, Union
class Result:
def __init__(self, value: Any, status: bool = True) -> None:
self.value = value
self.status = status
@classmethod
def Ok(cls, result: Any) -> Result:
return cls(result, status=True)
@classmethod
def Err(cls, error: Any):
return cls(error, status=False)
def unwrap(self):
if self.status:
print("from Result -> self.status TRUE")
print(f"from Result -> self.value = {self.value}")
return self.value
else:
print("from Result -> self.status FALSE")
print(f"from Result -> self.value = {self.value}")
return self.value
I cannot just use the class name Result
to indicate the return type, how do can I properly do so using the typing
module or with whatever other method that is available? TY!
EDIT:
would i so something like
@classmethod
def ok(cls, result: Any) -> __init__:
return cls(result, status=True)