Skip to content

Semantic analyzer confuses a function with a module #7203

Open
@Cito

Description

@Cito

The following code creates a package structure that demonstrates what I think is a bug in mypy's new semantic analyzer.

from os import makedirs

makedirs('src/core')
makedirs('src/stuff')

open('src/__init__.py', 'w').write("""
# nothing here
""")

open('src/core/__init__.py', 'w').write("""
from .run import config
""")

open('src/core/run.py', 'w').write("""
from ..stuff import somefunction

config = None

somefunction()
""")

open('src/stuff/__init__.py', 'w').write("""
from .somemore import more
from .somefunction import somefunction
""")

open('src/stuff/somefunction.py', 'w').write("""
def somefunction():
    print("Hello, World!")
""")

open('src/stuff/somemore.py', 'w').write("""
def more():
    from ..core import config
""")

When checking the created src package with mypy 0.720 and Python 3.7, I get the following error:

src/core/run.py:6: error: Module not callable

What mypy thinks is a module is actually a function. It just has the same name as its containing module.

When I check with --no-new-semantic-analyzer, I do not get this error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct codepriority-0-highsemantic-analyzerProblems that happen during semantic analysis

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions