-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix typing for Actor's join()
method
#45
Comments
Comment by @jakub-toptal
|
`BackgroundService` is a new abstract base class can be used to write other classes that runs one or more tasks in the background. It provides a consistent API to start and stop these services and also takes care of the handling of the background tasks. It can also work as an `async` context manager, giving the service a deterministic lifetime and guaranteed cleanup. The new `Actor` class brings quite a few new improvements over the old `@actor` decorator. These are the main differences: * It doesn't start automatically, `start()` needs to be called to start an actor. * The method to implement the main logic was renamed from `run()` to `_run()`, as it is not intended to be run externally. * Actors can have an optional `name` (useful for debugging/logging purposes) and `loop` (if the actor should run in a loop different from the currently running loop). * The actor will only be restarted if an unhandled `Exception` is raised by `_run()`. It will not be restarted if the `_run()` method finishes normally. If an unhandled `BaseException` is raised instead, it will be re-raised. For normal cancellation the `_run()` method should handle `asyncio.CancelledError` if the cancellation shouldn't be propagated (this is the same as with the decorator). * The `_stop()` method is public (`stop()`) and will `cancel()` and `await` for the task to finish, catching the `asyncio.CancelledError`. * The `join()` method is renamed to `wait()`, but they can also be awaited directly ( `await actor`). * For deterministic cleanup, actors can now be used as `async` context managers. The base actors (`ConfigManagingActor`, `ComponentMetricsResamplingActor`, `DataSourcingActor`, `PowerDistributingActor`) now inherit from the new `Actor` class, as well as the `MovingWindow`. Fixes #240, fixes #45, fixes #196.
What happened?
When calling the
join()
method of an actor (or_stop()
or probably any method defined by the@actor
decorator) we get an error frommypy
complaining about the method not existing in the actor class, for example:pylint
seems to be complaining too.What did you expect instead?
No errors when calling the method.
Affected version(s)
All
Affected part(s)
Actors
Extra information
The
typing_extensions
package (#19), in particular the@dataclass_transform()
decorator, might help with this, it needs further investigation.As a workaround,
# noqa
can be used when the method is called.Here is an example where we need to use
# noqa
:frequenz-sdk-python/tests/power_distribution/test_power_distributor.py
Line 193 in 20e1dff
The text was updated successfully, but these errors were encountered: