-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[v2.12 Regression] Asterisk argument mising-param-doc
vs anomalous-backslash-in-string
#5406
Comments
Thanks for the detailed report! I think this should be fixable as all styles have different checkers. Do you have any good links on Sphinx style documentation I could link to in the docstring of the new test cases? I think the main cause of this regression was that I did not know what style required what and wasn't able what Sphinx requires. I know I found it quite difficult to find authoritative style guides for some of these edge cases for all three styles. |
Thanks for the fast response @DanielNoord!
You and me both! Unfortunately, I don't. I actually changed my docstrings to the second syntax before I realized |
No luck. I've opened sphinx-doc/sphinx#9893. |
Thanks! Let's await their response before applying a fix here. Perhaps they will also start allowing it, that would make sense to me. |
I think I encountered this. The codebase in question has other checkers, so I had to add |
To expand on what @mwchase said We originally had kwargs without the prepended **
With 2.12.1 this raises
I think this is a style choice as to if the asterisks should be included and that probably needs a Boolean option. But I don't have a problem including them. The correct way to fix this is a single backslash to tell Sphinx the asterisks are literal and not formatting and the r prefix because pydocstyle requires it, which is appropriate.
The problem is Pylint still raises
It looks like there's some inconsistency in how this is being checked and the backslash isn't being handled correctly in the parameter names. |
I think we should be able to make Would this be an okay solution for all involved? |
That works for me |
Since sphinx doesn't currently accept sphinx-style Requiring asterisks makes sense to me. |
I assume it works in Google and NumPy style because Napoleon can handle the escaping during pre-processing. Like, in https://github.com/sphinx-contrib/napoleon/blob/master/sphinxcontrib/napoleon/docstring.py#L333. If some extension could support the same rewrites in |
I think this should do the trick: diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py
index 18c2ec0b..8edde4f7 100644
--- a/pylint/extensions/_check_docs_utils.py
+++ b/pylint/extensions/_check_docs_utils.py
@@ -280,9 +280,9 @@ class SphinxDocstring(Docstring):
\s+
)?
- (\*{{0,2}}\w+) # Parameter name with potential asterisks
- \s* # whitespace
- : # final colon
+ (\\\*{1,2}\w+|(?<=\s)\w+) # Parameter name with potential asterisks
+ \s* # whitespace
+ : # final colon
"""
re_param_in_docstring = re.compile(re_param_raw, re.X | re.S) I'm waiting on #5450 to be merged to make use of the functional test framework to test this. I think we should be able to still fit this in |
This does not look like it should be resolved yet. Although Most developers, including myself, will not want to update entire code bases to add |
@fmigneault Although I agree that this might be a bit of work for any existing codebase, I do think that requiring There is no real authority on this (and there has been no response to sphinx-doc/sphinx#9893), but there is an example within the Sphinx ecosystem which says that they should be there, see this example. The same goes for Numpy, which style guide states that they should be included here. Therefore, the main docstyle guides (we support) seem to lean towards actually requiring them. It is a shame that Obviously I am open to any counter-arguments as to why they shouldn't be required, but reducing the amount of false negatives (or introducing a new checker) will sadly always require some work from users that relied on |
It is not just a little work, it is massive work. Every code base use Given that At the very least, |
Although I can understand that you would be hesitant to do so I think with some regular expressions and replace all you should be able to fix most cases (and then let
The necessity of escaping
I think there is a reason why both previously mentioned style guides requires the |
I disagree with that. When the parameter is used in the code, only the parameter name itself is used without Many IDE (eg: PyCharm) explicitly warns about missing parameters in docstrings when adding the |
This would be a reason for me to allow no-asterisks: incompatibility with IDEs is indeed a problem. @Pierre-Sassoulas also uses PyCharm. Do you see the same problem? |
Pycharm raises
To be honest I'm not using this style of docstring myself which is why I did not realize this before. |
Chiming in as a regular pylint user: we here (@ satelligence) would also appreciate it if the possibility to omit the */** from the docstrings would return. Either optionally, or by default. Until this is resolved, we'll probably stick to pylint 2.11.x |
Sorry @vincentschut and @fmigneault I should have indeed reopened this. I'm adding this to I'm quite busy myself, so I won't get to this soon (and won't be able to get it in a patch version). But if someone is willing to open a PR I think we can review this quickly and get it in |
Thanks for reopening. |
I think that should do the trick. We just need a test as well, which can probably be based on some of the other tests. Searching for *args in the test directory should point you to the current test files I think. |
Hi there, please can you confirm what the usage will be following this issue - I've struggled to follow the conversation exactly. How should we document *args & **kwargs following this release? |
I have just opened a PR with a fix for the issues discussed here. |
Bug description
Take the following function:
The
args
parameter can be added to the docstring (in Sphinx style) in 3 ways::param args: Arguments to print.
This works with sphinx and pylint 2.11.1 and earlier (before Fix asterisks parsing of
mising-param-doc
#5175). With pylint 2.12.0 and later it causes the following errors:param *args: Arguments to print.
This works with pylint, but causes the following error with sphinx:
:param \*args: Arguments to print.
This works with sphinx, but causes the following error with pylint:
Configuration
Command used
Pylint output
For method 1 (with pylint 2.12.1):
For method 2:
No errors.
For method 3:
Expected behavior
I would expect pylint to accept the syntaxes that Sphinx does (1 and 3 from above).
I'd prefer if pylint rejected syntaxes which Sphinx rejects (2 from above). However, since Sphinx accepts asterisk-without-backslash for Google- and NumPy-style docstrings (as requested in #3733) if these can't be easily distinguished by pylint, it'd probably be preferable to accept them all.
Note: This issue has affected other linters and it was noted that sphinx.ext.napoleon (which adds support for NumPy and Google style docstrings) auto-escapes * at the beginning of arguments: peterjc/flake8-rst-docstrings#18 (comment) This is likely why those styles differ from Sphinx style in what is accepted.
Pylint version
OS / Environment
Debian GNU/Linux bookworm/sid
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: