usb-device-cdc: Fix default timeout in CDCInterface.init().#1080
Open
andrewleech wants to merge 1 commit intomicropython:masterfrom
Open
usb-device-cdc: Fix default timeout in CDCInterface.init().#1080andrewleech wants to merge 1 commit intomicropython:masterfrom
andrewleech wants to merge 1 commit intomicropython:masterfrom
Conversation
CDCInterface.__init__() sets self._timeout = 1000, then calls self.init(**kwargs). The init() method had timeout=None as default, which unconditionally overwrites self._timeout with None. This causes TypeError in read(), write(), readinto(), and ioctl() which all compare int >= self._timeout. Set the default timeout=1000 in init() to match the intended default, consistent with how other parameters (baudrate, bits, etc.) have their defaults specified directly in the init() signature. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
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.
Summary
CDCInterfaceis broken when constructed with default arguments — callingread(),write(),readinto(), orflush()raisesTypeError: unsupported types for __ge__: 'int', 'NoneType'becauseself._timeoutends up asNone.__init__setsself._timeout = 1000then immediately callsself.init(**kwargs). Theinit()method hastimeout=Noneas default and unconditionally assignsself._timeout = timeout, overwriting the 1000 with None. All the stream methods then fail ontime.ticks_diff(...) >= self._timeout.Fix is changing the default parameter from
timeout=Nonetotimeout=1000, consistent with how the other init parameters (baudrate, bits, parity, stop) all carry their real defaults in the signature.Testing
Tested on ESP32-S3 as USB CDC device with an MIMXRT1170-EVK as USB host. Confirmed
cdc._timeoutis now 1000 after default construction andread(),write(),readinto()all work without error. Also verified explicittimeout=parameter still takes effect.