Repository navigation
fix(extract): raise RefactoringError for empty or whitespace-only region - #929
Merged
lieryan merged 2 commits intoNov 8, 2026
Merged
Conversation
ExtractMethod and ExtractVariable raised IndexError for an empty region and ModuleSyntaxError for a whitespace-only one. Check for this in _ExceptionalConditionChecker.base_conditions() so both report a RefactoringError like other bad regions. Fixes python-rope#926 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aliassar
force-pushed
the
fix-extract-empty-region-926
branch
from
November 3, 2026 17:53
0f59eb5 to
57fb251
Compare
lieryan
enabled auto-merge
November 8, 2026 05:41
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #929 +/- ##
=======================================
Coverage 95.43% 95.43%
=======================================
Files 134 134
Lines 26826 26843 +17
=======================================
+ Hits 25601 25618 +17
Misses 1225 1225 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
LGTM. Thanks for the pull request. @allcontributors please add @aliassar for code contribution |
Contributor
|
I've put up a pull request to add @aliassar! 🎉 |
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.
Description
Extract method and extract variable raised
IndexErrorfor an empty region andModuleSyntaxErrorfor a whitespace-only one, which an editor integration can't tell apart from a real crash. The extracted text was never checked for being empty, so it ended up in_get_single_expression_body()(extracted.lstrip()[0]) or in the generated wrapper function with no body._ExceptionalConditionChecker.base_conditions()now raisesRefactoringError("Extracted piece should contain at least one expression or statement.") when the extracted text is blank, like the other bad-region cases.Added tests for extract method (empty and whitespace-only) and extract variable (empty) in
extracttest.py; they fail on master and pass now. The repro from the issue now printsRefactoringErrorfor all three cases.Fixes #926
Checklist (delete if not relevant):