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

Change untyped libraries from error to warning by default #10456

Closed
CrazyPython opened this issue May 11, 2021 · 2 comments
Closed

Change untyped libraries from error to warning by default #10456

CrazyPython opened this issue May 11, 2021 · 2 comments
Labels

Comments

@CrazyPython
Copy link

CrazyPython commented May 11, 2021

Feature

Change "found module but no type hints or library stubs" to a warning, not an error.

Change this:

lib.py:22: error: Skipping analyzing 'regex': found module but no type hints or library stubs
lib.py:136: error: Incompatible types in assignment (expression has type "float", variable has type "int")
persist.py:203: error: Skipping analyzing 'discord': found module but no type hints or library stubs
Found 2 errors in 2 files (checked 1 source file)

Into this:

lib.py:22: warning: Skipping analyzing 'regex': found module but no type hints or library stubs
lib.py:136: error: Incompatible types in assignment (expression has type "float", variable has type "int")
persist.py:203: warning: Skipping analyzing 'discord': found module but no type hints or library stubs
Found 1 error in 1 files (checked 1 source file)

Pitch

The vast majority of Python libraries lack type hints. Outside a group of highly skilled Pythonistas, few use type hints, partly because libraries don't use it. Showing that libraries fail to use type hints as an error dissuades new users from using mypy and hurts mypy adoption. Even without 3rd party type hints, type hinting a library internally can still be quite useful.

It also makes it harder to distinguish from actual typecheck errors.

Evidence

A lack of typing is the #1 most cited reason people avoid Python for large, "scalable" projects, and prefer Java, Go, or another statically typed language. On multiple occasions I have rebutted them by saying mypy exists and works well. Most of the time, the response is that most Python libraries do not support mypy. However, mypy can help people write Python in larger codebases without needing library type stubs.

@Bryant-Yang
Copy link

This feature should be very useful.
By now, I had to set ignore_missing_imports=True.
Or use "grep -v 'found module but no type hints or library stubs'" to check bad import of my own code.

@CrazyPython CrazyPython changed the title Change untyped libraries from error to warning Change untyped libraries from error to warning by default May 14, 2021
@hauntsaninja
Copy link
Collaborator

I added support for this in #14740, use --disable-error-code=import-untyped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants