You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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]
In #489 (comment), I learned that
Distribution.metadata
will return an emptyPackageMetadata
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 expectdist.metadata
to beNone
when no metadata file is present, and to return an emptyPackageMetadata
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 astr
, and (c) the implementation suppresses the type error (introduced in d390898).The underlying reason
email.message_from_string
accepts None is becauseio.StringIO
acceptsNone
and is indistinguishable fromio.StringIO('')
for reading.The text was updated successfully, but these errors were encountered: