Skip to content

Use pydocstyle instead of test#3490

Merged
flying-sheep merged 9 commits into
mainfrom
pa/ruff-docstyle
Feb 27, 2025
Merged

Use pydocstyle instead of test#3490
flying-sheep merged 9 commits into
mainfrom
pa/ruff-docstyle

Conversation

@flying-sheep
Copy link
Copy Markdown
Member

@flying-sheep flying-sheep commented Feb 27, 2025

Wow this is a huge one.

This is necessary for #3485, as Python 3.13 dedents docstrings and breaks that test.

Ruff does a better job than us at testing that.

Findings for people wanting to do the same:

  • Do this first, else some auto“fixes” break things

    [tool.ruff.lint.pydocstyle]
    convention = "numpy"
  • Don’t rely on unsafe fixes for D301, as it doesn’t replace \\ with \ when replacing """ with r"""

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.53%. Comparing base (f6a665b) to head (94eb10d).
Report is 67 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3490      +/-   ##
==========================================
+ Coverage   75.41%   75.53%   +0.11%     
==========================================
  Files         113      113              
  Lines       13266    13252      -14     
==========================================
+ Hits        10005    10010       +5     
+ Misses       3261     3242      -19     
Files with missing lines Coverage Δ
src/scanpy/__main__.py 0.00% <ø> (ø)
src/scanpy/_compat.py 84.49% <ø> (ø)
src/scanpy/_settings.py 88.75% <ø> (ø)
src/scanpy/_utils/__init__.py 75.00% <100.00%> (+0.28%) ⬆️
src/scanpy/_utils/_doctests.py 90.00% <ø> (ø)
src/scanpy/_utils/compute/is_constant.py 77.50% <ø> (ø)
src/scanpy/cli.py 93.75% <ø> (ø)
src/scanpy/datasets/_datasets.py 100.00% <ø> (ø)
src/scanpy/datasets/_ebi_expression_atlas.py 94.44% <ø> (ø)
src/scanpy/datasets/_utils.py 100.00% <ø> (ø)
... and 92 more

Comment on lines +252 to 271
def _doc_params(**replacements: str):
def dec(obj: _ForT) -> _ForT:
assert obj.__doc__
assert "\t" not in obj.__doc__

# The first line of the docstring is unindented,
# so find indent size starting after it.
start_line_2 = obj.__doc__.find("\n") + 1
assert start_line_2 > 0, f"{obj.__name__} has single-line docstring."
n_spaces = min(
len(m.group(1))
for m in _leading_whitespace_re.finditer(obj.__doc__[start_line_2:])
)

# The placeholder is already indented, so only indent subsequent lines
indented_replacements = {
k: indent(v, " " * n_spaces)[n_spaces:] for k, v in replacements.items()
}
obj.__doc__ = obj.__doc__.format_map(indented_replacements)
return obj
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably the only interesting part of this PR

@flying-sheep flying-sheep merged commit 6e68d06 into main Feb 27, 2025
@flying-sheep flying-sheep deleted the pa/ruff-docstyle branch February 27, 2025 18:19
meeseeksmachine pushed a commit to meeseeksmachine/scanpy that referenced this pull request Feb 27, 2025
flying-sheep added a commit that referenced this pull request Feb 27, 2025
Co-authored-by: Philipp A <flying-sheep@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant