Skip to content

feat(collectors): deprecate CollectorBase in favor of AbstractCollector#219

Merged
wpak-ai merged 2 commits into
cppalliance:developfrom
leostar0412:feat/deprecate-collector-base
May 18, 2026
Merged

feat(collectors): deprecate CollectorBase in favor of AbstractCollector#219
wpak-ai merged 2 commits into
cppalliance:developfrom
leostar0412:feat/deprecate-collector-base

Conversation

@leostar0412
Copy link
Copy Markdown
Collaborator

@leostar0412 leostar0412 commented May 18, 2026

Summary

  • Emit DeprecationWarning when subclassing CollectorBase (__init_subclass__, removal planned in v1.0).
  • Exempt DjangoCommandCollector via _skip_collector_base_deprecation so core glue code stays quiet.
  • Document CollectorBase as deprecated in Core_public_API.md and point contributors to AbstractCollector.
  • Add test_collector_base_subclass_emits_deprecation_warning (uses warnings.catch_warnings because pytest ignores DeprecationWarning globally).

Existing collectors that subclass CollectorBase keep working; the warning is advisory only.

Test plan

  • uv run pytest core/tests/test_collectors_base.py::test_collector_base_subclass_emits_deprecation_warning -q
  • uv run pytest core/tests/test_collectors_base.py -q (with DB available for @pytest.mark.django_db tests)

Closes #212

Summary by CodeRabbit

  • Deprecated

    • CollectorBase is marked deprecated with planned removal in v1.0; subclassing now emits a deprecation warning at definition time. Legacy run() is deprecated to encourage migration.
  • Documentation

    • Public API docs updated to reflect deprecation, removal timeline, and the subclassing warning behavior.
  • Tests

    • Added a test to assert subclassing triggers the deprecation warning.

Review Change Stack

@leostar0412 leostar0412 self-assigned this May 18, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

📝 Walkthrough

Walkthrough

CollectorBase now emits a DeprecationWarning when subclassed, with an opt-out for existing collectors; tests validate the warning and public API docs mark CollectorBase deprecated for removal in v1.0.

Changes

CollectorBase Deprecation

Layer / File(s) Summary
Deprecation mechanism and documentation
core/collectors/base.py, docs/Core_public_API.md
CollectorBase.__init_subclass__ emits DeprecationWarning unless _skip_collector_base_deprecation is set; DjangoCommandCollector opts out; TODO deprecation note added; API docs updated to mark CollectorBase deprecated (removal v1.0).
Deprecation warning validation
core/tests/test_collectors_base.py
New test test_collector_base_subclass_emits_deprecation_warning() captures and verifies DeprecationWarning on subclass creation with message content including CollectorBase, AbstractCollector, and v1.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #208 — Related migration/rollout work to replace CollectorBase with AbstractCollector; this PR adds the runtime warning and docs needed for that migration.

Poem

🐰 A gentle hop, a cautioned trace,
CollectorBase steps out of place.
"Use AbstractCollector," whispers the vine,
By v1.0 the old will resign.
A quiet opt-out keeps existing code fine.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding deprecation to CollectorBase in favor of AbstractCollector, which matches the PR's primary objective and all code changes.
Linked Issues check ✅ Passed All acceptance criteria from issue #212 are implemented: DeprecationWarning in init_subclass, Core_public_API.md documentation updated, test added for the warning, existing collectors continue working, and TODO comment included.
Out of Scope Changes check ✅ Passed All changes are directly related to deprecating CollectorBase: warning implementation, exemption for DjangoCommandCollector, documentation update, and test coverage. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
core/tests/test_collectors_base.py (1)

17-17: 💤 Low value

Consider using direct attribute access instead of getattr.

Since the attribute name is a constant string, getattr provides no additional safety over direct attribute access. Direct access would also make it clearer that the test expects the attribute to exist.

