Skip to content

pyright finds type errors with MatchesSetwise and tuples #568

@allenap

Description

@allenap

Using pyright:

# uv run pyright --version
pyright 1.1.408

I get the following typing errors:

# These are fine:
self.assertThat(["foo"], MatchesSetwise(Equals("foo")))
foo = ("foo",)
self.assertThat([foo], MatchesSetwise(Equals(foo)))
self.assertThat([foo], MatchesSetwise(Equals(("foo",))))
# But this does not type check:
self.assertThat([("foo",)], MatchesSetwise(Equals(("foo",))))

The error is:

Argument of type "MatchesSetwise[tuple[Literal['foo']]]"
cannot be assigned to parameter "matcher" of type "Matcher[T@assertThat]" in function "assertThat"
"MatchesSetwise[tuple[Literal['foo']]]" is not assignable to "Matcher[list[tuple[str]]]"
Type parameter "T@Matcher" is invariant,
but "Iterable[tuple[Literal['foo']]]" is not the same as "list[tuple[str]]" (reportArgumentType)

With mypy no errors are reported, so this might be a bug in pyright.

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