-
Notifications
You must be signed in to change notification settings - Fork 68
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
Method to ignore portions of docstring [Community Feedback] #144
Comments
Issue #82 was requesting the same/similar functionality as this issue, so #82 was closed to this issue. The solution proposed by the author of this issue is to use regex to ignore certain patterns. Two issues I have with this approach:
We can't make that assumption for every use case.
sed is your friend and can add the decorators to chunks of code based on the patterns you want to ignore. If there are multiple patterns you wanted to ignore, it could become unwieldly to manage. The proposed solution would be to introduce decorators similar to other autoformatting tools like black and yapf:
For example:
The only problem I encounter with the quick example is pydocstyle raising a I'm going to pin this issue and ask the user base for feedback. |
I can see use cases that would benefit from the fine grained control that decorators would give. I think for my use case it would be better to wait for docformatter to support Google docstrings rather than change all the docstrings to add decorators to ignore |
When a simple issue requires such an elaborate solution, users tend to ignore the tool in the first place. It is not maintainable nor practical. I will be waiting for the second solution, you have proposed. |
I think it should be a priority to get to get correct wrapping for google style docstrings sections as reported in #174 . The linked issue doesn't allow refactoring of basic syntax; so introducing additional syntax as proposed by this FR will clutter the docstrings without solving essential problems.
This should never be the case to begin with and the FR gives no practical example. Considering the Napoleon-Sphinx configuration and autodoc extension configuration are feature rich most of the rendering is done by the documentation builder and any additional complexity is preferably exterior to the docstring and put in the reST files. The only motivation I've seen mentioned consistently for keeping a field list or a docstring section with some formatting that "shouldn't be touched" (as said in this FR) is by users who want to document their code using Hence, while the FR seems reasonable at first glance I don't see a real need for it. There's an additional problem, inserting additional markup into the docstring seems to solve a problem but there's no telling if it won't break any of the many 3rd party extensions out there that parse docstrings in their documentation build process. So any functionality gained by adding this feature to docformatter is likely to be unusable because it'll break other tools further down the workflow. |
Support for Numpy and Google style docstrings are next up on the docket. Actually, I've already started working on that, but bugs take priority over new features.
I'm not sold on the use of decorators either, but issue #126 is a potential use case where a decorator might be the best approach. I don't think another argument (e.g.,
I agree with you. I suspect a decorator could/would booger up pydocstyle as well. |
The best solution would be Google docstring support. This was just a suggestion for an interim solution not knowing how long it would be before Google docstring support is completed. Happy to close this issue if the emphasis is now on adding Google docstring support. Presumably that would fix the handling of docstrings like this?
|
Storing example responses in docstrings is dumb, but there is no nice way to keep it on while avoiding formatting that makes them incomprehensible like: - """ - Response of Yeelight Dual Control Module - { - 'id': 1, - 'result': [ - {'did': 'switch_1_state', 'siid': 2, 'piid': 1, 'code': 0, 'value': False}, - {'did': 'switch_1_default_state', 'siid': 2, 'piid': 2, 'code': 0, 'value': True}, - {'did': 'switch_1_off_delay', 'siid': 2, 'piid': 3, 'code': 0, 'value': 300}, - {'did': 'switch_2_state', 'siid': 3, 'piid': 1, 'code': 0, 'value': False}, - {'did': 'switch_2_default_state', 'siid': 3, 'piid': 2, 'code': 0, 'value': False}, - {'did': 'switch_2_off_delay', 'siid': 3, 'piid': 3, 'code': 0, 'value': 0}, - {'did': 'interlock', 'siid': 4, 'piid': 1, 'code': 0, 'value': False}, - {'did': 'flex_mode', 'siid': 4, 'piid': 2, 'code': 0, 'value': True}, - {'did': 'rc_list', 'siid': 4, 'piid': 2, 'code': 0, 'value': '[{"mac":"9db0eb4124f8","evtid":4097,"pid":339,"beaconkey":"3691bc0679eef9596bb63abf"}]'}, - ] - } - """ + """Response of Yeelight Dual Control Module { 'id': 1, 'result': [ {'did': + 'switch_1_state', 'siid': 2, 'piid': 1, 'code': 0, 'value': False}, {'did': + 'switch_1_default_state', 'siid': 2, 'piid': 2, 'code': 0, 'value': True}, + {'did': 'switch_1_off_delay', 'siid': 2, 'piid': 3, 'code': 0, 'value': 300}, + {'did': 'switch_2_state', 'siid': 3, 'piid': 1, 'code': 0, 'value': False}, + {'did': 'switch_2_default_state', 'siid': 3, 'piid': 2, 'code': 0, 'value': + False}, {'did': 'switch_2_off_delay', 'siid': 3, 'piid': 3, 'code': 0, 'value': + 0}, {'did': 'interlock', 'siid': 4, 'piid': 1, 'code': 0, 'value': False}, + {'did': 'flex_mode', 'siid': 4, 'piid': 2, 'code': 0, 'value': True}, {'did': + 'rc_list', 'siid': 4, 'piid': 2, 'code': 0, 'value': '[{"mac":"9db0eb4124f8","ev + tid":4097,"pid":339,"beaconkey":"3691bc0679eef9596bb63abf"}]'}, ] }""" Somewhat related to PyCQA/docformatter#144
I would still find it useful to be able to tell docformatter somehow to ignore Args: onwards in the absence of full Google docstring support. Perhaps the first pass of Google docstring support could be to simply ignore Args: and all that follows so that at least any paragraphs before Args: are wrapped correctly. |
@mcarans I've thought about this further and I think the most reasonable solution would be a Your proposal of excluding only the args section or the whole docstring could be two separate |
Just wanted to add my two cents / question, since this is a "fresh issue". Googled "ignore part of docstring" as I was hoping to have autodoc ignore the method-part of the class-docstring to maybe avoid this. Kinda want to keep it as documentation for the users about the classes. Anyone got any workarounds for this, should I just delete the method-section of my class-docstring while I wait for something that can be used for this? klass\classes\codes.py:docstring of klass.classes.codes.KlassCodes.change_dates:1: WARNING: duplicate object description of klass.classes.codes.KlassCodes.change_dates, other instance in reference, use :no-index: for one of them |
@aecorn the issue you're describing isn't related to docformatter but it's about how you write the docstrings and
Google your warning on Stack Overflow as there are several possible configurations that can lead to it. |
For my use case to exclude Args and everything following, would that mean it looks like the following?
|
@mcarans Assuming a
I think that since we're dealing with docstrings, the right solution would be somethings like Poetry's include and exclude, so for example where Poetry uses: [tool.poetry]
# ...
include = [
{ path = "tests", format = "sdist" },
{ path = "for_wheel.txt", format = ["sdist", "wheel"] }
] docformatter could use an exclusion list dictionary mapping qualified names (e.g. [tool.docformatter]
# ...
exclude = [
{
"moduleA.classB": ["Args", "Yields"],
"moduleA.classB.methodC": ["Args",],
"moduleD.functionE": ["Keyword Args", "Returns"],
"moduleF": ["Returns",],
}
] This does come with one serious difficulty: It's likely not precise enough to bulk-exclude one docstring section by name in all modules. How to resolve the filename when there may be files with the same name? I don't think it makes much sense using filenames but instead Python qualified names should be used. (However, a user may also want to format modules that aren't importable and aren't on So what's the solution for this? Can we say that only importable objects should be formatted if included in |
While this is optimal in allowing more fine grained per module exclusions, would it be quite a lot of work to implement? If so, then could the first iteration just do global exclusions? |
It would be useful to have a feature to tell docformatter to leave part of the docstring alone. For example, someone may have manually set up part of the docstring exactly as they want it and don't want it to be touched.
This issue follows from and continues the discussion here.
The proposal in that comment suggests adding
# docfmt: off
and# docfmt: on
to the docstring. Assuming the same part of every docstring needs to be ignored, the problem is that it requires changing every docstring to add those comment directives which is not practical for a large project and there is the possibility that the directives will confuse other tools that parse the docstring. I think there needs to be a way to globally set whether docformatter ignores part of each docstring without needing to modify every docstring in a project.The text was updated successfully, but these errors were encountered: