Skip to content

Split comma-separated Keywords in JSON metadata - #559

Open
PDGGK wants to merge 1 commit into
python:mainfrom
PDGGK:fix-json-comma-keywords
Open

PDGGK wants to merge 1 commit into
python:mainfrom
PDGGK:fix-json-comma-keywords

Conversation

@PDGGK

@PDGGK PDGGK commented Nov 11, 2026

Copy link
Copy Markdown

metadata(name).json["keywords"] returns one item, the whole header, for distributions built by current backends. Core Metadata separates keywords with commas and setuptools writes them that way, but json splits the field on whitespace only. With pytest 9.0.2 installed:

>>> importlib_metadata.metadata("pytest")["Keywords"]
'test,unittest'
>>> importlib_metadata.metadata("pytest").json["keywords"]
['test,unittest']

black 26.10.1 and urllib3 2.7.0 behave the same way. pip inspect, which emits the same PEP 566 JSON form, reports ['test', 'unittest'] for that install. A keyword that contains a space is split in the wrong place: Keywords: sample package,tool becomes ['sample', 'package,tool'], and sample, package becomes ['sample,', 'package'].

PEP 566 says to split on whitespace, but the Core Metadata specification defines Keywords as comma-separated, and notes that the earlier space-separated example never matched what distutils and setuptools wrote. json now splits on commas when the value contains one and on whitespace otherwise, which is also the rule pip uses. Space-separated values such as Pygments' syntax highlighting give the same result as before. The stdlib importlib.metadata (Python 3.13.18 here) has the same behavior today.

test_as_json_comma_separated_keywords covers sample,package, sample, package and sample package,tool. All three subtests fail on main, for example with assert ['sample,package'] == ['sample', 'package']. The full suite passes (275 passed, 1 skipped) on Python 3.12.3 with the test, check, cover, enabler and type extras, which run the ruff, ruff format and mypy checks. I also compared json["keywords"] with pip inspect for black, pytest, urllib3 and Pygments before and after the change. I did not test other Python versions, Windows or macOS, or the CPython copy of the module.

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