Skip to content

Keep single-line signatures when body is an Ellipsis (...) in .py files #10026

@etienneschalk

Description

@etienneschalk

A minimal code snippet that reproduces the bug.

File name: format_ruff.py

Before ruff:

class MyClass:
    def __add__(self, other: int) -> int: ...

After ruff:

class MyClass:
    def __add__(self, other: int) -> int:
        ...

The command you invoked

ruff format format_ruff.py 

Note: in real-life scenario, one might have installed the Ruff extension on VSCode, opened a file with many stubs like in the minimal code snippet, and see them all formatted, introducing unwanted code change, which can be annoying for version control.

This might also slow down ruff adoption in existing large code bases where the case mentioned above happens a lot.

The current Ruff settings

No overriden settings. I ran a pip install ruff then ran the command above

The current Ruff version

ruff --version
ruff 0.2.2

What I would like

A way to opt-out of de-inlining the Ellipsis (...) in stubs. I have searched in documentation without finding such an option. I browsed the following issues (in Links section).

An option could be:

[tool.ruff.format]
keep-single-line-ellipsis = true

Links

Related Issues:

Related PRs:

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions