All Posts

Release: Static type checker in Python

Release: Static type checker in 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.

{{< highlight toml "hl_lines=8">}} version = 1

[[analyzers]] name = 'python' enabled = true

[analyzers.meta] type_checker = "mypy" {{< /highlight>}}

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 and type 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.

Get started with DeepSource

DeepSource is free forever for small teams and open-source projects. Start analyzing your code in less than 2 minutes.

Newsletter

Read product updates, company announcements, how we build DeepSource, what we think about good code, and more.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.