Repository: sciunto-org/python-bibtexparser

Issue:
Remove field
**Is your feature request related to a problem? Please describe.**
One of the reasons I parse is to remove fields (added by reference managers) that I do not want. With v2 it is not clear to me how I can do that?

**Describe the solution you'd like**
```python
@ARTICLE{Cesar2013,
  author = {Jean César},
  title = {An amazing title},
  year = {2013},
  volume = {12},
  pages = {12--23},
  journal = {Nice Journal},
  file = {/path/on/my/disk.pdf}
}
"""

import bibtexparser
library = bibtexparser.parse_string(bibtex_str)
library.entries[0].pop("file")
print(bibtexparser.write_string(library))
```

should give

```bib
@ARTICLE{Cesar2013,
  author = {Jean César},
  title = {An amazing title},
  year = {2013},
  volume = {12},
  pages = {12--23},
  journal = {Nice Journal}
}
```

**Use cases**
Many reference managers add many fields that one does not want to keep in submissions. Even more important is that some styles might show some fields that you would like to throw away. 

**Describe alternatives you've considered**
-

**Remaining Questions (Optional)**
Please tick all that apply:

- [x] I would be willing to to contribute a PR to fix this issue.
- [x] This issue is a blocker, I'd be greatful for an early fix.


Discussion:

Patch:
diff --git a/bibtexparser/model.py b/bibtexparser/model.py
index b53876a..2e37b00 100644
--- a/bibtexparser/model.py
+++ b/bibtexparser/model.py
@@ -304,6 +304,16 @@ class Entry(Block):
         else:
             self._fields.append(field)
 
+    def pop_field(self, key: str) -> Optional[Field]:
+        """Removes and returns the field with the given key, if present."""
+        try:
+            field = self.fields_dict.pop(key)
+        except KeyError:
+            return None
+
+        self._fields = [f for f in self._fields if f.key != key]
+        return field
+
     def __getitem__(self, key: str) -> Any:
         """Dict-mimicking index.
 
@@ -326,6 +336,14 @@ class Entry(Block):
         """
         self.set_field(Field(key, value))
 
+    def __delitem__(self, key):
+        """Dict-mimicking index.
+
+        This serves for partial v1.x backwards compatibility,
+        as well as for a shorthand for `pop_field`.
+        """
+        self.pop_field(key)
+
     def items(self):
         """Dict-mimicking, for partial v1.x backwards compatibility.
 


Test patch:
diff --git a/tests/test_model.py b/tests/test_model.py
index a2d5c3b..4807bc8 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -1,6 +1,8 @@
 from copy import copy, deepcopy
 from textwrap import dedent
 
+import pytest
+
 from bibtexparser.model import (
     Entry,
     ExplicitComment,
@@ -311,3 +313,9 @@ def test_entry_fields_shorthand():
     assert entry.fields_dict["myNewField"].key == "myNewField"
     assert entry.fields_dict["myNewField"].value == "new_value"
     assert entry.fields_dict["myNewField"].start_line is None
+
+    del entry["myNewField"]
+    assert "myNewField" not in entry.fields_dict
+    assert len([f for f in entry.fields if f.key == "myNewField"]) == 0
+    with pytest.raises(KeyError):
+        entry["myNewField"]