Skip to content

Commit 5ffcb7f

Browse files
committed
Rename json_metadata to metadata_dict
1 parent 70d0336 commit 5ffcb7f

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/pip/_internal/metadata/_json.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def json_name(field: str) -> str:
3939

4040

4141
def msg_to_json(msg: Message) -> Dict[str, Any]:
42+
"""Convert a Message object into a JSON-compatible dictionary."""
43+
4244
def sanitise_header(h: Union[Header, str]) -> str:
4345
if isinstance(h, Header):
4446
chunks = []
@@ -67,6 +69,8 @@ def sanitise_header(h: Union[Header, str]) -> str:
6769
else:
6870
value = sanitise_header(msg.get(field))
6971
if key == "keywords":
72+
# Accept both comma-separated and space-separated
73+
# forms, for better compatibility with old data.
7074
if "," in value:
7175
value = [v.strip() for v in value.split(",")]
7276
else:

src/pip/_internal/metadata/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def metadata(self) -> email.message.Message:
364364
raise NotImplementedError()
365365

366366
@property
367-
def json_metadata(self) -> Dict[str, Any]:
367+
def metadata_dict(self) -> Dict[str, Any]:
368368
"""PEP 566 compliant JSON-serializable representation of METADATA or PKG-INFO.
369369
370370
This should return an empty dict if the metadata file is unavailable.

tests/unit/metadata/test_metadata.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ class FakeDistribution(BaseDistribution):
6060
assert isinstance(direct_url.info, ArchiveInfo)
6161

6262

63-
def test_json_metadata(tmp_path: Path) -> None:
64-
"""Basic test of BaseDistribution json_metadata.
63+
def test_metadata_dict(tmp_path: Path) -> None:
64+
"""Basic test of BaseDistribution metadata_dict.
6565
6666
More tests are available in the original pkg_metadata project where this
6767
function comes from, and which we may vendor in the future.
6868
"""
6969
wheel_path = make_wheel(name="pkga", version="1.0.1").save_to_dir(tmp_path)
7070
wheel = FilesystemWheel(wheel_path)
7171
dist = get_wheel_distribution(wheel, "pkga")
72-
json_metadata = dist.json_metadata
73-
assert json_metadata["name"] == "pkga"
74-
assert json_metadata["version"] == "1.0.1"
72+
metadata_dict = dist.metadata_dict
73+
assert metadata_dict["name"] == "pkga"
74+
assert metadata_dict["version"] == "1.0.1"

0 commit comments

Comments
 (0)