Skip to content

✨ Support dict(entry) by adding Entry.keys() and __iter__ - #631

Merged
MiWeiss merged 1 commit into
mainfrom
feat/629-entry-keys-iter
Oct 2, 2026
Merged

MiWeiss merged 1 commit into
mainfrom
feat/629-entry-keys-iter

Conversation

@MiWeiss

@MiWeiss MiWeiss commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Entry mimics a dict (items(), __getitem__, __contains__, ...) but has no keys() or __iter__, so the obvious conversions fail:

entry = bibtexparser.parse_string("@article{key, title={T}}").entries[0]
dict(entry)   # KeyError: 0
list(entry)   # KeyError: 0
{**entry}     # TypeError: 'Entry' object is not a mapping

Fix: add Entry.keys() and Entry.__iter__, both derived from items() (ENTRYTYPE, ID, then field keys), so dict(entry) == dict(entry.items()). Entry still isn't a Mapping/Collection (no __len__), so the middleware's collection check is unaffected.

Tests: one new test in tests/test_model.py; full suite 2778 passed, 12 skipped. Pre-commit clean.

Refs #629

Entry mimicked dicts via items(), __getitem__ etc., but lacked keys() and
__iter__, so dict(entry) and list(entry) raised KeyError: 0 and {**entry}
raised TypeError. Both return the keys in items() order.

Refs #629
@MiWeiss
MiWeiss merged commit c9f1628 into main Oct 2, 2026
18 checks passed
MiWeiss added a commit that referenced this pull request Oct 2, 2026
Relies on Entry.keys()/__iter__ from #631.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant