Repository navigation
Raise SerialException when using a port that is not open - #158
Open
Happyfield7 wants to merge 3 commits into
Open
Happyfield7 wants to merge 3 commits into
Happyfield7 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #158 +/- ##
==========================================
+ Coverage 94.38% 94.40% +0.01%
==========================================
Files 25 25
Lines 4437 4451 +14
==========================================
+ Hits 4188 4202 +14
Misses 249 249 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Happyfield7
force-pushed
the
fix-closed-port-errors
branch
from
November 20, 2026 17:47
f2c3e99 to
fac2c20
Compare
puddly
reviewed
Nov 20, 2026
Happyfield7
force-pushed
the
fix-closed-port-errors
branch
from
November 20, 2026 18:04
7f65f7b to
3b54103
Compare
puddly
reviewed
Nov 20, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Reading, writing, flushing, resetting buffers, reading byte counts or using modem pins on a sync port that is not open (never opened, or closed) fails with a bare
AssertionErrorfrom an internal assert, which tells the caller nothing. Underpython -Othe asserts are removed and the same calls fail withTypeErrororAttributeErrorinstead. Some socket, RFC 2217 and ESPHome calls (flush, the byte counts,reset_write_buffer) silently succeed, so the mistake goes unnoticed.Change
BaseSerial._check_broken()now first raisesSerialException("Attempting to use a port that is not open"), pyserial's message, before re-raising a stored disconnect error; it runs at the start of the public sync methods and each backend'snum_unread_bytes/num_unwritten_bytes. Async transports check only the stored disconnect error, since some never open their internal sync object.dtr/rtson a closed port keep their on-open values, andreconfigure_portkeeps its own message.Testing
Pair tests cover ten operations on a never-opened and a closed port; a compat test checks that
serial.Serialraisesserial.SerialExceptionwith the same message. Full suite passes on macOS and Debian sid, andpython -Ogives the sameSerialException.