Skip to content

Conversation

@danparizher
Copy link
Contributor

Summary

Fixes #20959. Enhanced the DOC102 rule to recognize and validate multiple parameters listed together in NumPy-style docstrings using comma separation.

Problem Analysis

The existing DOC102 rule failed to detect extraneous parameters when NumPy-style docstrings combined multiple parameters with commas (e.g., x1, x2 : object), causing false negatives.

Approach

Updated the parse_parameters_numpy function to split comma-separated parameter names and validate each individually, added comprehensive test cases covering the original issue and edge cases, and ensured code compliance with project standards.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 19, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks! Just a few nits

@ntBre ntBre added rule Implementing or modifying a lint rule preview Related to preview mode features labels Oct 22, 2025
Refactored the calculation of parameter start and end positions in the Numpy docstring parser to use more direct conversions and remove unnecessary error handling. This improves code clarity and safety by relying on guaranteed substring presence.
Resolved merge conflict in DOC102_numpy.py by combining both test cases:
- Kept comma-separated parameter test cases from issue astral-sh#20959
- Added DOC102 false positive test case with Warnings section from upstream
@danparizher danparizher requested a review from ntBre October 24, 2025 21:35
@augustelalande
Copy link
Contributor

Can you add a test case for a type less docstring with comma, e.g.:

def add_numbers(a, b):
    """
    Adds two numbers and returns the result.

    Parameters
    ----------
    a, b
        The numbers to add.

    Returns
    -------
    int
        The sum of the two numbers.
    """
    return a + b

Added a new test case to DOC102_numpy.py to verify handling of comma-separated parameters without type annotations in numpy-style docstrings.
content_start + param_end,
),
});
let param_line = before_colon.trim_end();
Copy link
Member

Choose a reason for hiding this comment

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

I suspect that the trim_end call here now is unnecessary, given that you also trim each parameter part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing it causes incorrect column positions in the diagnostic ranges, from my testing.

Even though we trim() each parameter part, the offset calculation happens before trimming, so the trailing whitespace in before_colon affects the positions.

- Track offset incrementally instead of using `find()`
- Use `TextRange::at()` instead of `TextRange::new()`
- Use `','.text_len()` for comma length instead of hardcoded value
Comment on lines 674 to 677
let param_start_in_line = current_offset
+ TextSize::from(u32::from(
param_part.text_len() - param_part_trimmed.text_len(),
));
Copy link
Member

Choose a reason for hiding this comment

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

This seems unnecessarily complicated to go from TextSize -> u32 -> TextSize. Can you say more why you added that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oversight on my part - Since both param_part.text_len() and param_part_trimmed.text_len() return TextSize, we can subtract them directly without the conversion.

@MichaReiser MichaReiser merged commit 725ae69 into astral-sh:main Nov 12, 2025
37 checks passed
@danparizher danparizher deleted the fix-20959 branch November 12, 2025 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC102 false negative for NumPy-style comma-separated parameters

4 participants