-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How should we annotate functions that forward to their superclass? #1471
Comments
If you're using a smart editor or language server, it should take little or no effort to duplicate the signature when overriding a method. For example, with pylance installed in VS Code, you can type |
Thanks @erictraut, that's a good point. I use NeoVim, which afaik doesn't have this functionality. I'm sure you're aware, but just for any other readers, the limitations of copying the base class signature include:
|
@NeilGirdhar Chiming in: I use NeoVim too, and with these plugins, I do get the
Using |
On this topic, I think there is a need for a way to forward parameters annotations in general, not just for the purpose of inheritance. For example, I often write pure helper functions that are called inside a method that take the same parameters as the method. |
A plain-text copy of another library's source code is a flaky error-prone thing to maintain, even if it is possible to generate one. You might end up having to import a big pile of weird internal details that the upstream library uses in their type annotations that might break at any time, and are otherwise irrelevant to your application. For example, consider the case of writing a type stub for Similarly, imagine a case where I'm writing my own subclass of I think the above cases are common enough and painful enough that something like |
Consider this real code:
If we want full annotations for
TrainingInferenceManager.__init__
, we currently need to duplicate all of the superclass's parameters. I suggest addingtyping.SuperKwargs
that stands in place of them.(This could be made more complicated by allowing the child class to synthesize some of the parameters.)
Related: python/mypy#8769
The text was updated successfully, but these errors were encountered: