Skip to content

Commit

Permalink
Modify Trie code to avoid a mypy error
Browse files Browse the repository at this point in the history
cursor is a dict, cursor.get(.., None) returns another dict or None
mypy is being confused as the variable is overwritten, use another
temp variable to handle the case where letter is not in the cursor dict
  • Loading branch information
enzbang committed Oct 27, 2023
1 parent f9c158d commit 527dc1d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/e3/collection/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ def match(self, word: str, delimiter: str | None = None) -> bool:
if self.END_MARKER in cursor and (not delimiter or letter in delimiter):
return True
else:
cursor = cursor.get(letter, None)
if cursor is None:
new_cursor = cursor.get(letter, None)
if new_cursor is None:
return False
else:
cursor = new_cursor

return self.END_MARKER in cursor

0 comments on commit 527dc1d

Please sign in to comment.