-
Notifications
You must be signed in to change notification settings - Fork 20
[core] fix field detection for escaped % and { format styles - #75
[core] fix field detection for escaped % and { format styles #75dylanpulver wants to merge 2 commits into
Conversation
`parse()` read `%%(name)s` and `{{name}}` as fields even though both are
escaped literals, and read a `{` style conversion or format spec as part
of the field name, so `{levelname:>8}` produced a `"levelname:>8": null`
key and dropped `levelname`.
`%` now skips `%%` the same way the `$` style skips `$$` (nhairs#69), and `{`
uses `string.Formatter`, which is what `logging.StrFormatStyle.validate`
parses the same string with.
Assisted-by: claude-opus-5
A regex-only fix passes the plain `{levelname:>8}` case but reads
`{width}` out of `{levelname:>{width}}`, which stdlib accepts.
Assisted-by: claude-opus-5
@nhairs
nhairs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dylanpulver, overall looks good, though have a number of comments for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need these comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be merged with test_percentage_format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove this rather than marking it as deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add your own
Thanks @dylanpulver line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should have a reference to the issue
Closes #74.
parse()reads escaped literals as fields:%%(b)sin a%format,{{b}}in a{one. #69 fixed this for$; these two were left.{also folds a conversion or format spec into the name, so"{levelname:>8} {message}"— an ordinary stdlib format thatStrFormatStyle.validate()accepts — logs{"levelname:>8": null, "message": "hello"}.Changes
%: skip%%, mirroring the$fix.{: usestring.Formatter, which is whatlogging.StrFormatStyle.validateparses the same string with. Covers{{/}},!r,:>8, and nested specs like{levelname:>{width}}.STYLE_STRING_FORMAT_REGEXis kept but unused — say the word and I'll drop it.Testing
pytest tests: 224 passed, 218 before. Two new tests beside the existing per-style ones. black/pylint/mypy/validate-pyproject clean.Oracle: the substitution engine itself (
fmt % tracking_dict,string.Formatter().parse,Template.get_identifiers). Over 37 formats$agreed 7/7 as a control;%+{diverged 13x before, 1 after — the remainder is"{}", whichvalidate()skips too.Reverting only the
core.pychange fails the 6 new cases and nothing else. A regex-only alternative passes{levelname:>8}but readswidthout of{levelname:>{width}}; hence that case in the test.One behaviour change: with
validate=Falsea malformed{format now raises at construction instead of silently yielding no fields.Prepared with AI assistance; I reviewed and tested it locally.