Skip to content

Mypy shows type errors when using has_item, expecting Matcher[Never] #264

Description

@gabeseltzer

Hi, thanks so much for this awesome library! I'm using python 3.10.15, with PyHamcrest 2.1.0 and mypy 1.15.0.

I've tried the following:

from hamcrest import has_entry, has_item

has_item(has_entry("name", "Sky"))

and mypy complains:

error: Argument 1 to "has_item" has incompatible type "Matcher[Mapping[str, str]]"; expected "Matcher[Never]"  [arg-type]

Am I doing something wrong? Is this an issue with mypy? Or is this an issue in PyHamcrest's typing? Or maybe I'm just using incompatible versions of the three?

Thanks for the help!

# More realistic example:
x = [{"name": "Tim", "age": 5},{"name": "Alice", "age": 2},{"name": "Sky", "age": 13},{"name": "Xin", "age": 22}]
assert_that(x, has_item(has_entry("name", "Alice")))

# Cannot infer type argument 1 of "assert_that" Mypy misc
# Argument 1 to "has_item" has incompatible type "Matcher[Mapping[str, str]]"; expected "Matcher[Never]" Mypy arg-type

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