Skip to content

TypeError: 'NoneType' object is not iterable in _top_level_inferred  #344

Closed
@harupy

Description

@harupy

Reposting #340 (comment) as an issue.

I'm observing importlib_metadata.packages_distributions() throw the following error:

  File "/opt/mlflow/mlflow/utils/requirements_utils.py", line 129, in <module>
    _MODULE_TO_PACKAGES = importlib_metadata.packages_distributions()
  File "/miniconda/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 1016, in packages_distributions
    for pkg in _top_level_declared(dist) or _top_level_inferred(dist):
  File "/miniconda/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 1026, in _top_level_inferred
    return {

https://github.com/mlflow/mlflow/runs/3428616955#step:5:7078

It looks like the line 1028 in _top_level_inferred tries to iterate on dist.files that can be None and then throws the error above:

def _top_level_inferred(dist):
return {
f.parts[0] if len(f.parts) > 1 else f.with_suffix('').name
for f in dist.files
if f.suffix == ".py"
}

https://docs.python.org/3/library/importlib.metadata.html#distribution-files says:

In the case where the metadata file listing files (RECORD or SOURCES.txt) is missing, files() will return None. The caller may wish to wrap calls to files() in always_iterable or otherwise guard against this condition if the target distribution is not known to have the metadata present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions