Replies: 1 comment
-
Pyright already has a feature called "call-site type inference". It's applied to functions and methods that have no parameter annotations. It is used at the "call site" of the function where the argument types are known. It does this in an attempt to infer the type of the call's return value. This is especially helpful for completion suggestions. This is a pretty advanced feature for a type checker. To the best of my knowledge, no other Python type checkers do it. It is found in compilers for some languages like Julia. For more details about call-site type inference, refer to this documentation. When pyright performs analysis of a function as part of call-site type inference, it suppresses all type errors that are detected during this analysis. It suppresses these errors for two important reasons:
There are probably better ways to achieve the goal of detecting bugs like this. The most straightforward way is to encourage developers to add type annotations for all input parameters. We've been talking about ways that we might help automate this through AI models, but we haven't had time to explore this in depth. |
Beta Was this translation helpful? Give feedback.
-
Wondering what's preventing having an option to do recursive analysis on calls to unannotated functions to catch the type error in the following example:
I've done some local hacking which suggest that it could be possible (by hijacking the machinery for inferring return types for calls to functions with unknown parameter types), but my gut tells me there's probably a reason I'm not privy to for this functionality not being available.
Beta Was this translation helpful? Give feedback.
All reactions