Skip to content

Commit acbd25c

Browse files
authored
Fix non-clearing output when nothing is outputted (#60)
When the the update does not print anything the output is not cleared, since it waits for an output to be cleared. We fix this by printing an empty string to invoke the clearning of the output * Ignore B040 for checks failing Through an update linter complained that no error message is raised, but we do not want to raise an error message when one of the checks raises one.
1 parent 7519ac6 commit acbd25c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/scwidgets/check/_check.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ def check_function(self) -> ChecksResult:
218218
if self._fingerprint is not None:
219219
try:
220220
output = self._fingerprint(*output)
221-
except Exception as exception:
221+
except ( # we do not raise here since it is passed to widget output # noqa B040
222+
Exception
223+
) as exception:
222224
if python_version() >= "3.11":
223225
exception.add_note(
224226
"An error was raised in fingerprint function, "

src/scwidgets/exercise/_widget_code_exercise.py

+5
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ def _on_click_update_action(self) -> bool:
657657
raised_error = True
658658
raise e
659659

660+
# The clear_output command at the beginning of the function waits till
661+
# something is printed. If nothing is printed, it is not cleared. We
662+
# enforce it to be invoked by printing an empty string
663+
print("", end="")
664+
660665
return not (raised_error)
661666

662667
def run_update(self):

0 commit comments

Comments
 (0)