Is there any tool that can report "type coverage" of a project?

I was reading an article this morning that linked to this tool for TypeScript:

This tool will check type of all identifiers, the type coverage rate = the count of identifiers whose type is not any / the total count of identifiers , the higher, the better.

And I wondered if there is any similar tool for Python projects?

I think we can tell e.g. mypy to be strict about untyped identifiers and raise errors for them. We could then count the errors.

But what if we wanted to run it more leniently but still collect a soft metric about the state of our code?

Pyright can output a “type completeness” score. This measures the percentage of public symbols (functions, methods, globals etc) that are fully typed. It’ll also warn about any definitions that would require inference, and therefore might vary across different type checkers or versions.


mypy can generate type checking coverage reports. See these options: The mypy command line - mypy 1.5.1 documentation

(I’ll caveat: I haven’t really used these myself)