Release: Static type checker in Python
The Python analyzer now supports type checking with mypy.
- By Srijan
- ·
- Product
- Releases
- Python
Static type checking has taken the Python world by storm lately, with several engineering teams implementing it at scale and driving massive value. But if you're writing type-hint annotated code in Python today, you'd have to run a static type checker manually, as part of your CI or your local machine.
Well, no more! We're excited to announce that static type checking for Python is now available on DeepSource, powered by mypy. And how do you use it? By just adding a single line in your .deepsource.toml
.
version = 1
[[analyzers]] name = 'python' enabled = true
analyzers.meta type_checker = "mypy"
If you happen to have a mypy.ini
in your repository for your typing configuration, DeepSource will honor that. Read all about it in the docs.
Issues detected by the type checker
At the time of writing this, the checker detects 80+ typing related issues which are all categorized as Type Check
issues.
Here are some of the issues to give you an idea:
Issues with wrong type hint implementation
- Inconsistent use of
type annotation
andtype comment
- Invalid return
type hint
for generator function - Unsupported
Type
declaration - Use of deprecated type hint
Issues in type annotated code
- Missing return value in a function
- Unexpected return value
- Incompatible return value type
Other issues
- Unnecessary suppression of type checking issue
- Invalid type comment
Silencing type check issues
To silence issues raised by the type checker on a particular line, add # type: ignore
or # skipcq: TYP-001
at the end of the line. To read more on silencing issues, follow this article.
With the addition of type checker, our Python analyzer is even more powerful now, and we can't wait for you to use it! Check out the docs for more details on enabling the Python analyzer and type checker.