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

engine: fix possible clear_translator_state issue #1547

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news.d/bugfix/1547.core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix possible exception when calling `Engine.clear_translator_state(undo=True)`.
3 changes: 2 additions & 1 deletion plover/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ def translator_state(self, state):
def clear_translator_state(self, undo=False):
if undo:
state = self._translator.get_state()
self._formatter.format(state.translations, (), None)
if state.translations:
self._formatter.format(state.translations, (), None)
self._translator.clear_state()

@property
Expand Down
3 changes: 3 additions & 0 deletions test/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,6 @@ def test_engine_running_state(engine):
# Running state is kept throughout.
engine.set_output(True)
assert engine.translator_state == running_state

def test_undo_and_clear_empty_translator_state(engine):
engine.clear_translator_state(undo=True)