Skip to content

refactor: replace if/type chains with match/case - #185

Open
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:feat/ifex-140-match-case
Open

refactor: replace if/type chains with match/case#185
SoundMatt wants to merge 1 commit into
COVESA:masterfrom
SoundMatt:feat/ifex-140-match-case

Conversation

@SoundMatt

Copy link
Copy Markdown
Contributor

Closes #140

Changes

Converts isinstance/type() if-chains to match/case in the two files called out in the issue:

ifex/models/DBus/dbus_types.py

gen_dbus_type() — six branches replaced by five match arms. Typedef | Enumeration written as a single OR pattern. Accumulating into a mutable dbus_type string replaced by early returns.

collect_types() — four separate if type(node) in [...] checks (which could fall through into each other) replaced by a clean match with per-type cases. Shared struct/typedef/enum registration logic extracted into _collect_type_definitions() to avoid duplication between the Namespace and Interface arms.

ifex/input_filters/franca/franca_to_ifex.py

translate_type() — four sequential if type(t) is guards replaced by match arms. The guarded first Reference case (type(t.reference) in [...]) is preserved as a match guard. All comments kept in place.

Notes

  • No behaviour changes; pure structural refactor.
  • Requires Python ≥ 3.10 (already required by the repo).

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>
@gunnar-mb

Copy link
Copy Markdown
Collaborator

Good code-style fix but heavy changes to the core functionality so it needs careful testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(code style) Refactor code with match/case

2 participants