Skip to content

Conversation

@danparizher
Copy link
Contributor

Summary

Fixes #19752

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -151 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)

binary-husky/gpt_academic (+0 -11 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

- crazy_functions/Document_Optimize.py:331:13: E301 [*] Expected 1 blank line, found 0
- crazy_functions/Latex_Project_Polish.py:16:9: E301 [*] Expected 1 blank line, found 0
- crazy_functions/Latex_Project_Translate_Legacy.py:16:9: E301 [*] Expected 1 blank line, found 0
- crazy_functions/Markdown_Translate.py:19:9: E301 [*] Expected 1 blank line, found 0
- crazy_functions/SourceCode_Analyse_JupyterNotebook.py:18:9: E301 [*] Expected 1 blank line, found 0
- crazy_functions/latex_fns/latex_actions.py:184:9: E301 [*] Expected 1 blank line, found 0
- crazy_functions/paper_fns/reduce_aigc.py:390:13: E301 [*] Expected 1 blank line, found 0
- crazy_functions/pdf_fns/report_gen_html.py:25:9: E301 [*] Expected 1 blank line, found 0
- request_llms/bridge_chatglmonnx.py:33:9: E301 [*] Expected 1 blank line, found 0
- request_llms/com_sparkapi.py:118:9: E301 [*] Expected 1 blank line, found 0
... 1 additional changes omitted for project

bokeh/bokeh (+0 -140 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- src/bokeh/client/connection.py:366:9: E301 [*] Expected 1 blank line, found 0
- src/bokeh/model/model.py:559:13: E301 [*] Expected 1 blank line, found 0
- src/bokeh/server/session.py:231:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/models/test_plot.py:76:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/models/test_plot.py:80:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_button.py:65:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_button.py:70:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_checkbox_button_group.py:48:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_checkbox_button_group.py:53:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_checkbox_group.py:66:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_checkbox_group.py:71:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_datepicker.py:183:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_datepicker.py:211:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_dropdown.py:70:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_dropdown.py:75:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_radio_button_group.py:48:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_radio_button_group.py:53:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_radio_group.py:65:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_radio_group.py:70:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_select.py:223:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_select.py:228:13: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_toggle.py:64:9: E301 [*] Expected 1 blank line, found 0
- tests/integration/widgets/test_toggle.py:69:13: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_code_runner.py:132:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:106:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:128:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:147:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:170:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:186:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:205:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:215:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:256:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:281:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:319:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:341:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:362:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:381:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:400:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:418:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:434:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_directory.py:91:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_notebook__handlers.py:59:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_notebook__handlers.py:71:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_notebook__handlers.py:82:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_script.py:46:9: E301 [*] Expected 1 blank line, found 0
- tests/unit/bokeh/application/handlers/test_script.py:61:9: E301 [*] Expected 1 blank line, found 0
... 94 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
E301 151 0 151 0 0

@whitequark
Copy link

Nice, -148 violations!

@ntBre ntBre added preview Related to preview mode features bug Something isn't working rule Implementing or modifying a lint rule labels Aug 5, 2025
&& !(state.follows.is_any_def() && line.last_token != TokenKind::Colon)
&& !state.follows.follows_def_with_dummy_body()
&& matches!(state.class_status, Status::Inside(_))
// Only apply to functions that are "immediately within" a class (not nested within other functions/blocks)
Copy link
Member

Choose a reason for hiding this comment

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

Can we add the reasoning why we only trigger for functions directly within a class?

What about

class Foo:
	if True:
		def test(): pass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added in some additional details; let me know if it's too verbose—there may be a simpler way to put it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need something more like this example or one of the other checks on main will short-circuit:

class Foo:
    if True:
        print("conditional")
        def test():
            pass

but this version is also flagged by pycodestyle (and flake8), so I think we'll want to test that it still is:

$ pycodestyle try.py --select E301 --show-source
try.py:4:9: E301 expected 1 blank line, found 0
        def test():
        ^

I was hopeful that we could detect this a bit more robustly than checking indentation anyway.

Comment on lines 243 to 252
E30.py:993:9: E306 [*] Expected 1 blank line before a nested definition, found 0
|
991 | if True:
992 | print("conditional")
993 | def test():
| ^^^ E306
994 | pass
995 | # end
|
= help: Add missing blank line
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on my comment with the pycodestyle results, this is supposed to be getting an E301, but it's still only getting an E306.

I would really prefer if we could handle these checks by updating the state tracking in this function rather than trying to compare the indentation. Have you explored that at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't thought of that, thank you!

@danparizher danparizher requested a review from ntBre August 15, 2025 19:48
@ntBre
Copy link
Contributor

ntBre commented Sep 8, 2025

Thanks. Could you resolve the merge conflicts? They should just be from the new diff output format. It also still looks like the callback case is getting an E301 diagnostic in the snapshot. Is that correct? I thought it should only be an E306.

@danparizher
Copy link
Contributor Author

Should be all set, let me know!

@whitequark
Copy link

Can this PR get a review please? It's the last thing blocking the adoption of ruff for me: GlasgowEmbedded/glasgow#993

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.

I had one question about the E306 code and a suggestion for one more test case, but this looks like a nice fix. Thank you!

}
}

if line.preceding_blank_lines == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to move this code now? I tested locally after putting it back, and it seems fine down here still.

@danparizher danparizher requested a review from ntBre September 15, 2025 22:58
@ntBre
Copy link
Contributor

ntBre commented Sep 15, 2025

I think you may have reverted the wrong piece of code. The ecosystem check is now showing -160 E306 violations instead of -151 E301 violations.

@danparizher
Copy link
Contributor Author

Hm, maybe I am confused—Could you point me to what part we were looking to revert? Feel free to commit from your side if it's easier, I know this has been a long PR 🙂

@ntBre
Copy link
Contributor

ntBre commented Sep 15, 2025

I'll push a commit! I may not have phrased it well, but I just wanted to move the E306 code back to where it was originally (a standalone if instead of an else if on the E301 check).

@ntBre
Copy link
Contributor

ntBre commented Sep 15, 2025

This is what I had in mind. I'll double-check the ecosystem report to make sure it's actually equivalent. The else if might be necessary, but it's a really clean diff if not. I'm expecting -151 E301 in the ecosystem check (I think the ecosystem projects have added 3 new instances of E301 since the initial PR when it was -148).

@ntBre ntBre merged commit aa63c24 into astral-sh:main Sep 16, 2025
35 checks passed
@whitequark
Copy link

Thank you! When can I expect the fix to be available in a release (really, I just want it to use with pre-commit.ci)?

@danparizher danparizher deleted the fix-19752 branch September 16, 2025 15:14
@ntBre
Copy link
Contributor

ntBre commented Sep 16, 2025

Our weekly releases are usually on Thursday, so it should be out in ~2 days!

@whitequark
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 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.

E301 is inconsistent with flake8

4 participants