Skip to content

usb-device-cdc: Fix default timeout in CDCInterface.init().#1080

Open
andrewleech wants to merge 1 commit intomicropython:masterfrom
andrewleech:fix-cdc-default-timeout
Open

usb-device-cdc: Fix default timeout in CDCInterface.init().#1080
andrewleech wants to merge 1 commit intomicropython:masterfrom
andrewleech:fix-cdc-default-timeout

Conversation

@andrewleech
Copy link
Contributor

Summary

CDCInterface is broken when constructed with default arguments — calling read(), write(), readinto(), or flush() raises TypeError: unsupported types for __ge__: 'int', 'NoneType' because self._timeout ends up as None.

__init__ sets self._timeout = 1000 then immediately calls self.init(**kwargs). The init() method has timeout=None as default and unconditionally assigns self._timeout = timeout, overwriting the 1000 with None. All the stream methods then fail on time.ticks_diff(...) >= self._timeout.

Fix is changing the default parameter from timeout=None to timeout=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._timeout is now 1000 after default construction and read(), write(), readinto() all work without error. Also verified explicit timeout= parameter still takes effect.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants