Skip to content

Commit

Permalink
Fix comparison between set and dictionary (#146)
Browse files Browse the repository at this point in the history
The check `card_ords == {}` will always evaluate to `False`, even when it is empty. This is because `card_ords` is a set, and `{}` is a dictionary.

>>> set() == {}
False

The intended check was probably something like "card ords is empty", which can be expressed as `if not card_ords`.
  • Loading branch information
ernieIzde8ski authored Nov 12, 2024
1 parent 9f78e4b commit c8417ad
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion genanki/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _cloze_cards(self):
field_value = self.fields[field_index] if field_index >= 0 else ""
# update card_ords with each cloze reference N, e.g. "{{cN::...}}"
card_ords.update(int(m)-1 for m in re.findall(r"{{c(\d+)::.+?}}", field_value, re.DOTALL) if int(m) > 0)
if card_ords == {}:
if not card_ords:
card_ords = {0}
return([Card(ord) for ord in card_ords])

Expand Down

0 comments on commit c8417ad

Please sign in to comment.