Understanding mypy coverage report coloring (Any Types, Omitted Generics)

Viewed 317

I'm getting started with type checking in Python and using the mypy tool. I've run a mypy html coverage report on a snippet of my code and see the following:

enter image description here

If I hover over this portion of the code it says "Any Types on this Line: Omitted Generics(x2)". My question is, what exactly does this mean? While mypy doesn't return any errors, I'm curious as to whether the fact that this is colored yellow means that I could (and should) do better so that it is colored green.

1 Answers

First off, it's discouraged to just post images in your question - here it's useful because you're trying to figure out why your IDE is rendering something this way, but it would be very helpful to people who use screen readers to summarize what is going on in the image.

Second, you didn't mention which IDE generated the image you're looking at or the message that appears when you hover over it, so I can't help you with those specifics.

However, third, and hopefully this helps you actually resolve your confusion: list[dict] isn't the proper way to give mypy (or any other Python static typechecker for that matter) a type hint that this function returns a list. You should at mininum use List[dict] instead (List is provided by the typing library), or, for even more brownie points, be specific about what the dicts hold with List[Dict[key_type, value_type]].

Related