Description
Bug Report
When mypy
is run multiple times on a Python module containing from aws_cdk import core
it will fail every 2nd time due to the error "Skipping analyzing 'aws_cdk': found module but no type hints or library stubs".
Disabling the mypy cache with --no-incremental
will result in mypy
passing every time.
To Reproduce
- Install
mypy
andaws-cdk.core
. - Create a Python module with
from aws_cdk import core
. - Run
mypy
on the module and it will pass. - Run
mypy
on the module again and it will fail. Subsequent runs will cycle between passing and failing.
$ python3.8 -m venv .venv && source .venv/bin/activate
(.venv) $ pip install mypy==0.790 aws-cdk.core==1.80.0
(.venv) $ echo 'from aws_cdk import core' > repro.py
(.venv) $ mypy repro.py
Success: no issues found in 1 source file
(.venv) $ mypy repro.py
repro.py:1: error: Skipping analyzing 'aws_cdk': found module but no type hints or library stubs
repro.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
(.venv) $ mypy repro.py
Success: no issues found in 1 source file
(.venv) $ mypy repro.py
repro.py:1: error: Skipping analyzing 'aws_cdk': found module but no type hints or library stubs
repro.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
Running mypy
on a module containing only from aws_cdk import core
should always pass.
Actual Behavior
Every second time mypy
is run on the module it will report an error.
Your Environment
- Mypy version used: 0.790
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.8.2
- Operating system and version: macOS
aws-cdk.core
version used: 1.80.0
The problem may be related to how the package that is installed is aws-cdk.core
but the namespace being imported from is aws_cdk
. A workaround is to change:
from aws_cdk import core
to:
import aws_cdk.core as core
The first form is what is generated by the cdk
tool and used in the cdk example code.