You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the Matcher class has a type arg T as it should, but Matchers are currently invariant with respect to T. However, I think it's quite clear that the following should be legal code:
» pyright test.py
[...]
test.py
test.py:23:25 - error: Expression of type"Matcher[Sized]" cannot be assigned to declared type"Matcher[str]""Matcher[Sized]" is incompatible with "Matcher[str]"
TypeVar "T@Matcher" is invariant
"Sized" is incompatible with "str" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations
Completed in 0.582sec
Changing line 3 to T = TypeVar('T', contravariant=True) fixes the issue.
Ah, I remember now. So, I did try this back when I added typing, but the trouble is getting the contravariant matcher to work with assert_that(). I was never able to work it out.
Activity
brunns commentedon Nov 28, 2022
Thanks, I'll look into this in a few days if no one else gets to it first.
mezuzza commentedon Nov 28, 2022
Thanks a lot. I think this should fix a number of type problems when using the library.
brunns commentedon Dec 8, 2022
Ah, I remember now. So, I did try this back when I added typing, but the trouble is getting the contravariant matcher to work with
assert_that(). I was never able to work it out.mezuzza commentedon Dec 8, 2022
Maybe I'm missing something, but
Doesn't give me any errors.
Was there a specific case that fails?
brunns commentedon Dec 8, 2022
It may be be me who is missing something! Or perhaps the overrides are the problem? But in any case, I can't get this working in the real codebase.
Do you want to try it? I'm sure a PR would be gratefully received as long as it's backward compatible.
mezuzza commentedon Dec 15, 2022
I can give it a shot later when I get some time. Probably won't be for a bit though.
brunns commentedon Dec 15, 2022
Thanks, I appreciate it.
Make Matcher contravariant to fix type checking (issue hamcrest#222)
Make Matcher contravariant to fix type checking (issue hamcrest#222)
Merge pull request #273 from brunns/fix-matcher-contravariance-issue-222
Mypy 2 upgrade (#301)