Skip docstring first-word capitalization for code identifiers and URLs (#793)

This commit is contained in:
Glenn Jocher
2026-07-06 18:29:14 +02:00
committed by GitHub
parent c52e654af9
commit 3b6e36bed6
3 changed files with 15 additions and 2 deletions
+1 -1
View File
@@ -28,4 +28,4 @@
# ├── test_summarize_pr.py
# └── ...
__version__ = "0.2.19"
__version__ = "0.2.20"
+2 -1
View File
@@ -380,7 +380,8 @@ def format_docstring(
single_ok = ("\n" not in text) and not has_section and not has_list
if single_ok:
words = text.split()
if words and not words[0].startswith(("http://", "https://")) and not words[0][0].isupper():
core = words[0].rstrip(".") if words else "" # ignore terminal dots so only interior ones mark identifiers
if core.islower() and not any(c in core for c in "_./`("):
words[0] = words[0][0].upper() + words[0][1:]
out = " ".join(words)
if out and out[-1] not in ".!?":
+12
View File
@@ -26,3 +26,15 @@ def test_docstring_formatter_keeps_simple_docstrings_single_line():
text = "Make the live fp32 EMA genuinely non-finite while the model stays finite (sticky-NaN on a finite-loss run)."
assert format_python_docstrings.format_docstring(text, 8, 120, '"""', "") == f'"""{text}"""'
def test_docstring_formatter_preserves_identifier_first_words():
"""Test that code identifiers, dotted names, and URLs are not capitalized as first words."""
for text in (
"process_mask/process_mask_native/scale_masks must handle 0 detections without crashing.",
"np.array inputs are converted to tensors.",
"https://ultralytics.com hosts the docs.",
"iOS builds are not supported.",
):
assert format_python_docstrings.format_docstring(text, 8, 120, '"""', "") == f'"""{text}"""'
assert format_python_docstrings.format_docstring("done.", 8, 120, '"""', "") == '"""Done."""'