Skip to content

"Result" monad's "Left" and "Right" types are reversed #226

@mikepii

Description

@mikepii

Result is defined as:

Result = Either[SuccessResult, ErrorResult]

However, the runtime values are reversed:

def validate_result(result: Result) -> None:
"""Validate the return value from a method.
Raises an AssertionError if the result returned from a method is invalid.
Returns: None
"""
assert (isinstance(result, Left) and isinstance(result._error, ErrorResult)) or (
isinstance(result, Right) and isinstance(result._value, SuccessResult)
), f"The method did not return a valid Result (returned {result!r})"

Therefore mypy complains if users type their methods with -> Result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions