Skip to content
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

Use pydocstyle instead of test #3490

Merged
merged 9 commits into from
Feb 27, 2025
Merged

Use pydocstyle instead of test #3490

merged 9 commits into from
Feb 27, 2025

Conversation

flying-sheep
Copy link
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"""

Copy link

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 2 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
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
14 checks passed
@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