Skip to content

Comments

Fix TypeError when dist.metadata returns None on Python 3.15#537

Closed
Fridayai700 wants to merge 1 commit intotox-dev:mainfrom
Fridayai700:fix-metadata-none
Closed

Fix TypeError when dist.metadata returns None on Python 3.15#537
Fridayai700 wants to merge 1 commit intotox-dev:mainfrom
Fridayai700:fix-metadata-none

Conversation

@Fridayai700
Copy link
Contributor

Summary

Fixes TypeError: argument of type 'NoneType' is not a container or iterable on Python 3.15, where dist.metadata returns None for missing/empty METADATA files instead of an empty PackageMetadata object.

Fixes #530

Changes

  • has_valid_metadata(): added dist.metadata is not None guard before the "Name" in dist.metadata check
  • Added test_has_valid_metadata_none regression test using a mock dist with metadata=None

Test plan

  • New test verifies has_valid_metadata returns False when dist.metadata is None
  • Existing test_invalid_metadata continues to pass

In Python 3.15, importlib.metadata changed behavior: the metadata
property returns None for missing/empty METADATA files instead of an
empty PackageMetadata object. Guard has_valid_metadata() with a None
check to handle both behaviors.

Fixes tox-dev#530
@kemzeb
Copy link
Collaborator

kemzeb commented Feb 18, 2026

I currently believe that the changes made to importlib.metadata for 3.15 are a regression, so I rather wait to see what decision the Python maintainers will make here. I'll close this for now, but if they decide to continue on with these changes I'll reopen.

@kemzeb kemzeb closed this Feb 18, 2026
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.

Compatibility of tests with Python 3.15

2 participants