Suggest super functions marked with overload #2622
Replies: 7 comments
-
Thanks for the suggestion. Currently, pylance offers to complete a function override for non-overloaded functions. Overloaded functions present an interesting problem, especially if the overloads come from a type stub file. The problem is that the type signature of the runtime function or method isn't specified in a type stub. So there's no way for pylance to know what signature to use in the completion. If the base class is defined in a source file (rather than a stub), then it will have both overloads and a runtime implementation. In that case, Pylance could offer the runtime implementation's signature in the completion. But that wouldn't help in either of the cases you mentioned above because the type definitions for |
Beta Was this translation helpful? Give feedback.
-
I don't know if it would work, but would it be possible to add a function signature more than ones? I theory I'm thinking about something like the hover hint below where you can cycle though the different overloads. However, I don't believe that's possible at the moment, that's why I'm suggesting multiple entries. To select the correct one a user could use the extended hint. |
Beta Was this translation helpful? Give feedback.
-
With overloaded functions, the type signature of the runtime implementation generally doesn't match any of the overload signatures. It's a combination of all of them. |
Beta Was this translation helpful? Give feedback.
-
I see. What about just suggesting the function arguments without type hints (or with Any) in those cases? |
Beta Was this translation helpful? Give feedback.
-
I don't think that would work because overload signatures often omit some parameters (those that have default values in the runtime signature) or use *args/**kwargs. |
Beta Was this translation helpful? Give feedback.
-
How often do you find that you need to override an overloaded method? I can't remember ever doing this myself, but maybe my usage differs from yours. |
Beta Was this translation helpful? Give feedback.
-
Not that often, so it certainly wouldn't be worth finding a solution just for me alone. With all the issues I open it's mostly that, while working on some other project, I find these little things where I constantly imagine they should work but they don't. I know how hard it is to get good bug reports and if I open one maybe somebody finds it relevant enough and it will eventually get fixed. If it's something that really bothers me, I'm even willing to spend some of my free time to fix it myself if I can. Just to get back to the topic, this one definitely is not :) |
Beta Was this translation helpful? Give feedback.
-
Environment data
Expected behaviour
Pylance should suggest all functions of a super class which could be overwritten.
Actual behaviour
Only functions that don't have an
overload
decorator are suggested.Logs
--Code Snippet / Additional information
ArgumentParser.parse_args()
Typeshed - argparse.pyi
Just to give another example:
bytes.__getitem__()
Typeshed - builtins.pyi
Beta Was this translation helpful? Give feedback.
All reactions