I'm going through an exercise of adding type hints through a large codebase, but I'm sometimes seeing that less-than-optimal type hint worsens IDE recommendations:
before, the IDE is able to figure out that y['result'] is a string:
after, it does not know:
I know I could fix this with a more specific type hint:
But in general, is there a way to know if the type hint being added is less specific that what the LSP was able to infer from the code?
I've looked to add very detailed type hints to avoid this issue (e.g. subclassing TypeDict), but keen to avoid the effort if the LSP is able to figure things out itself.
EDIT #1:
To clarify, I'm asking if there is a way to warn the user when they are adding a type hint that will worsen the LSP's understanding of the code:
We have warnings when the type hints contradict the code:
What I'm looking for is some warning for when the type hint is worse than no type hint at all.
EDIT #2:
To elaborate further, you can see here that the LSP was easily able to infer a pretty detailed return type.
Which would have been lost if the user added a "bad" type hint.
But I take the overall feedback, maybe this is an ask to the pylance project more than a stack overflow question.