Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Entry: Dict-mimicking in operator. #458

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bibtexparser/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,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
MiWeiss marked this conversation as resolved.
Show resolved Hide resolved

def __getitem__(self, key: str) -> Any:
"""Dict-mimicking index.

Expand Down
6 changes: 6 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading