Semantic analyzer confuses a function with a module
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Recreate the generated src package from the issue body and run mypy 0.720 with and without --no-new-semantic-analyzer, focusing on src/core/run.py and src/stuff/somefunction.py. Trace why somefunction is resolved as a module instead of a callable function; done when the new semantic analyzer accepts the call and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100