Given the results
dict, if I want to get a sequence containing the keys of that dict sorted by the values, I can use the simple idiom: sorted(results, key=results.get, reverse=True)
The trouble is that, assuming that the keys aren’t a type comparable with None (and writing that type as I
), the return type of results.get is I|None
. My type checker gives me a type warning because not knowing that all the values that will be passed to results.get will make it return an I
, it deduces that an I
could be compared with None.
Is there another solution than using # type: ignore
which would shut off all checks on that line ?
Another solution which would preferably be simple both in writing and in complexity.