Skip to content

馃悰 Keep month field enclosing when the value is not transformed - #605

Merged
MiWeiss merged 3 commits into
mainfrom
fix/month-enclosing
Sep 2, 2026
Merged

MiWeiss merged 3 commits into
mainfrom
fix/month-enclosing

Conversation

@MiWeiss

@MiWeiss MiWeiss commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

_MonthInterpolator.transform_entry assigns month.value even when the month could not be resolved. The Field.value setter resets enclosing, so the no-enclosing demand on a reference is lost and AddEnclosingMiddleware braces it into a literal.

>>> lib = bibtexparser.parse_string("@article{a, month = foo}", append_middleware=[MonthLongStringMiddleware()])
>>> bibtexparser.write_string(lib)
'@article{a,\n\tmonth = {foo}\n}\n'

Fix: assign only when the value actually changed, comparing type too, since "1" to 1 is a real transformation. _demanded_enclosing and the metadata line stay outside the guard, because MonthAbbreviationMiddleware demands no-enclosing for an already-correct jan.

model.py untouched; the setter's reset is documented behavior.

Tests: 5 cases across all three month middlewares, 3 fail before. Suite 2581 passed, from 2576.


馃 Generated with Claude Code

The month middlewares assigned `Field.value` unconditionally, and that
setter resets `Field.enclosing` to None. For values the middleware cannot
resolve (bibtex string references like `month = foo`, or concatenations
like `mymonth # "foo"`), this discarded the `no-enclosing` demand, so
`AddEnclosingMiddleware` wrapped them in braces and turned a reference
into a literal. The value is now assigned only when it actually changed
(comparing type as well, so e.g. "1" -> 1 still counts as a change).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@MiWeiss
MiWeiss force-pushed the fix/month-enclosing branch from ebcf150 to 66b450e Compare September 2, 2026 20:03
@MiWeiss

MiWeiss commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

lgtm

@MiWeiss
MiWeiss force-pushed the fix/month-enclosing branch from 199f18c to 4d107b9 Compare September 2, 2026 20:38
@MiWeiss
MiWeiss merged commit 29b01cf into main Sep 2, 2026
16 checks passed
@MiWeiss
MiWeiss deleted the fix/month-enclosing branch September 10, 2026 20:04
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