stacktrace for empty list of suggestions
Summary
When finesse tries to suggest for a non-existing key, but there are no suggestions, it produces a stacktrace
Steps to reproduce
E.g.:
import finesse
model = finesse.Model()
model.parse("laser l1")
model.parse("space s1 l1.p1 lens1.p1 1.0")
model.parse("lens lens2")
Bug behavior
A stacktrace is produced, pointing at
1 model = finesse.Model()
3 model.parse("laser l1")
----> 4 model.parse("space s1 l1.p1 lens1.p1 1.0")
5 model.parse("lens lens2")
and ending with
File ~/finesse3/src/finesse/exceptions.py:138, in ModelAttributeError.__init__(self, model, pieces)
136 spell.word_frequency.load_words(dir(curr))
137 candidates = spell.candidates(key)
--> 138 if key not in spell.candidates(key):
139 # Ensure suggestions are sorted alphabetically.
140 suggestions = sorted([correct + option for option in candidates])
141 msg += f"\n\nDid you mean: {', '.join(suggestions)}?"
TypeError: argument of type 'NoneType' is not iterable
What is the expected correct behavior?
Ideally it should have suggested that I meant lens2
.
Also note that reordering the space
and lens
lines does find the correct suggestion.
Possible Fixes
Simplest is to print that there are no suggestions (I'll produce a MR that does that).