-
Notifications
You must be signed in to change notification settings - Fork 4
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
Docstring inheritance #17
Comments
Firstly, I really like the idea of not having to declare a docstring to be used in a downstream class. This massively simplifies things for developers. If we could just fetch docstrings on demand at the location where they'll be used it would be vastly simpler to use. Secondly, the idea of inheriting doc strings and adding to them without having to insert the text formatting strings is another major improvement. Again, this is one less thing for devs to worry about. As you've outlined above, the Finally, as I mentioned in issue #16 I really would like to see a parameter over-write superclass info by default. We have abstract base classes and subclasses where defaults are specified, and I need the subclassed docstring to supersede the parent class. Overall, the proposed changes look great to me! |
I just changed my mind about point 2 above. I think I would prefer to have the power to insert the specific segments of a docstring in the locations I want. For instance, we have a The optimal api for my particular work flow would be something like:
In other words, in an ideal world I'd like: (a) for docrep to grab the docstrings on demand inside the child instead of devs having to specify which parts docrep grabs at the parent class level and (b) to be able to pick and choose which components get put in which locations using the current syntax, with the parsing enabled by simply adding a single, clear decorator to the function/method. Also, as I mentioned in #16, I'd like the child class parameters to overwrite the parent. |
Hey @jgostick, thanks for your thoughts on this! I think I see your point: You prefer to be a bit more explicit in the docs rather then hiding everything inside the decorator. I like your suggestion, it's intuitive and forces the developer to explicitly tell I like the syntax you propose and with the Line 19 in 6ae96d5
I propose to add three decorators in this case, with reference to the current implemented methods, that all use the params attribute. See the following table
The challenging aspect is, however, to resolve class A:
def my_method(self, a=1):
"""Do something awesome
Parameters
----------
a: int
A number
Returns
-------
int
The changed number
""""
return a + 1
class B:
@docstrings.resolve_and dedent(A=A.my_method)
def my_method(self, a=1, b=2):
"""
Do something better
Parameters
----------
%(A.parameters)s
b : int (optional, default = 2)
Another parameter
Returns
-------
%(A.returns)s
""""
return a + 1 It should also be possible to keep or delete certain parameters with this framework. In this case, I would stick to the syntax as it is currently used by keep_params and delete_params, i.e.
with this methodology of course, the check for duplicates would be something on top of the |
Hey!
There is a new feature that I would like to discuss for docrep and I'd very much like your feedback (pinging @jgostick, @mennthor, @amnona, @lesteve). It's about docstring inheritance (i.e. the
docrep.DocstringProcessor
inserts parameters based on the base class).Wouldn't it be nice to have something like
and then have
B.my_method
the same docstring asA.my_method
?inherit_parameters
andinherit_returns
would mark the method to be processed then inresolve_inheritance
(Note: this separate treatment is necessary as, during class compilation,B
is not yet defined and we therefore cannot resolve thatB
inheritsA
withininherit_parameters
).I'd like to discuss with you, how this should be set up (besides the implementation discussed above). Here are some ideas that I have and I highly appreciate your feedback and suggestions 😃
Specifying the base class
We could extend this by optionally specifying the
base
class, e.g. viaThis would then make it available for functions as well.
Replace arguments
We could also replace arguments in the sub class method (see alsp #16), e.g.
Specify parameters
I would in general use
inspect.getfullargspec
and match the parameters of the function with the parameters ofbase
. But it should also have the possibility to specify them manually, e.g. to resolve stuff like*args, **kwargs
. Here is an examplefuncb
in this case should have used the docstring of parametera
although it is not in the argspec offuncb
.The text was updated successfully, but these errors were encountered: