GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [`flake8-executable`] Mark `EXE004` fix as unsafe by baltasarblanco · Pull Request #26033 · astral-sh/ruff

Conversation

@baltasarblanco

@baltasarblanco baltasarblanco commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

The fix removes the whitespace before the shebang, which can include blank lines. If a blank line separates the shebang from an encoding declaration, deleting it moves the encoding up to line 2. Python then reads it following PEP 263 and changes how the file is decoded. In short, it changes the behavior.

For this reason, the fix should not be marked as safe. @MichaReiser confirmed this in the thread. Fixes #15581

Test Plan

  • New fixture EXE004_5.py
  • Regenerated snapshots now include the note: This is an unsafe fix and may change runtime behavior
  • Smoke test: with --fix the fix is not applied; with --fix --unsafe-fixes it is

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@baltasarblanco
[flake8-executable] Mark EXE004 fix as unsafe
e796e8f
@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre June 16, 2026 03:22
@astral-sh-bot

astral-sh-bot Bot commented Jun 16, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ntBre
ntBre reviewed Jun 16, 2026
View reviewed changes

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Should we only mark it unsafe when the leading whitespace contains a newline? That sounded like the problem to me in the issue.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@baltasarblanco
Only mark the fix unsafe when the leading whitespace contains a newline
6895dc9
@baltasarblanco

baltasarblanco commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Good call, done. Now it's only marked unsafe when the leading whitespace contains a newline. Thank you! @ntBre

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MichaReiser MichaReiser added the fixes Related to suggested fixes for violations label Jun 17, 2026
MichaReiser
MichaReiser reviewed Jun 17, 2026
View reviewed changes
Comment thread ada Resolved

Uh oh!

There was an error while loading. Please reload this page.

@baltasarblanco
Remove stray file committed by mistake
ca9df90
ntBre
ntBre reviewed Jun 24, 2026
View reviewed changes
Comment thread ...s/flake8_executable/snapshots/ruff_linter__rules__flake8_executable__tests__EXE004_4.py.snap Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@baltasarblanco
Address review: trim fix-safety docs, use applicability, drop EXE004_5
8ab2b3e
@baltasarblanco

baltasarblanco commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed all the comments in the latest push:

  • Dropped the EXE004_5 fixture — EXE004_4 already covers the unsafe case.
  • Removed the redundant code comment.
  • Switched to computing an Applicability and using Fix::applicable_edit.
  • Trimmed the fix-safety docs to your suggested wording.

On the PEP 263 regex: I kept the conservative approach for now since it's niche, as you mentioned — happy to follow up with the narrower check if you'd prefer.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ntBre
ntBre reviewed Jun 25, 2026
View reviewed changes

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks this looks good now! Just one more nit about using an existing helper method. There are also some merge conflicts. Would you mind resolving those too? You probably just need to rerun the test and accept the new snapshot.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

baltasarblanco added 3 commits June 25, 2026 17:18
@baltasarblanco
Use locator.contains_line_break helper
245a06f
@baltasarblanco
Merge remote-tracking branch 'upstream/main' into feat/15581-exe004-u…
0606441
…nsafe-fix

# Conflicts:
#	crates/ruff_linter/src/rules/flake8_executable/snapshots/ruff_linter__rules__flake8_executable__tests__EXE004_4.py.snap
@baltasarblanco
Regenerate EXE004_4 snapshot after merge
3b0f084
@baltasarblanco

baltasarblanco commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Done — switched to locator.contains_line_break(prefix) and resolved the merge conflicts (regenerated the EXE004_4 snapshot). Thanks!

Heads up: the ruff-isp check failed on a transient crates.io network error (HTTP2 framing), not the change — should pass on a re-run.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ntBre
ntBre approved these changes Jun 25, 2026
View reviewed changes

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

baltasarblanco reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@ntBre
ntBre merged commit 3145856 into astral-sh:main Jun 25, 2026
76 of 77 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@BrewTestBot BrewTestBot mentioned this pull request Jul 9, 2026
ruff 0.15.21 Homebrew/homebrew-core#292272
Merged
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
chore(deps): update ⬆️ mise-packages scottames/dots#978
Merged
1 task
@baltasarblanco
baltasarblanco deleted the feat/15581-exe004-unsafe-fix branch July 14, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@MichaReiser MichaReiser MichaReiser left review comments
@ntBre ntBre ntBre approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

EXE004 fix can activate an encoding declaration

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@baltasarblanco @MichaReiser @ntBre
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.