format-docstring 0.2.3__py3-none-any.whl → 0.2.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- format_docstring/line_wrap_numpy.py +41 -8
- {format_docstring-0.2.3.dist-info → format_docstring-0.2.4.dist-info}/METADATA +1 -1
- {format_docstring-0.2.3.dist-info → format_docstring-0.2.4.dist-info}/RECORD +7 -7
- {format_docstring-0.2.3.dist-info → format_docstring-0.2.4.dist-info}/WHEEL +0 -0
- {format_docstring-0.2.3.dist-info → format_docstring-0.2.4.dist-info}/entry_points.txt +0 -0
- {format_docstring-0.2.3.dist-info → format_docstring-0.2.4.dist-info}/licenses/LICENSE +0 -0
- {format_docstring-0.2.3.dist-info → format_docstring-0.2.4.dist-info}/top_level.txt +0 -0
|
@@ -464,19 +464,39 @@ def _standardize_default_value(line: str) -> str:
|
|
|
464
464
|
>>> _standardize_default_value('arg : bool, default: True')
|
|
465
465
|
'arg : bool, default=True'
|
|
466
466
|
"""
|
|
467
|
+
colon_idx = line.find(':')
|
|
468
|
+
if colon_idx == -1:
|
|
469
|
+
return line
|
|
470
|
+
|
|
471
|
+
# `prefix` is everything before the 1st colon (param identifier portion).
|
|
472
|
+
# We leave `prefix` untouched so arg names like `default` aren't rewritten.
|
|
473
|
+
prefix = line[: colon_idx + 1]
|
|
474
|
+
after_colon = line[colon_idx + 1 :]
|
|
475
|
+
|
|
467
476
|
# Check colon format first to avoid matching colons in space-based pattern
|
|
468
|
-
match = _DEFAULT_COLON_RE.match(
|
|
477
|
+
match = _DEFAULT_COLON_RE.match(after_colon)
|
|
469
478
|
if match:
|
|
470
|
-
before = match.group(1)
|
|
479
|
+
before = match.group(1)
|
|
480
|
+
if before.strip() == '':
|
|
481
|
+
return line
|
|
482
|
+
|
|
471
483
|
default_value = match.group(2).strip()
|
|
472
|
-
|
|
484
|
+
rebuilt_suffix = f'{before.rstrip()}, default={default_value}'
|
|
485
|
+
return f'{prefix}{rebuilt_suffix}'
|
|
473
486
|
|
|
474
487
|
# Try space-separated format with optional "is"
|
|
475
|
-
match = _DEFAULT_SPACE_RE.match(
|
|
488
|
+
match = _DEFAULT_SPACE_RE.match(after_colon)
|
|
476
489
|
if match:
|
|
477
|
-
before = match.group(1)
|
|
490
|
+
before = match.group(1)
|
|
491
|
+
if before.strip() == '':
|
|
492
|
+
return line
|
|
493
|
+
|
|
494
|
+
# ``before`` still contains any annotation text; tightening the spacing
|
|
495
|
+
# here standardizes the ``", default=..."`` suffix while preserving
|
|
496
|
+
# whatever appeared to the left.
|
|
478
497
|
default_value = match.group(2).strip()
|
|
479
|
-
|
|
498
|
+
rebuilt_suffix = f'{before.rstrip()}, default={default_value}'
|
|
499
|
+
return f'{prefix}{rebuilt_suffix}'
|
|
480
500
|
|
|
481
501
|
return line
|
|
482
502
|
|
|
@@ -730,12 +750,20 @@ def handle_single_line_docstring(
|
|
|
730
750
|
# or certain punctuation (like > and . for `>>> ` and `... ` literals)
|
|
731
751
|
# Note: We match [^`]+ (anything except backticks) and then check in the
|
|
732
752
|
# replacement function whether it's an external link (contains < followed by >)
|
|
733
|
-
# The opening backtick must not be immediately followed by _ or __ (to avoid
|
|
734
|
-
# matching the trailing backtick of cross-references like `text`_ or `text`__)
|
|
735
753
|
_RST_BACKTICK_PATTERN = re.compile(
|
|
736
754
|
r'(?:^|(?<=\s)|(?<=\()|(?<=[>.]))(?::[\w-]+:)?`(?!_)([^`]+)`(?!`)(?!__)(?!_)'
|
|
737
755
|
)
|
|
738
756
|
|
|
757
|
+
# 2nd-stage fixer for ``__dunder__`` names that slipped past the main pattern
|
|
758
|
+
# because the literal starts with an underscore. Negative lookbehinds/aheads
|
|
759
|
+
# ensure we only touch isolated single-backtick literals and leave
|
|
760
|
+
# cross-references (`name`_ / `name`__) alone.
|
|
761
|
+
_DUNDER_LITERAL_PATTERN = re.compile(
|
|
762
|
+
r'(?<!`)`(__[A-Za-z0-9_]+__)`(?!`)(?!_)(?!__)'
|
|
763
|
+
)
|
|
764
|
+
# Replacement wraps the captured dunder name (group 1) with double backticks.
|
|
765
|
+
_DUNDER_LITERAL_REPLACEMENT = r'``\1``'
|
|
766
|
+
|
|
739
767
|
|
|
740
768
|
def _fix_rst_backticks(docstring: str) -> str:
|
|
741
769
|
"""
|
|
@@ -857,6 +885,11 @@ def _fix_rst_backticks(docstring: str) -> str:
|
|
|
857
885
|
# Process the entire docstring (with REPL lines protected)
|
|
858
886
|
protected_docstring = ''.join(protected_lines)
|
|
859
887
|
processed = _RST_BACKTICK_PATTERN.sub(replace_func, protected_docstring)
|
|
888
|
+
# Upgrade remaining single-backtick ``__dunder__`` literals to double
|
|
889
|
+
# backticks; they are safe literals (not targets or refs) after the guards.
|
|
890
|
+
processed = _DUNDER_LITERAL_PATTERN.sub(
|
|
891
|
+
_DUNDER_LITERAL_REPLACEMENT, processed
|
|
892
|
+
)
|
|
860
893
|
|
|
861
894
|
# Restore REPL lines
|
|
862
895
|
result_lines = processed.splitlines(keepends=True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: format-docstring
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A Python formatter to wrap/adjust docstring lines
|
|
5
5
|
Author-email: jsh9 <25124332+jsh9@users.noreply.github.com>
|
|
6
6
|
Maintainer-email: jsh9 <25124332+jsh9@users.noreply.github.com>
|
|
@@ -3,13 +3,13 @@ format_docstring/base_fixer.py,sha256=8SVkyn2ZSwQr3-7GzxxmHVSYMHymdj6AchBxd53IA1
|
|
|
3
3
|
format_docstring/config.py,sha256=OwVasV5uX2y4gMajzY-2CIcmaSKuVUm3GxWDUdbWDcc,5586
|
|
4
4
|
format_docstring/docstring_rewriter.py,sha256=LFLPd1pMyPBQCkkNTlcMcgHWyuOLOiyJNYjz1HOeVyY,21315
|
|
5
5
|
format_docstring/line_wrap_google.py,sha256=iJdpMwCB97H3CUatmkGAexJ_J8FeWv1kMEv1UzzUvjM,587
|
|
6
|
-
format_docstring/line_wrap_numpy.py,sha256=
|
|
6
|
+
format_docstring/line_wrap_numpy.py,sha256=0Vof7ct5KAA-f_pYv94xP_xRQfKGg7YR9X8_o9gImUM,30333
|
|
7
7
|
format_docstring/line_wrap_utils.py,sha256=q59n26gzbnNgi9sWAIyX-M4MTbi5tITXVrKjJDK-Vao,28178
|
|
8
8
|
format_docstring/main_jupyter.py,sha256=3mHBeT-BVlF5R1m8xpF3OxOzQTReR6NnPjbN80eo18E,6300
|
|
9
9
|
format_docstring/main_py.py,sha256=S4zZCvJMZn8ZoDx2zYWPikKmH5-of10UTc5sad5W5v8,4597
|
|
10
|
-
format_docstring-0.2.
|
|
11
|
-
format_docstring-0.2.
|
|
12
|
-
format_docstring-0.2.
|
|
13
|
-
format_docstring-0.2.
|
|
14
|
-
format_docstring-0.2.
|
|
15
|
-
format_docstring-0.2.
|
|
10
|
+
format_docstring-0.2.4.dist-info/licenses/LICENSE,sha256=UNm_-hqU-1dAB3bLytP6wvGtUeitoJde2xzb5wgVYn0,1061
|
|
11
|
+
format_docstring-0.2.4.dist-info/METADATA,sha256=4Ei4SrGYksCOoMFJc_BNVtfD3LAh800jdpYPyFgy6dU,15453
|
|
12
|
+
format_docstring-0.2.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
13
|
+
format_docstring-0.2.4.dist-info/entry_points.txt,sha256=Re2iHTzfgKJgeXDga5Z4bGNPtWGmxupOdzTolwn52sk,129
|
|
14
|
+
format_docstring-0.2.4.dist-info/top_level.txt,sha256=NXPwfHm_1YwwGuetwtK3pJv0jXwXelqPTNCFpm5LQyE,17
|
|
15
|
+
format_docstring-0.2.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|