♻️ Proposed refactor
-    assert getattr(DjangoCommandCollector, "_skip_collector_base_deprecation") is True
+    assert DjangoCommandCollector._skip_collector_base_deprecation is True
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/tests/test_collectors_base.py` at line 17, Replace the getattr call with
direct attribute access: the test should assert the class attribute
DjangoCommandCollector._skip_collector_base_deprecation is True instead of using
getattr(DjangoCommandCollector, "_skip_collector_base_deprecation"); this makes
the expectation explicit and clearer.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/Core_public_API.md`:
- Line 9: The table entry for `core.collectors.CollectorBase` contains a broken
anchor to "Migrating from `CollectorBase` to `AbstractCollector`"; add a
migration section with that exact header text so the link resolves, e.g., a
short "Migrating from `CollectorBase` to `AbstractCollector`" section describing
replacing `run()` with `name`, `validate_config()` and `collect()` (and that
`AbstractCollector.run()` wires them together), or alternatively remove the
`[Migrating from
`CollectorBase`](`#migrating-from-collectorbase-to-abstractcollector`)` reference
in the `core.collectors.CollectorBase` table entry if you prefer not to add the
guide.

---

Nitpick comments:
In `@core/tests/test_collectors_base.py`:
- Line 17: Replace the getattr call with direct attribute access: the test
should assert the class attribute
DjangoCommandCollector._skip_collector_base_deprecation is True instead of using
getattr(DjangoCommandCollector, "_skip_collector_base_deprecation"); this makes
the expectation explicit and clearer.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b6a7b73f-3ff5-4950-8736-daa0f6cda66a

📥 Commits

Reviewing files that changed from the base of the PR and between 2037bb5 and da69687.

📒 Files selected for processing (3)
  • core/collectors/base.py
  • core/tests/test_collectors_base.py
  • docs/Core_public_API.md

Comment thread docs/Core_public_API.md Outdated
@leostar0412
Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
core/collectors/base.py (1)

50-51: ⚡ Quick win

Attribute lookup semantics concern is valid but not applicable here.

The code uses getattr which includes inherited attributes; using cls.__dict__.get would restrict the flag to explicitly opt-out classes only. However, DjangoCommandCollector has no subclasses in the codebase, so this is not a practical issue. All production collectors inherit directly from CollectorBase, not from DjangoCommandCollector. If future code extends DjangoCommandCollector, the suggested change would prevent unintended warning suppression in subclasses.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/collectors/base.py` around lines 50 - 51, Replace the current attribute
lookup using getattr in the CollectorBase deprecation check so that the opt-out
flag only applies when a class explicitly defines it; change the condition that
reads getattr(cls, "_skip_collector_base_deprecation", False) to check the class
namespace directly (e.g. cls.__dict__.get("_skip_collector_base_deprecation"))
so that subclasses of DjangoCommandCollector do not inherit and unintentionally
suppress the warning—update the check in the method where this condition appears
(referencing CollectorBase and the _skip_collector_base_deprecation symbol).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/tests/test_collectors_base.py`:
- Line 17: The test uses getattr(DjangoCommandCollector,
"_skip_collector_base_deprecation") unnecessarily; replace the getattr call with
direct attribute access by asserting
DjangoCommandCollector._skip_collector_base_deprecation is True so the assertion
reads: assert DjangoCommandCollector._skip_collector_base_deprecation is True,
keeping the same symbol DjangoCommandCollector and attribute name
_skip_collector_base_deprecation.

---

Nitpick comments:
In `@core/collectors/base.py`:
- Around line 50-51: Replace the current attribute lookup using getattr in the
CollectorBase deprecation check so that the opt-out flag only applies when a
class explicitly defines it; change the condition that reads getattr(cls,
"_skip_collector_base_deprecation", False) to check the class namespace directly
(e.g. cls.__dict__.get("_skip_collector_base_deprecation")) so that subclasses
of DjangoCommandCollector do not inherit and unintentionally suppress the
warning—update the check in the method where this condition appears (referencing
CollectorBase and the _skip_collector_base_deprecation symbol).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 55de6368-9dd9-4c00-839b-bd41cfeba457

📥 Commits

Reviewing files that changed from the base of the PR and between 2037bb5 and 0443e66.

📒 Files selected for processing (3)
  • core/collectors/base.py
  • core/tests/test_collectors_base.py
  • docs/Core_public_API.md

Comment thread core/tests/test_collectors_base.py
@leostar0412 leostar0412 requested a review from henry0816191 May 18, 2026 21:05
@leostar0412 leostar0412 requested a review from wpak-ai May 18, 2026 21:26
@wpak-ai wpak-ai merged commit 84608cc into cppalliance:develop May 18, 2026
5 checks passed
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.

Add DeprecationWarning to CollectorBase

3 participants