refactor: replace if/type chains with match/case - #185
Open
SoundMatt wants to merge 1 commit into
Open
Conversation
Convert isinstance/type() if-chains to match/case in: - dbus_types.gen_dbus_type(): each branch now a match arm; extract _collect_type_definitions() helper to share struct/typedef/enum registration between Namespace and Interface cases - dbus_types.collect_types(): collapse four sequential if-checks into a clean match with per-type cases; move common logic to helper - franca_to_ifex.translate_type(): four if-blocks become match arms, guard clause on the first Reference case is preserved Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
Collaborator
|
Good code-style fix but heavy changes to the core functionality so it needs careful testing. |
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.
Closes #140
Changes
Converts
isinstance/type()if-chains tomatch/casein the two files called out in the issue:ifex/models/DBus/dbus_types.pygen_dbus_type()— six branches replaced by five match arms.Typedef | Enumerationwritten as a single OR pattern. Accumulating into a mutabledbus_typestring replaced by early returns.collect_types()— four separateif type(node) in [...]checks (which could fall through into each other) replaced by a cleanmatchwith per-type cases. Shared struct/typedef/enum registration logic extracted into_collect_type_definitions()to avoid duplication between theNamespaceandInterfacearms.ifex/input_filters/franca/franca_to_ifex.pytranslate_type()— four sequentialif type(t) isguards replaced bymatcharms. The guarded first Reference case (type(t.reference) in [...]) is preserved as a match guard. All comments kept in place.Notes