Skip to content

chore: add __getattr__ hook for rfdetr.util/rfdetr.deploy removal#839

Merged
Borda merged 6 commits intodevelopfrom
chore/import-deprecation-hooks
Mar 21, 2026
Merged

chore: add __getattr__ hook for rfdetr.util/rfdetr.deploy removal#839
Borda merged 6 commits intodevelopfrom
chore/import-deprecation-hooks

Conversation

@Borda
Copy link
Member

@Borda Borda commented Mar 20, 2026

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

  • Bug fix (non-breaking change that fixes an issue)
  • Refactoring (no functional changes)

Testing

  • I have tested this change locally
  • I have added/updated tests for this change

Additional Context

…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>
Copilot AI review requested due to automatic review settings March 20, 2026 20:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_V17 mapping in rfdetr.__init__ and route util/deploy attribute access through importlib.import_module, raising a migration-hint ImportError only when the shim module itself is missing.
  • Add tests covering shim-present resolution, shim-missing migration hint, and propagation of nested ModuleNotFoundError from 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
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 95.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71%. Comparing base (ce247ba) to head (66473da).
⚠️ Report is 1 commits behind head on develop.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Codex <noreply@openai.com>
@Borda Borda force-pushed the chore/import-deprecation-hooks branch from 78c76a3 to 54a4e87 Compare March 21, 2026 23:13
Borda and others added 2 commits March 22, 2026 00:42
…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>
@Borda Borda merged commit fb7299f into develop Mar 21, 2026
22 of 23 checks passed
@Borda Borda deleted the chore/import-deprecation-hooks branch March 21, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants