Disabling `reportUnusedCallResult` for specific functions
Repost from https://github.com/microsoft/pyright/issues/8650, which got rejected:
A very common use-case of
typing.assert_typeis in type tests, e.g. the NumPy type tests do this.But currently when
reportUnusedCallResultis enabled, the following codefrom typing import Literal, assert_type assert_type(0, Literal[0])results in the following pyright error:
Result of call expression is of type "Literal[0]" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)https://pyright-play.net/?strict=true&reportUnusedCallResult=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAySMApiAIYA2ANFOQM71kwD68CJAUJw03m4hIAKAAy0ipCpQDaIgLoBKTkA
This isn't only limited to
assert_type; e.g. the return value ofdict.setdefaultis also often ignored, and I'm sure there are many more cases like these.So I think that the cleanest solution would be to have a configuration option that disables
reportUnusedCallResultfor specific functions, which in apyproject.tomlcould look like:[tool.pyright] # [...] reportUnusedCallResult = true ignoreUnusedCallResult = [ "dict.setdefault", "typing.assert_type", "typing_extensions.assert_type" ] # [...]
i already raised #21 for assert_type but i like the idea of making it configurable
i already raised #21 for
assert_typebut i like the idea of making it configurable
It must be true then when they say that "great minds think alike" 😉 .
I would very much like to see 'reportUnusedCallResult' enabled by a decorator, as a way of gently introducing this check to an existing code base.
another example of this, list.pop(), was mentioned by @denballakh
There is file.write(...) as well.
Result is almost never used.
I suppose it would be good to have a decorator for annotating first party code, and a config option for third party code
I suppose it would be good to have a decorator for annotating first party code, and a config option for third party code
and 2nd party code...?