chore: add __getattr__ hook for rfdetr.util/rfdetr.deploy removal#839
Merged
chore: add __getattr__ hook for rfdetr.util/rfdetr.deploy removal#839
Conversation
…v1.7 Extends rfdetr/__init__.__getattr__ with a _REMOVED_IN_V17 mapping so that when the util/ and deploy/ shim directories are deleted at the v1.7 release, users get a clear ImportError with a migration hint instead of an opaque ModuleNotFoundError. While the shim files still exist the hook transparently delegates to importlib.import_module(), preserving backward compatibility. A guard on ModuleNotFoundError.name prevents the hook from masking genuine nested import failures inside the shim. Adds 4 tests: shim-exists resolution for util and deploy, migration hint on missing shim (mocked), and nested-error propagation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Co-Authored-By: Codex <noreply@openai.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the top-level rfdetr.__getattr__ lazy-resolution hook to handle upcoming removal of the rfdetr.util and rfdetr.deploy shim packages, so that once those shims are deleted users get a clear ImportError migration hint instead of a ModuleNotFoundError.
Changes:
- Add
_REMOVED_IN_V17mapping inrfdetr.__init__and routeutil/deployattribute access throughimportlib.import_module, raising a migration-hintImportErroronly when the shim module itself is missing. - Add tests covering shim-present resolution, shim-missing migration hint, and propagation of nested
ModuleNotFoundErrorfrom within shim imports.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/rfdetr/__init__.py |
Adds removed-module alias handling to __getattr__ with guarded ModuleNotFoundError handling and migration-hint ImportError. |
tests/utilities/test_package.py |
Adds tests for the new __getattr__ behavior (shim exists/missing and nested import error propagation). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #839 +/- ##
======================================
Coverage 71% 71%
======================================
Files 92 92
Lines 7161 7201 +40
======================================
+ Hits 5049 5087 +38
- Misses 2112 2114 +2 🚀 New features to boost your workflow:
|
Co-Authored-By: Codex <noreply@openai.com>
78c76a3 to
54a4e87
Compare
…th sentinel - `_RemovedModuleFinder.find_spec` now short-circuits on any `fullname` that does not start with `rfdetr.`, preventing bare top-level imports such as `import util` or `import deploy` from being hijacked by the RF-DETR migration finder after `import rfdetr`. - Replace the type-identity dedup guard with a `sys`-level sentinel (`sys._rfdetr_removed_finder`) so `importlib.reload(rfdetr)` never inserts a second finder into `sys.meta_path`. - Add two characterization tests: scope guard (bare names return None) and reload idempotency (finder count unchanged after reload). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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?
Extends rfdetr/init.getattr with a _REMOVED_IN_V17 mapping so that when the util/ and deploy/ shim directories are deleted at the v1.7 release, users get a clear ImportError with a migration hint instead of an opaque ModuleNotFoundError.
While the shim files still exist the hook transparently delegates to importlib.import_module(), preserving backward compatibility. A guard on ModuleNotFoundError.name prevents the hook from masking genuine nested import failures inside the shim.
Adds 4 tests: shim-exists resolution for util and deploy, migration hint on missing shim (mocked), and nested-error propagation.
Type of Change
Testing
Additional Context