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

Ignore trailing commas not working for function arguments #16475

Closed
sparxastronomy opened this issue Mar 3, 2025 · 2 comments
Closed

Ignore trailing commas not working for function arguments #16475

sparxastronomy opened this issue Mar 3, 2025 · 2 comments
Labels
question Asking for support or clarification

Comments

@sparxastronomy
Copy link

Summary

I have the following function block:

def compute_profiles(
        x: np.ndarray, 
        y: np.ndarray, 
        window_size: int, 
        type: str = "median", 
        return_xbins: bool = False
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:

However ruff ignores the trailing commas, and formats it to even though skip-magic-trailing-comma = false

def compute_profiles(
    x: np.ndarray, y: np.ndarray, window_size: int, type: str = "median", return_xbins: bool = False
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:

The problem only appears for functions, for regular arrays the problem does not appear.

My configuration is:

[tool.ruff]
extend-include = ["*.ipynb"]
preview = true
line-length = 120
indent-width = 4

[tool.ruff.format]
preview = true
quote-style = "double"
indent-style = "space"
line-ending = "auto"
skip-magic-trailing-comma = false
docstring-code-format = true
docstring-code-line-length = "dynamic"

[tool.ruff.lint]
select = [
    "E", # pycodestyle (error)
    "F", # pyflakes
    "B", # bugbear
    "B9",
    "C4", # flake8-comprehensions
    "SIM", # flake8-simplify
    "I", # isort
    "UP", # pyupgrade
    "PIE", # flake8-pie
    "PGH", # pygrep-hooks
    "PYI", # flake8-pyi
    "RUF",
]
ignore = [
    # only relevant if you run a script with `python -0`,
    # which seems unlikely for any of the scripts in this repo
    "B011",
    # Leave it to the formatter to split long lines and
    # the judgement of all of us.
    "E501",
    "RUF052",
    "E201",
    "E241"
]

fixable = ["A", "B", "C", "D", "E", "F"]
unfixable = []

[tool.ruff.lint.pydocstyle]
convention = "google"

I am using the latest version of Ruff extension on VSCode.

Version

v2025.14.0 (VScode)

@MichaReiser MichaReiser added the question Asking for support or clarification label Mar 3, 2025
@MichaReiser
Copy link
Member

Hi @sparxastronomy

I don't see a trailing comma in your example code. The trailing comma must come after the last argument's default value:

def compute_profiles(
        x: np.ndarray, 
        y: np.ndarray, 
        window_size: int, 
        type: str = "median", 
        return_xbins: bool = False,
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: ...

Ruff should then split the arguments across multiple lines when using skip-magic-trailing-comma=false (default)

https://play.ruff.rs/10014487-0683-40d5-9eed-968075bce9b5

@sparxastronomy
Copy link
Author

Thanks @MichaReiser for point out the missing commas. I thought the last comma was not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

2 participants