Skip to content

Changing the Err type E with and_then() passes type checking, but should not #190

Open
@JLessinger

Description

@JLessinger

The following type checks (pyright, all checks enabled):

T_cov = TypeVar("T_cov", covariant=True)

StrResult = Result[T_cov, str]
ExceptionResult = Result[T_cov, Exception]


def foo() -> StrResult[int]:
    return Ok(1)


def baz(x: int) -> ExceptionResult[int]:
    return Ok(x)


r1 = foo()
x = r1.and_then(baz)

In particular, x is inferred to be a x: StrResult[int] | Err[Exception].

The expression r1.and_then(baz) should not type check: pyright should report that a StrResult is not compatible with a int -> ExceptionResult because the Err types differ.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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