Remove pointless try/except in polling_task #2091
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #2090. This PR goes a step further.
This code is a stack of clever hacks.
pymodbus/pymodbus/transport/serialtransport.py
Lines 45 to 48 in d6704a2
The purpose of this code is to cancel
self.poll_task()and then set it toNoneafterwards.Because the code is sync,
awaitcannot be used to ensure the cancellation.Hack #1 - use
ensure_futureThen
ruffcomplains withRUF006. This could have been safely ignored - nobody cares if the GC cleans up, since it's immediately set toNone. Instead...Hack #2 - use
self.futureto hold a reference.Next
mypycomplains thatself.futureis untyped.Hack #3 - add an annotation to the constructor.
Looking at
polling_task, I see no purpose to catchingasyncio.CancelledTask. All it does is callself.close().... which is the very code that cancelled it!I think the whole
try/Exceptand stack of hacks can be removed. :)