Skip to content

Commit

Permalink
Minor type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotwrobson committed Jun 17, 2023
1 parent 54295b4 commit 5313990
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions automata/base/automaton.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ def __repr__(self) -> str:
)
return f"{self.__class__.__qualname__}({values})"

def __contains__(self, input_str: str) -> bool:
def __contains__(self, item: Any) -> bool:
"""Returns whether the word is accepted by the automaton."""
return self.accepts_input(input_str)

if not isinstance(item, str):
return False

return self.accepts_input(item)
1 change: 1 addition & 0 deletions tests/test_dfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def test_accepts_input_false(self) -> None:
"""Should return False if DFA input is rejected."""
self.assertFalse(self.dfa.accepts_input("011"))
self.assertNotIn("011", self.dfa)
self.assertNotIn(1, self.nfa)

def test_read_input_step(self) -> None:
"""Should return validation generator if step flag is supplied."""
Expand Down
1 change: 1 addition & 0 deletions tests/test_nfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def test_accepts_input_false(self) -> None:
"""Should return False if NFA input is rejected."""
self.assertFalse(self.nfa.accepts_input("abba"))
self.assertNotIn("abba", self.nfa)
self.assertNotIn(1, self.nfa)

def test_cyclic_lambda_transitions(self) -> None:
"""Should traverse NFA containing cyclic lambda transitions."""
Expand Down

0 comments on commit 5313990

Please sign in to comment.