PyHamcrest
PyHamcrest copied to clipboard
Package doesn't seem to be compatible with strict mypy
Hello!
Always been a great fan of this library!
Disclaimer: I'm new to mypy, so this might just be me lacking understadings, if so, i'm sorry i'll close this.
I'm trying to introduce mypy strict=true to my test suite and notice 2 things:
-
The documented way of importing does seem to fail on mypy.
from hamcrest import * def test() -> None: assert_that(1, is_(1))
Results in
error: Name "assert_that" is not defined.
note: vscode also does not recognize import *... unless i miss an extension other than python
-
If imported manually, there seems to be an issue with dynamically created
__all__
.from hamcrest import assert_that, is_ def test() -> None: assert_that(1, is_(1))
Results in
Module "hamcrest" does not explicitly export attribute "assert_that"; implicit reexport disabled
note: type checking works fine with
no_implicit_reexport=false
: if you don't pass a matcher to assert_that you get an error.
So i'm not sure what to make of this...
mitigation
- Setting
no_implicit_reexport=false
obviously solves the problem... but it would be better to keep it for other repos. Unless there's a way to specify this only for pyhamcrest - Using # type: ignore on the
from hamcrest import assert_that, is_
line disable the warning along with type checking
reproduce
Here's a repo with 3 files that produce error, reproduce steps are in the readme https://github.com/lindycoder/pyhamcrest-mypy-issue
Thank you very much!
Strict mode is new to me, I must say, but I'll take a look at this when I get the chance.
The import *
thing is easily fixed in a way, since that's not the best way of importing in the first place!
@lindycoder can you check with 2.0.4 please? I believe we've fixed this in the latest release, but I would like to be sure.
@offbyone Hi, it does seem to be working with latest mypy, thank you!