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

Vendored modules (hypothesis/vendor/pretty.py) produce type errors with Mypy #1359

Closed
PiDelport opened this issue Jun 26, 2018 · 2 comments
Closed

Comments

@PiDelport
Copy link
Contributor

As of the 0.62.0 release, when type-checking a Hypothesis-using project with Mypy, at least the pretty vendored module raises (valid) type errors:

…/hypothesis/vendor/pretty.py:501: error: Module has no attribute "InstanceType"
…/hypothesis/vendor/pretty.py:503: error: Incompatible types in assignment (expression has type "Tuple[Callable[[object], str]]", variable has type "Tuple[Callable[[object], str], Any]")
…/hypothesis/vendor/pretty.py:764: error: Cannot assign to a type
…/hypothesis/vendor/pretty.py:764: error: Cannot assign multiple types to name "_exception_base" without an explicit "Type[...]" annotation
…/hypothesis/vendor/pretty.py:791: error: Module has no attribute "DictProxyType"
…/hypothesis/vendor/pretty.py:792: error: Module has no attribute "DictProxyType"
…/hypothesis/vendor/pretty.py:794: error: Module has no attribute "ClassType"
…/hypothesis/vendor/pretty.py:795: error: Module has no attribute "SliceType"
…/hypothesis/vendor/pretty.py:800: error: Name 'xrange' is not defined
…/hypothesis/vendor/pretty.py:801: error: Name 'long' is not defined
…/hypothesis/vendor/pretty.py:802: error: Name 'unicode' is not defined
…/hypothesis/vendor/pretty.py:808: error: Need type annotation for '_deferred_type_pprinters'

(The errors are things like Python 2 compatibility code that isn't valid under Python 3.)

I'm guessing this is due to the py.typed marker, which counts everything under the hypothesis
package to be type-checked.

The workaround is to explicitly ignore the module's errors in the project's mypy.ini:

[mypy-hypothesis.vendor.pretty]
ignore_errors = True

However, projects should not be expected to do this in general: the fix should be to explicitly annotate the code in question (or the whole module, pending python/mypy#626) with # type: ignore.

@PiDelport
Copy link
Contributor Author

As an aside, the Hypothesis CI should probably run Mypy too, to avoid this kind of problem.

@Zac-HD
Copy link
Member

Zac-HD commented Jun 26, 2018

Ack! You're entirely right, thanks for reporting this. We actually do run Mypy in CI... but with the vendor directory ignored. Whoops.

I'll fix this as a matter of priority.

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