Comments (7)
Hi @Zeitsperre thanks for the nice example.
This is certainly feasible - I wrote a merge-style like this a few years ago, and it wasn't all that bad to implement (unfortunately there is no trace of it...). That being said, you could certainly leverage the docstring parsing tools that are included in this library to implement this relatively easily.
Specifically parse_napoleon_doc
will give you a dictionary containing all of the sections of the parsed docstring. You can access the Parameters
section of this and parse it for the individual parameters within and do a specialized merge for this.
Your use case with a wrapper is an interesting one that I hadn't considered. I would definitely be open to adding this merge-style to the zoo.
from custom_inherit.
Ok sounds pretty cool. I'll see when I have time to work on this but I'll start by forking master and examining the algorithm based off your test examples. What would be good to know going in is how best to handle the order of signature elements (ie: parent args --> child args --> parent kwargs --> child kwargs).
Is there currently a way to link the entries under Parameters to their call signatures to know which is an arg/kwarg?
from custom_inherit.
Presently, is no way to do that. I would be open to making these call-signatures available to the merge styles in version 3.0
after dropping support for Python 2.7.
So that I have more context: in what case would you want to know if an argument is an arg/kwarg, for the purpose of docstring-merging?
from custom_inherit.
I was thinking along the lines of parameter entry order. It would be good to have the signatures to appear in such a way that args appear before kwargs.
On second thought, I could see this getting complicated as args depend on order and if two functions are mixing args in their docstrings, it could give the impression that the function call is set up in that order. To build on the example above, the problem would be how to regulate the order in which the Parameters appear.
Let's suppose that z
is an arg of func foo
and y
is a kwarg. How would one order the following signatures in the docstring?
Parameters
----------
x : str (child arg)
some string
y : str (child kwarg)
some other string
z : int (parent arg)
some number
I feel now that this might be beyond the scope of custom-inherit. Mixing signatures demands kwargs.
from custom_inherit.
Hi all,
I am also very interested in such a option, and I developed three new built-in styles that allow such inner section merging. You can find it on my repo https://github.com/Boubsi/custom_inherit/tree/inner_section_merging.
The new built-in styles are called (for now) "numpy_with_merge"
, "numpy_napoleon_with_merge"
and "google_with_merge"
.
With those styles, if there is an overlap in some section of child and parents docstrings, the resulting section will be the concatenation of parent's and child's section. It works for all sections except some sections for which it is not relevant to perform the merge (such as "Summary" or "Examples" sections.
For example, here is the docstring I wrote for the "numpy_with_merge"
style:
"""
Behaves identically to the 'numpy' style, but also merges sections that
overlap, instead of only keeping the child's section. All sections are
concerned except sections "Short Summary", "Extended Summary", "Deprecation
Warning" and "Examples" for which the 'numpy' style behaviour applies.
Example:
- parent's docstring:
''' Parent's line
Parameters
----------
x: int
description of x
y: Union[None, int]
description of y
Raises
------
NotImplemented Error
Example
-------
>>> parent_func(x=3, y=None)
NotImplementedError:'''
- child's docstring:
''' Child's line
Parameters
----------
z: Union[None, int]
description of z
Returns
-------
int
Notes
-----
notes blah blah
Example
-------
>>> child_func(x=3, y=None, z=4)
7'''
- docstring that is ultimately inherited:
''' Child's line
Parameters
----------
x: int
description of x
y: Union[None, int]
description of y
z: Union[None, int]
description of z
Returns
-------
int
Notes
-----
notes blah blah
Example
-------
>>> child_func(x=3, y=None, z=4)
7'''
What do you think about it? Should I make a merge request on this repo?
from custom_inherit.
@Boubsi this looks like a nice addition to the styles. I think that it would be a convenient add-on for users who want this sort of capability.
A PR would be welcome!
from custom_inherit.
Closed by #31
from custom_inherit.
Related Issues (18)
- Show-stopping bug HOT 1
- Google-style functions using "Args:" are inherited with "Parameters:" HOT 2
- Documentation HOT 2
- Cannot remove parameters HOT 5
- It does not work with multiple inheritance (mixins) HOT 7
- Transferring ownership
- Conda-Forge Package HOT 3
- Make readthedocs page HOT 4
- custom_inherit 3.0 will drop support for Python < 3.5
- Allow docstring of __init__ to also inherit from the parent class HOT 2
- Inherit docstrings from Zope Interfaces HOT 2
- class docstring with 'numpy_merge' section order HOT 2
- Multiple inheritance HOT 5
- Fix _Store
- Whitespace stripped with numpy style causes trouble HOT 2
- Merging a google docstring with a numpy docstring
- Problem when merging with flake8 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from custom_inherit.