In #489 (comment), I learned that Distribution.metadata will return an empty PackageMetadata even when there is no metadata file present.
Although not part of the recommended operating practice, it seems to be occasional occurrence for an uninstalled package to leave a lingering metadata directory (*.dist-info) with nothing in it. Instead, I would expect dist.metadata to be None when no metadata file is present, and to return an empty PackageMetadata object when a metadata file is present but empty.
The underlying reason email.message_from_string accepts None is because io.StringIO accepts None and is indistinguishable from io.StringIO('') for reading.
In 597776e, I started exploring an optional None return type from .metadata(), but that does violate other interfaces (just internally):
_________________________________________________________ importlib_metadata/__init__.py _________________________________________________________
465: error: Value of type "PackageMetadata | None" is not indexable [index]
475: error: Value of type "PackageMetadata | None" is not indexable [index]
972: error: Incompatible return value type (got "PackageMetadata | None", expected "PackageMetadata") [return-value]
1041: error: Value of type "PackageMetadata | None" is not indexable [index]
_______________________________________________________ importlib_metadata/compat/py39.py ________________________________________________________
23: error: Value of type "PackageMetadata | None" is not indexable [index]
Activity
jaraco commented on Jun 27, 2024
In 597776e, I started exploring an optional None return type from .metadata(), but that does violate other interfaces (just internally):
drfho commented on Jul 18, 2024
jaraco commented on Jul 20, 2024