refactor: Use ensure_context decorator in Actor class#822
Conversation
Replace manual `_raise_if_not_initialized()` calls with the `ensure_context` decorator from Crawlee, matching the pattern already used in ChargingManager. - Add `active` attribute to `_ActorType` (replaces `_is_initialized`) - Decorate all public methods with `@ensure_context` instead of calling `_raise_if_not_initialized()` at the start of each method - Remove the now-unused `_raise_if_not_initialized` method - Update all test references from `_is_initialized` to `active` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #822 +/- ##
==========================================
- Coverage 85.92% 85.87% -0.06%
==========================================
Files 46 46
Lines 2778 2796 +18
==========================================
+ Hits 2387 2401 +14
- Misses 391 395 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
The tiny small comment is that we now have one more public .active , which is not really needed. In a gigantic class like Actor, that further increases the clutter.
What about making the @ensure_context decorator with a parameter?
Then we can do something like this
_ensure_context = ensure_context("_active")
class Actor:
...
@_ensure_context
async def open_dataset
Sure, good idea. I've implemented a new version of I implemented it in the SDK rather than changing the one in the Crawlee; this way, we don't have to restrict the lower bound version of Crawlee. We can unify it again in the next major version of Crawlee & SDK (to have only 1 version of ensure context). |
Summary
_raise_if_not_initialized()calls with the@ensure_contextdecorator from Crawlee, matching the pattern already used inChargingManageractiveattribute to_ActorType(replaces_is_initialized) for compatibility withensure_context_raise_if_not_initializedmethodReopens #400
Test plan
🤖 Generated with Claude Code