`reportAny` false positive when annotating a value from a dict of [x, Any] starting 1.28.5
Description
from typing import Any
d: dict[str, Any] = dict(a=1) # pyright: ignore[reportExplicitAny], dict from a lib I don't control
a: int = d["a"]
raises Type of "a" is Any (reportAny) starting 1.28.5
Latest pyright does not trigger on this.
thank you for the report
it is indeed true that d["a"] is of type Any, one immediate concern that i can see is that it is the variable that is being reported, not the assigned expression
But isn't manually type-hinting the way to tell the linter that we know what type it is?
Current pyright (and basedpyright 1.28.4) behavior is if you type hint something coming from Any, it treats it as such.
Also there's nothing about this behavior change in the changelog from 1.28.5 which to me hints at it not being intentional.
But isn't manually type-hinting the way to tell the linter that we know what type it is?
yes, but the type is still Any. the purpose of the rule is to inform the user that a value is dangerous and unchecked. in your case, it might seem trivial, you understand that the value is unsafe because you have annotated it as such, but this unsafety very quickly infects an entire project, defeating the usefulness of type safety
Current pyright (and basedpyright 1.28.4) behavior is if you type hint something coming from Any, it treats it as such.
pyright doesn't have this check at all, it's a basedpyright exclusive
Also there's nothing about this behavior change in the changelog from 1.28.5 which to me hints at it not being intentional.
this is concerning, and we will look into it
if you have any suggestions for improvments to how we handle this situation, we are very interested in hearing your opinions 🙂
This is the result of a bug fix from upstream to the reportUnknown... rules that also applied to our reportAny rule. See https://github.com/DetachHead/basedpyright/issues/1218#issuecomment-2801779652