Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify transitions data structure #11

Open
jvoigtlaender opened this issue Apr 17, 2024 · 0 comments
Open

Simplify transitions data structure #11

jvoigtlaender opened this issue Apr 17, 2024 · 0 comments
Assignees

Comments

@jvoigtlaender
Copy link
Member

Something that's been bugging me for a while is this code:

if dest_key not in globals.transitions[source_key]:
globals.transitions[source_key][dest_key] = {label: "Option 1"}
else:
counter = transition_counter.get((source_key, dest_key), 1) + 1
transition_counter[(source_key, dest_key)] = counter
globals.transitions[source_key][dest_key][label] = f"Option {counter}"

Specifically, the whole "Option" and counter business. It leads to structures like the following (or did at a time, based on inspection; I guess nothing has changed around this):

transitions = {
    "A": {"C": {"y": "Option 1", "a": "Option 2"}, "B": "f", "D": "z"},
    "B": {"D": {"b": "Option 3", "x": "Option 4"}},
    "C": {"D": "c", "A": "e"},
    "D": {"C": "d", "A": "e"},
}

I never got an explanation of what the numbers are used for. I think they simply aren't used.
The numbers don't seem to affect the behavior of the app. The user is never asked for one of these numbers, etc. So, it seems the data structure could simply be more like

transitions = {
    "A": {"C": ["y", "a"], "B": "f", "D": "z"},
    "B": {"D": ["b", "x"]},
    "C": {"D": "c", "A": "e"},
    "D": {"C": "d", "A": "e"},
}

What bugs me further is that the transitions global is type-annotated thus:

transitions: Dict[str, List[str]] = {}
which seems to be in disagreement with what the structure above shows. Is the "type checker" not catching this mismatch for some reason?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants