Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy fails with nested matchers #207

Closed
robyoung opened this issue Jul 25, 2022 · 1 comment
Closed

Mypy fails with nested matchers #207

robyoung opened this issue Jul 25, 2022 · 1 comment

Comments

@robyoung
Copy link
Contributor

In the example below I have used has_items and has_properties however I am seeing this with contains and friends and has_entries as well.

Minimal reproducable example

Packages

mypy==0.971
PyHamcrest==2.0.3

Example

from dataclasses import dataclass
from hamcrest import assert_that, has_items, has_properties


@dataclass
class Example:
    name: str
    age: int


items = [Example("dave", 1), Example("wave", 2)]

assert_that(
    items,
    has_items(
        has_properties(name="dave", age=1),
        has_properties(name="wave", age=2),
    ),
)

Expected outcome

mypy does not complain as this is a valid use of has_items and has_properties.

Actual outcome

mypy returns the following error

test.py:13: error: Cannot infer type argument 1 of "assert_that"
test.py:16: error: Argument 1 to "has_items" has incompatible type "Matcher[object]"; expected "Matcher[<nothing>]"
test.py:17: error: Argument 2 to "has_items" has incompatible type "Matcher[object]"; expected "Matcher[<nothing>]"
Found 3 errors in 1 file (checked 1 source file)
@offbyone
Copy link
Member

This is a minimal example on mypy-play: https://mypy-play.net/?mypy=latest&python=3.10&gist=4c8824df5632e2358e459fd80cb42388

offbyone added a commit to offbyone/PyHamcrest that referenced this issue Aug 6, 2022
fixes hamcrest#207

`Matcher[object]` is too tight of a bound on the output type; what we're
asserting is that a matcher for `Any` type is what `has_properties` will
do
offbyone added a commit to offbyone/PyHamcrest that referenced this issue Aug 6, 2022
fixes hamcrest#207

`Matcher[object]` is too tight of a bound on the output type; what we're
asserting is that a matcher for `Any` type is what `has_properties` will
do
offbyone added a commit that referenced this issue Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants