Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.metadata is an empty message even for missing metadata #493

Open
jaraco opened this issue Jun 27, 2024 · 3 comments
Open

.metadata is an empty message even for missing metadata #493

jaraco opened this issue Jun 27, 2024 · 3 comments

Comments

@jaraco
Copy link
Member

jaraco commented Jun 27, 2024

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.

It seems the reason this expectation was previously missed is because (a) this case hasn't previously been tested, (b) the typespec indicates that email.message_from_string accepts only a str, and (c) the implementation suppresses the type error (introduced in d390898).

The underlying reason email.message_from_string accepts None is because io.StringIO accepts None and is indistinguishable from io.StringIO('') for reading.

@jaraco
Copy link
Member Author

jaraco commented Jun 27, 2024

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]

@drfho

This comment was marked as off-topic.

@jaraco

This comment was marked as off-topic.

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

No branches or pull requests

2 participants