usb-device-cdc: optmise CDCInterface constructor - #1138
Merged
Conversation
dpgeorge
commented
Jul 15, 2026
| cdc = CDCInterface() | ||
| cdc.init(timeout=0) # zero timeout makes this non-blocking, suitable for os.dupterm() | ||
| # Zero timeout makes this non-blocking, suitable for os.dupterm(). | ||
| cdc = CDCInterface(timeout=0) |
Member
Author
There was a problem hiding this comment.
We don't have to make this change, but I thought it was a little cleaner to set the timeout in the constructor.
Member
Author
|
@projectgus curious what you think about this change? I can close the PR if you don't think it's a good idea. |
projectgus
approved these changes
Jul 29, 2026
projectgus
left a comment
Contributor
There was a problem hiding this comment.
Looks like a nice optimisation to me!
Don't set instance attributes that will just be reset by `self.init()`. Saves 30 bytes of bytecode. Signed-off-by: Damien George <damien@micropython.org>
Makes the example a little bit simpler. Signed-off-by: Damien George <damien@micropython.org>
dpgeorge
force-pushed
the
usb-device-cdc-optimise
branch
from
July 29, 2026 07:59
1498098 to
dbb3b45
Compare
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
Don't set
CDCInterfaceinstance attributes that will just be reset byself.init().Saves 30 bytes of bytecode.
Also simplify the associated example.
Testing
Built, and tested the example on RPI_PICO. It still works.
Trade-offs and Alternatives
This makes it less clear what exactly are the instance attributes, because their initialisation is done in
.init(), not the constructor. The added comment tries to work around that.Generative AI
Not used.