fix(win32): handle missing asyncio protocol methods in _MethodProxy#97
fix(win32): handle missing asyncio protocol methods in _MethodProxy#97HiDiHo01 wants to merge 7 commits into
Conversation
On Windows, when a serial port closes or disconnects, asyncio's proactor event loop calls eof_received() on the transport's protocol. _MethodProxy looks this up via __getattr__ from a fixed _mapping dict, but eof_received is not in that mapping, so a KeyError is raised:
Fatal error: protocol.eof_received() call failed.
...
File ".../serialx/platforms/serial_win32.py", line 434, in __getattr__
return self._mapping[name]
KeyError: 'eof_received'
This surfaces as a noisy Fatal error log on every HA shutdown/restart cycle when a Zigbee or other serial device is connected on Windows.
|
Thanks for the PR. I think it would be better to just proxy |
|
Fair point — it's more explicit and doesn't silently swallow arbitrary unknown attribute access. The correct behaviour for So the mapping entry would be: "eof_received": lambda: False,That's more honest than a catch-all no-op: it documents exactly which asyncio protocol method was missing and returns the semantically correct value rather than Update the PR description accordingly — replace the proposed |
Change the __getattr__ method to raise an AttributeError instead of returning a no-op lambda for missing attributes.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #97 +/- ##
==========================================
- Coverage 92.23% 92.18% -0.05%
==========================================
Files 22 22
Lines 3632 3635 +3
==========================================
+ Hits 3350 3351 +1
- Misses 282 284 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add eof_received method to handle EOF in asyncio proactor
| self._mapping = mapping | ||
|
|
||
| def eof_received(self): | ||
| # PATCH: asyncio proactor calls this on pipe EOF; _MethodProxy doesn't |
There was a problem hiding this comment.
Make sure you have prek set up. It will flag that this method has no docstring or type annotation.
Also, please remove the LLM comments. return False doesn't need four lines of explanation.
Add return type annotation for eof_received method.
On Windows, when a serial port closes or disconnects, asyncio's proactor event loop calls eof_received() on the transport's protocol. _MethodProxy looks this up via getattr from a fixed _mapping dict, but eof_received is not in that mapping, so a KeyError is raised: Fatal error: protocol.eof_received() call failed.
...
File ".../serialx/platforms/serial_win32.py", line 434, in getattr
return self._mapping[name]
KeyError: 'eof_received'
This surfaces as a noisy Fatal error log on every HA shutdown/restart cycle when a Zigbee or other serial device is connected on Windows.