Repository navigation
Add Pylint checker and test for unescaped underscore symbols in docstrings - #8514
BretMishler wants to merge 8 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8514 +/- ##
========================================
Coverage 99.58% 99.59%
========================================
Files 1137 1139 +2
Lines 105119 105392 +273
========================================
+ Hits 104687 104961 +274
+ Misses 432 431 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Scope Question: The checker runs on every file pylint lints, including (a) keep it uniform as is, which is simpler and consistent with the repo's other docstring lint rules, or (b) skip test files so it only enforces where rendering matters? Happy to do either; with (b), the test-file edits can stay as cleanup. |
|
Hi @BretMishler – thank you for tackling this! Before going much further, I have two higher-level requests/feedback.
|
|
Whoops, I missed your questions earlier:
Though it's going to be more annoying for human devs, I'd favor option (a). More uniformity ⟹ fewer exceptions to remember ⟹ less cognitive load. @pavoljuhas @arettig What do you think? (For speed, you can also simply can use thumbs up/down to indicate agreement/disagreement.) |
| """ | ||
| lines = _splitlines_lf(docstring, keepends=True) | ||
| indents = [len(line) - len(line.lstrip(" ")) for line in lines[1:] if line.strip()] | ||
| base_indent = min(indents) if indents else 0 |
There was a problem hiding this comment.
nit -
| base_indent = min(indents) if indents else 0 | |
| base_indent = min(indents, default=0) |
+1
It may be worthwhile to look at the implementation of docstring checks in the pylint itself - for example, Perhaps we could reuse that machinery, at very least the Also, if getting the exact |
Fixes #1189
This adds a Pylint checker for symbols like
__init__,_unitary_, and_private_helperin Python docstrings that DevSite renders as bold or italics outside code formatting.Basically, how the check works:
astandtokenizeto extract module, class, function, and attribute docstrings plusdocument(...)strings with exact source line and column offsets.```and~~~) and indented code blocks, doctest blocks (including continuation and output lines up to a blank line), inline backticks, URLs, and LaTeX math.__foo__), single-underscore (_foo_), and leading/trailing underscore symbols (_foo_bar,foo_bar_), skipping parameter names inArgs:/Attributes:sections.The checker is registered in
pyproject.tomlsocheck/pylintshould enforce it, andexamples/bb84.py's example output block is wrapped in a code fence so its underscore bitstrings render as literal output.