Repository navigation
Add match_filter and import_filter hooks to Restructure - #918
Open
marlon-costa-dc wants to merge 5 commits into
Open
marlon-costa-dc wants to merge 5 commits into
marlon-costa-dc wants to merge 5 commits into
Conversation
Restructure accepts two optional callables: - match_filter(pymodule, match) is consulted for every match found in a module; only the matches it accepts are restructured. - import_filter(resource, imports) selects the imports added to a changed module. Clients previously had to override the private _compute_changes and _add_imports to select matches or to reuse bindings a module already has. The hook type aliases are defined at module level, so the annotations of Restructure.__init__ resolve at runtime. (cherry picked from commit 4e2da5a) (cherry picked from commit 3bc57a7) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #918 +/- ##
=======================================
Coverage 95.44% 95.45%
=======================================
Files 134 134
Lines 26910 26952 +42
=======================================
+ Hits 25685 25727 +42
Misses 1225 1225 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
marlon-costa-dc
added a commit
to flext-sh/flext-infra
that referenced
this pull request
Nov 22, 2026
…lter hook (flext-2lout) (#2760) ## Summary `FlextInfraRopeRestructure` overrode Rope's private `Restructure._add_imports` to drop the import declarations whose binding the changed module already defines (keeping a richer public facade instead of rebinding it). The pinned rope (`dc-use`, the same hook proposed upstream as python-rope/rope#918) calls a public `import_filter(resource, imports)` exactly before adding imports, so this passes `_admit_imports` as that hook and deletes the private override. - Same selection: with a mapping policy, keep only the declarations whose binding is not defined by the module; otherwise keep the requested imports. - No private-method coupling to Rope; 16 insertions, 22 deletions. Bead: flext-2lout (rope fork reduced to what flext-infra needs, through public hooks). ## Note This lane's commit hook did not run (its workspace setup had not finished, so prek was not installed); the integration CI is the gate for this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Replaces the private `Restructure._add_imports` override with the public `import_filter` hook that the pinned rope fork exposes, keeping the same import-admission behavior. This removes coupling to rope's private API and trims the restructure code. <sup>Written for commit b6b2614. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/flext-sh/flext-infra/pull/2760?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This branch has not been deployed
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.
Restructureaccepts two optional callables:match_filter(pymodule, match)is called for every match found in a module, and only the matches it accepts are restructured;import_filter(resource, imports)selects which ofimportsare added to a changed module.Today a client that wants to skip some matches (for example matches inside code it must not touch) or reuse an import the module already has has to override the private
_compute_changesand_add_imports. Both hooks default toNone, so existing callers are unaffected.The hook type aliases (
MatchFilter,ImportFilter) are defined at module level, sotyping.get_type_hints(Restructure.__init__)resolves.Tests in
restructuretest.pycover filtering matches, filtering imports, and the runtime annotations. Tested locally on Python 3.10, 3.11, 3.13 and 3.14.