Invert default value logic for BusABC._is_shutdown#1774
Merged
hardbyte merged 1 commit intohardbyte:mainfrom Apr 29, 2024
Merged
Invert default value logic for BusABC._is_shutdown#1774hardbyte merged 1 commit intohardbyte:mainfrom
hardbyte merged 1 commit intohardbyte:mainfrom
Conversation
The destructor of BusABC gives a warning when shutdown() was not previously called on the object after construction. However, if the construction fails (e.g. when the derived bus class constructor raises an exception), there is no way to call shutdown() on the unfinished object, and it is not necessary either. Initialize the _is_shutdown flag to False initially and flip it to True only when the parent class constructor runs, which usually happens last in derived classes. That avoids the shutdown warning for objects that failed to initialize at all.
hardbyte
approved these changes
Apr 29, 2024
Owner
hardbyte
left a comment
There was a problem hiding this comment.
Thanks - seems very reasonable.
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.
The destructor of BusABC gives a warning when shutdown() was not previously called on the object after construction. However, if the construction fails (e.g. when the derived bus class constructor raises an exception), there is no way to call shutdown() on the unfinished object, and it is not necessary either.
Initialize the _is_shutdown flag to False initially and flip it to True only when the parent class constructor runs, which usually happens last in derived classes. That avoids the shutdown warning for objects that failed to initialize at all.
This is an alternative approach solving the same problem as #1771, but that PR could be merged independently to have an error log message before raising the constructor exception.