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

Ruff treats pass and ... differently for #12799

Open
ssteinerx opened this issue Aug 11, 2024 · 2 comments
Open

Ruff treats pass and ... differently for #12799

ssteinerx opened this issue Aug 11, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@ssteinerx
Copy link

ssteinerx commented Aug 11, 2024

Ruff version: ruff 0.5.7

I searched for "pass", "...", "blank-line-between-methods", and "E301" but found nothing.

The example at blank-line-between-methods (E301) shows insertion of blank lines between methods of a class.

With --preview and E301 enabled, missing blank lines are detected and fixed.

If, instead of pass, you use ..., then the missing blank between methods is not detected or corrected. There is a mention in the doc about the rule not enabled in .pyi files; this isn't one of those.

# This will get spaced out as per the example for E301
class MyClass(object):
    def func1():
        pass
    def func2():
        pass

Becomes:

class MyClass(object):
    def func1():
        pass

    def func2():
        pass
# This will NOT get the missing blank lines detected or inserted
# It doesn't matter whether the `...` is on the same line as the `def` or not
# NOTE: ruff *does* bring the `...` up to the same line as the `def` as might be expected in a `.pyi` file, 
# I'm not sure if that be an altogether different rule that may be interacting with E301..
class MyClass(object):
    def func1(): ...
    def func2():
        ...

Becomes:

class MyClass(object):
    def func1(): ...
    def func2(): ...
@MichaReiser MichaReiser added documentation Improvements or additions to documentation question Asking for support or clarification labels Aug 11, 2024
@MichaReiser
Copy link
Member

Hi

This behavior was added in #10704 to make the rule compatible with the formatter. Mentioning this behavior in the documentation does make sense.

@MichaReiser MichaReiser removed the question Asking for support or clarification label Aug 11, 2024
@ssteinerx
Copy link
Author

I want the code formatted the same as everything else with the dummy body (or the other dummy body, whichever is which) on next line, indented, and a space between it and the next method. Oddly enough, I would have expected the current behaviour for an overload annotation with ...; go figure.

Since, from reading the related issues, this looks like a horrendous PITA, and is likely to get even more annoying in the future, just documenting that ... and pass are treated differently should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants