diff --git a/bibtexparser/model.py b/bibtexparser/model.py index fc57a28..b6b38be 100644 --- a/bibtexparser/model.py +++ b/bibtexparser/model.py @@ -315,6 +315,10 @@ def pop_field(self, key: str) -> Optional[Field]: self._fields = [f for f in self._fields if f.key != key] return field + def __contains__(self, key: str) -> bool: + """Dict-mimicking ``in`` operator.""" + return key in self.fields_dict + def __getitem__(self, key: str) -> Any: """Dict-mimicking index. diff --git a/tests/test_model.py b/tests/test_model.py index 4807bc8..3f98771 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -77,6 +77,12 @@ def test_entry_deepcopy(): assert entry_1.fields_dict["field"] == entry_2.fields_dict["field"] +def test_entry_contain(): + entry = Entry("article", "key", [Field("field", "value", 1)], 1, "raw") + assert "field" in entry + assert "other" not in entry + + def test_string_equality(): # Equal to itself string_1 = String(