-
Notifications
You must be signed in to change notification settings - Fork 4
Add Handler.initialise(controller) #135
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
==========================================
- Coverage 90.83% 90.81% -0.03%
==========================================
Files 41 41
Lines 1954 1971 +17
==========================================
+ Hits 1775 1790 +15
- Misses 179 181 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Could be helpful for setting up things like converters so we can have less logic inside the update/put calls! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as part of this change we should take out controller
as an argument to put
/update
, making this PR unneccesary.
If the user wants the controller in the handler for use in put
or update
then they should store it as an attribute (in the python sense) in their handler from initialise.
We can take out controller as an argument here
Lines 76 to 87 in 5aa7a12
def _link_attribute_sender_class( | |
controller_api: ControllerAPI, controller: Controller | |
) -> None: | |
for attr_name, attribute in controller_api.attributes.items(): | |
match attribute: | |
case AttrW(sender=Sender()): | |
assert not attribute.has_process_callback(), ( | |
f"Cannot assign both put method and Sender object to {attr_name}" | |
) | |
callback = _create_sender_callback(attribute, controller) | |
attribute.add_process_callback(callback) |
and here
Lines 130 to 141 in 5aa7a12
def _create_updater_callback(attribute, controller): | |
async def callback(): | |
try: | |
await attribute.updater.update(controller, attribute) | |
except Exception as e: | |
print( | |
f"Update loop in {attribute.updater} stopped:\n" | |
f"{e.__class__.__name__}: {e}" | |
) | |
raise | |
return callback |
66d4dc7
to
8005664
Compare
…Added initialise method to Attribute, checks for handler and calls the method. Moved initialise into BaseController class, loops over attributes calling initialise with a reference to self. Added unit test for Attribute class.
…ated initialisation.
…lank initialise method.
6da6ec6
to
e7430a5
Compare
This is actually broken and is showing up a lack of testing. The updater callbacks are still being called with a controller here, which causes them to stop and print a warning. The reason this exception is caught and printed was originally so that one attribute update failing doesn't crash the whole application. I was on the fence about this and am again thinking just crashing would be better. Although to be fair if this had type hints that would have caught it. |
Good spot, I guess you noticed this by running an application? Perhaps I should add the type hints as this is not really a runtime exception but a develop time syntax error. |
2921205
to
d52f300
Compare
Resolves #59
Added default initialise methods to Sender and Updater base classes.
Added initialise method to Attribute, checks for handler and calls the method.
Moved initialise into BaseController class, loops over attributes calling initialise with a reference to self.
Added unit test for Attribute class.
Fixes #59
Fixes #130