Skip to content

Commit

Permalink
Cleanup documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
olekli committed Oct 17, 2024
1 parent cd8a84e commit 7532af2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 69 deletions.
21 changes: 0 additions & 21 deletions drresult/gather_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@

class ResultContainer[T]:
"""Container to hold a `Result` within a context.
Attributes:
_result (Result[T] | Result[None]): The result held.
_finalized (bool): Indicates if the result is finalized.
Methods:
set(result): Set the result.
get() -> Result[T] | Result[None]: Get the finalized result.
"""

def __init__(self) -> None:
Expand Down Expand Up @@ -62,11 +54,6 @@ class gather_result[T]:
# Code that might raise exceptions
result_container.set(Ok(value))
result = result_container.get()
Attributes:
_expects (Tuple[Type[BaseException], ...]): Expected exceptions.
_not_expects (Tuple[Type[BaseException], ...]): Unexpected exceptions.
_container (ResultContainer[T]): The result container.
"""

def __init__(
Expand All @@ -88,14 +75,6 @@ def __enter__(self):

def __exit__(self, exc_type, exc_value, traceback):
"""Exit the context, handling exceptions.
Args:
exc_type: The exception type.
exc_value: The exception instance.
traceback: The traceback object.
Returns:
bool: True if the exception was handled, False otherwise.
"""
match exc_value:
case None:
Expand Down
48 changes: 0 additions & 48 deletions drresult/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

class BaseResult[T]:
"""Base class for `Ok` and `Err` result types.
Attributes:
_value (T): The value held by the result.
"""

def __init__(self): # pragma: no cover
Expand Down Expand Up @@ -73,9 +70,6 @@ def _unexpected(self, msg: Optional[str] = None) -> NoReturn:

class Ok[T](BaseResult[T]):
"""Represents a successful result.
Attributes:
_value (T): The successful value.
"""

__match_args__ = ('value',)
Expand Down Expand Up @@ -184,9 +178,6 @@ def unwrap_or_return(self) -> T:

class Err[E: BaseException](BaseResult[E]):
"""Represents an error result.
Attributes:
_value (E): The exception representing the error.
"""

__match_args__ = ('error',)
Expand Down Expand Up @@ -305,14 +296,6 @@ def unwrap_or_return(self) -> NoReturn:
"""Type alias for `Result`, which can be an `Ok` or an `Err`."""

def filter_traceback(e: BaseException) -> List[traceback.FrameSummary]:
"""Filter the traceback to exclude internal frames.
Args:
e (BaseException): The exception to filter.
Returns:
List[traceback.FrameSummary]: The filtered traceback frames.
"""
tb = traceback.extract_tb(e.__traceback__)
return [
frame
Expand All @@ -331,48 +314,17 @@ def filter_traceback(e: BaseException) -> List[traceback.FrameSummary]:
]

def format_traceback(e: BaseException) -> str:
"""Format the traceback of an exception.
Args:
e (BaseException): The exception to format.
Returns:
str: The formatted traceback string.
"""
new_tb_list = filter_traceback(e)
trace_to_print = ''.join(traceback.format_list(new_tb_list))
return trace_to_print

def format_exception(e: BaseException) -> str:
"""Format the exception message.
Args:
e (BaseException): The exception to format.
Returns:
str: The exception message.
"""
return ''.join(traceback.format_exception_only(e))[:-1]

def format_traceback_exception(e: BaseException) -> str:
"""Format the full traceback and exception message.
Args:
e (BaseException): The exception to format.
Returns:
str: The formatted traceback and exception message.
"""
return f'{format_traceback(e)}{format_exception(e)}'

def excepthook(type, e, traceback):
"""Custom exception hook to print formatted exceptions.
Args:
type: The exception type.
e (BaseException): The exception instance.
traceback: The traceback object.
"""
print(f'{format_traceback_exception(e)}')

sys.excepthook = excepthook
Expand Down

0 comments on commit 7532af2

Please sign in to comment.