Skip to content

Commit

Permalink
Add comment to subtle code, and rename variable
Browse files Browse the repository at this point in the history
Rename "fields_map" variable as types should be avoided in variable
names. Add a comment to explain the purpose of the map.

Ref. None
  • Loading branch information
kanigsson committed Apr 9, 2024
1 parent 52e6639 commit d08b28a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions rflx/model/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,11 +1146,26 @@ def substitute(expression: expr.Expr) -> expr.Expr:
self.package,
)

fields_map = {f.identifier: f.identifier for f in (INITIAL, *types, FINAL)}
# While field_identifiers is an identity map, it still permits looking up a the
# canonical name of an identifier. This is because the keys are instances
# of ID, whose equality is case insensitive.

field_identifiers = {f.identifier: f.identifier for f in (INITIAL, *types, FINAL)}

structure = [
Link(
Field(ID(fields_map[l.source.identifier], location=l.source.identifier.location)),
Field(ID(fields_map[l.target.identifier], location=l.target.identifier.location)),
Field(
ID(
field_identifiers[l.source.identifier],
location=l.source.identifier.location,
),
),
Field(
ID(
field_identifiers[l.target.identifier],
location=l.target.identifier.location,
),
),
l.condition.substituted(substitute),
l.size.substituted(substitute),
l.first.substituted(substitute),
Expand Down

0 comments on commit d08b28a

Please sign in to comment.