fix(tools): remove dead code in _is_likely_binary and harden _check_lint against brace paths - #6950
Closed
luyao618 wants to merge 1 commit into
Closed
Conversation
…int against brace paths
- Remove unreachable `if not content_sample` branch inside the truthy
`if content_sample` block in `_is_likely_binary()` (dead code that
could never execute).
- Replace `linter_cmd.format(file=...)` with `linter_cmd.replace("{file}", ...)`
in `_check_lint()` so file paths containing curly braces (e.g.
`src/{test}.py`) no longer raise KeyError/ValueError.
- Add 16 unit tests covering both fixes and edge cases.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
luyao618
force-pushed
the
fix/file-operations-binary-check-and-lint
branch
from
April 10, 2026 04:20
a1391b9 to
73dbc94
Compare
Contributor
|
Merged via #7541 with authorship preserved. Thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes two edge-case bugs in
ShellFileOperations:Dead code in
_is_likely_binary()— An unreachableif not content_samplebranch was nested inside aif content_sampletruthy check, meaning the inner guard could never execute. This dead code reduces readability and suggests the original intent was an early return for empty strings (which is already handled by the outer falsy check on empty"")._check_lint()crashes on brace-containing file paths —linter_cmd.format(file=...)interprets{and}in the file path as format-string placeholders, raisingKeyErrororValueErrorfor paths likesrc/{test}.py. Replaced withlinter_cmd.replace("{file}", ...)which is immune to this issue.Related Issue
No existing issue — found during code audit.
Type of Change
Changes Made
tools/file_operations.py:368-370— Removed 2 lines of dead code (if not content_sample: return False) from_is_likely_binary()tools/file_operations.py:741— Changedlinter_cmd.format(file=...)→linter_cmd.replace("{file}", ...)in_check_lint()tests/tools/test_file_operations_edge_cases.py— 16 unit tests covering:_is_likely_binary(): binary extensions, text/binary content thresholds, empty/None samples, tab/newline exclusion, >1000 char samples_check_lint(): normal paths, curly-brace paths, nested braces, missing linters, lint failuresHow to Test
pytest tests/tools/test_file_operations_edge_cases.py -v— all 16 tests passpytest tests/ -q --ignore=tests/integration --ignore=tests/e2e— full suite passesChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A