Jason R. Coombs <jar...@jaraco.com> added the comment:
Thanks for the report. Yes, the issues are related, where .version and .name returning None are specific manifestations of the metadata not having that key and the behavior being ill-defined. I haven't yet decided if metadata items being undefined should result in None or raise an Exception (maybe KeyError). For the specific case of a missing Name or Version, however, the packaging spec says that these fields are required (https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata-specifications), so it may be reasonable for the behavior when the specification is not met that the resulting behavior would be undefined (i.e. importlib.metadata should be able to assume the specification). It's outside the scope of importlib.metadata to detect, report, and repair invalid metadata. I would welcome and even encourage a third-party package to take on the responsibility of validating all distributions in an environment and reporting on non-compliant aspects. In that sense, the type declaration is correct. `.name` and `.version` should always return `str` or raise an exception. This additional example leads me stronger toward the position that `.metadata[missing]` should raise a KeyError, which would also fix this issue. I'd also argue that if the metadata file is missing altogether, that should perhaps be a different error. That is, missing metadata is different from null metadata. Right now, the two are indistinguishable from the interface. > I'd expect there to be a PackageNotFoundError raised in this situation That doesn't sound quite right to me. If there's a `.dist-info` directory, that implies a package is present. e.g.: ``` ~ $ mkdir foo.dist-info ~ $ py -c "import importlib.metadata as md; print(md.distribution('foo'))" <importlib.metadata.PathDistribution object at 0x1032f8580> ``` I'm going to ponder this one some more and probably address the `.metadata` issue(s) first before making any pronouncements on the best approach here. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue47060> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com