Skip to content

Fix inherited metadata field validation and serialization - #1454

Open
AryanRG wants to merge 1 commit into
pypa:mainfrom
AryanRG:fix-metadata-subclass-fields
Open

AryanRG wants to merge 1 commit into
pypa:mainfrom
AryanRG:fix-metadata-subclass-fields

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 16, 2026 •

Copy link
Copy Markdown

A Metadata subclass currently rejects valid input through its inherited from_raw() and from_email() methods: fields such as name, version, and requires_dist are reported as unrecognized because validation looks only in the subclass's own __dict__. With validate=False, as_rfc822() instead silently drops all inherited headers, leaving only the description body.

Use Metadata.__dict__ as the core field schema in both places. Values are still read through getattr() on the instance, preserving descriptor validation and subclass attribute overrides. The four regression cases cover both factories with validation enabled and disabled, and compare the complete serialized metadata with the base class output. All four fail on ef837aad3127167671eb37b9f6bd8a94ec7ce26e before the fix.

Validation on macOS:

  • Python 3.13: python -m coverage run -m pytest -q — 62,496 passed, 1 glibc-only test skipped, 427 property tests deselected by the default configuration.
  • python -m coverage report — 100% statement and branch coverage, including metadata.py.
  • Python 3.10: python -m pytest tests/test_metadata.py -q — 348 passed.
  • nox -s lint — passed all hooks, type checks, sdist/wheel builds, and Twine checks.

AI assistance: AI agents performed the investigation, generated the patch, regression tests, and PR text, and ran the checks above. A separate AI agent reproduced the bug, reviewed the final diff, reran the metadata tests, and reported no blockers in its automated review. The full supported interpreter/platform matrix has not been run locally.

Use the core Metadata class as the field schema so that subclasses do not
reject inherited fields or omit their headers when writing RFC822 metadata.
Keep instance attribute access for validation and value retrieval.

Cover both factories and both validation modes with subclass round trips.

Assisted-by: OpenAI Codex

This branch has not been deployed

No deployments
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