Skip to content

Change in behavior with __import__('pkgutil').extend_path() # type: Iterable[str]  #7582

@ericvw

Description

@ericvw

I noticed a change in behavior between versions 0.720 and 0.730 when using pkgutil-style namespace packages.

For the following __init__.py file:

__path__ = __import__('pkgutil').extend_path(__path__, __name__)

mypy == 0.720 will report:

$ mypy --version
mypy 0.720

$ mypy --show-traceback __init__.py
__init__.py:2: error: Cannot determine type of '__path__'

Thus, I "resolved" this with the following in, in 0.720:

from typing import Iterable
__path__ = __import__('pkgutil').extend_path(__path__, __name__)  # type: Iterable[str]

With mypy ==0.730, I get the following:

$ mypy --version
mypy 0.730

mypy --show-traceback __init__.py
__init__.py:2: error: Module has no attribute "extend_path"
Found 1 error in 1 file (checked 1 source file)

When researching this issue, #7501 (comment) indicates that __import__ is not followed. However, I don't fully understand the change in behavior and had trouble using git-bisect to narrow it down.

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