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

Package doesn't seem to be compatible with strict mypy #192

Closed
lindycoder opened this issue Dec 23, 2021 · 3 comments
Closed

Package doesn't seem to be compatible with strict mypy #192

lindycoder opened this issue Dec 23, 2021 · 3 comments

Comments

@lindycoder
Copy link

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:

  1. 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

  2. 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!

@brunns
Copy link
Member

brunns commented Mar 3, 2022

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!

@offbyone
Copy link
Member

@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.

@lindycoder
Copy link
Author

@offbyone Hi, it does seem to be working with latest mypy, thank you!

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

3 participants