python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.61k stars 2.85k forks source link

Cache causes mypy to fail every 2nd run for module importing from aws_cdk #9852

Closed RobbieClarken closed 3 years ago

RobbieClarken commented 3 years ago

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

  1. Install mypy and aws-cdk.core.
  2. Create a Python module with from aws_cdk import core.
  3. Run mypy on the module and it will pass.
  4. 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

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.

hauntsaninja commented 3 years ago

Huh, that's an interesting one. I can repro, including with master. But weirdly, not with my editable install of mypy.

hauntsaninja commented 3 years ago

Here's a side by side of mypy -v from a successful and a failing run:

``` LOG: Mypy Version: 0.800+dev.dc251783ccb9baa48fc62d109a88854ac514816d LOG: Mypy Version: 0.800+dev.dc251783ccb9baa48fc62d109a88854ac514816d LOG: Config File: Default LOG: Config File: Default LOG: Configured Executable: /Users/shantanu/.virtualenvs/wut/bin/python LOG: Configured Executable: /Users/shantanu/.virtualenvs/wut/bin/python LOG: Current Executable: /Users/shantanu/.virtualenvs/wut/bin/python LOG: Current Executable: /Users/shantanu/.virtualenvs/wut/bin/python LOG: Cache Dir: .mypy_cache LOG: Cache Dir: .mypy_cache LOG: Compiled: False LOG: Compiled: False LOG: Found source: BuildSource(path='repro.py', module='repro', has_text=False, base_ LOG: Found source: BuildSource(path='repro.py', module='repro', has_text=False, base_ LOG: Metadata fresh for repro: file repro.py | LOG: Could not load cache for repro: repro.meta.json > LOG: Metadata not found for repro > LOG: Parsing repro.py (repro) > LOG: Metadata not found for aws_cdk > LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk (aws_cdk) LOG: Metadata fresh for aws_cdk.core: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for aws_cdk.core: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for builtins: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for builtins: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for abc: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/ LOG: Metadata fresh for abc: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/ LOG: Metadata fresh for datetime: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for datetime: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for enum: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for enum: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for typing: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packag LOG: Metadata fresh for typing: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packag LOG: Metadata fresh for jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for typing_extensions: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/ LOG: Metadata fresh for typing_extensions: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/ LOG: Metadata fresh for aws_cdk.core._jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3.9 LOG: Metadata fresh for aws_cdk.core._jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3.9 LOG: Metadata fresh for aws_cdk.cx_api: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/sit LOG: Metadata fresh for aws_cdk.cx_api: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/sit LOG: Metadata fresh for constructs: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pa LOG: Metadata fresh for constructs: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pa LOG: Metadata fresh for sys: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/ LOG: Metadata fresh for sys: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/ LOG: Metadata fresh for _typeshed: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for _typeshed: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for ast: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/ LOG: Metadata fresh for ast: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/ LOG: Metadata fresh for io: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/m LOG: Metadata fresh for io: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/m LOG: Metadata fresh for types: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-package LOG: Metadata fresh for types: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-package LOG: Metadata fresh for time: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for time: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for collections: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for collections: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for jsii.__meta__: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site LOG: Metadata fresh for jsii.__meta__: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site LOG: Metadata fresh for jsii._runtime: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site LOG: Metadata fresh for jsii._runtime: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site LOG: Metadata fresh for aws_cdk.cloud_assembly_schema._jsii: file /Users/shantanu/.virtualenvs/ LOG: Metadata fresh for aws_cdk.cloud_assembly_schema._jsii: file /Users/shantanu/.virtualenvs/ LOG: Metadata fresh for aws_cdk.cloud_assembly_schema: file /Users/shantanu/.virtualenvs/wut/li LOG: Metadata fresh for aws_cdk.cloud_assembly_schema: file /Users/shantanu/.virtualenvs/wut/li LOG: Metadata fresh for aws_cdk.cx_api._jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3 LOG: Metadata fresh for aws_cdk.cx_api._jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3 LOG: Metadata fresh for aws_cdk.region_info._jsii: file /Users/shantanu/.virtualenvs/wut/lib/py LOG: Metadata fresh for aws_cdk.region_info._jsii: file /Users/shantanu/.virtualenvs/wut/lib/py LOG: Metadata fresh for aws_cdk.region_info: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for aws_cdk.region_info: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for constructs._jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/s LOG: Metadata fresh for constructs._jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/s LOG: Metadata fresh for importlib.abc: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site LOG: Metadata fresh for importlib.abc: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site LOG: Metadata fresh for array: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-package LOG: Metadata fresh for array: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-package LOG: Metadata fresh for mmap: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for mmap: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for os: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/m LOG: Metadata fresh for os: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/m LOG: Metadata fresh for _ast: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for _ast: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for codecs: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packag LOG: Metadata fresh for codecs: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packag LOG: Metadata fresh for _importlib_modulespec: file /Users/shantanu/.virtualenvs/wut/lib/python LOG: Metadata fresh for _importlib_modulespec: file /Users/shantanu/.virtualenvs/wut/lib/python LOG: Metadata fresh for json: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for json: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for jsii._compat: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for jsii._compat: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for attr: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for attr: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages LOG: Metadata fresh for jsii._reference_map: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for jsii._reference_map: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for jsii._kernel: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for jsii._kernel: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for jsii.python: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for jsii.python: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for jsii._kernel.types: file /Users/shantanu/.virtualenvs/wut/lib/python3.9 LOG: Metadata fresh for jsii._kernel.types: file /Users/shantanu/.virtualenvs/wut/lib/python3.9 LOG: Metadata fresh for importlib: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for importlib: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for posix: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-package LOG: Metadata fresh for posix: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-package LOG: Metadata fresh for os.path: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packa LOG: Metadata fresh for os.path: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packa LOG: Metadata fresh for json.decoder: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for json.decoder: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for json.encoder: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for json.encoder: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for importlib.resources: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for importlib.resources: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for attr.exceptions: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/si LOG: Metadata fresh for attr.exceptions: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/si LOG: Metadata fresh for attr.filters: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for attr.filters: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for attr.converters: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/si LOG: Metadata fresh for attr.converters: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/si LOG: Metadata fresh for attr.setters: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for attr.setters: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site- LOG: Metadata fresh for attr.validators: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/si LOG: Metadata fresh for attr.validators: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/si LOG: Metadata fresh for attr._version_info: file /Users/shantanu/.virtualenvs/wut/lib/python3.9 LOG: Metadata fresh for attr._version_info: file /Users/shantanu/.virtualenvs/wut/lib/python3.9 LOG: Metadata fresh for inspect: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packa LOG: Metadata fresh for inspect: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packa LOG: Metadata fresh for itertools: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for itertools: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for functools: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for functools: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for jsii.errors: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for jsii.errors: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for jsii._utils: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for jsii._utils: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for jsii._kernel.providers: file /Users/shantanu/.virtualenvs/wut/lib/pytho LOG: Metadata fresh for jsii._kernel.providers: file /Users/shantanu/.virtualenvs/wut/lib/pytho LOG: Metadata fresh for genericpath: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for genericpath: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-p LOG: Metadata fresh for pathlib: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packa LOG: Metadata fresh for pathlib: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packa LOG: Metadata fresh for textwrap: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for textwrap: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for jsii._kernel.providers.base: file /Users/shantanu/.virtualenvs/wut/lib/ LOG: Metadata fresh for jsii._kernel.providers.base: file /Users/shantanu/.virtualenvs/wut/lib/ LOG: Metadata fresh for jsii._kernel.providers.process: file /Users/shantanu/.virtualenvs/wut/l LOG: Metadata fresh for jsii._kernel.providers.process: file /Users/shantanu/.virtualenvs/wut/l LOG: Metadata fresh for atexit: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packag LOG: Metadata fresh for atexit: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packag LOG: Metadata fresh for contextlib: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pa LOG: Metadata fresh for contextlib: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pa LOG: Metadata fresh for importlib.machinery: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for importlib.machinery: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for platform: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for platform: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for subprocess: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pa LOG: Metadata fresh for subprocess: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pa LOG: Metadata fresh for tempfile: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for tempfile: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for cattr: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-package LOG: Metadata fresh for cattr: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-package LOG: Metadata fresh for dateutil.parser: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/si LOG: Metadata fresh for dateutil.parser: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/si LOG: Metadata fresh for dateutil: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for dateutil: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for jsii._embedded.jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for jsii._embedded.jsii: file /Users/shantanu/.virtualenvs/wut/lib/python3. LOG: Metadata fresh for jsii._embedded: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/sit LOG: Metadata fresh for jsii._embedded: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/sit LOG: Metadata fresh for cattr.converters: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/s LOG: Metadata fresh for cattr.converters: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/s LOG: Metadata fresh for cattr.gen: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for cattr.gen: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pac LOG: Metadata fresh for cattr._compat: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site LOG: Metadata fresh for cattr._compat: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site LOG: Metadata fresh for cattr.disambiguators: file /Users/shantanu/.virtualenvs/wut/lib/python3 LOG: Metadata fresh for cattr.disambiguators: file /Users/shantanu/.virtualenvs/wut/lib/python3 LOG: Metadata fresh for cattr.multistrategy_dispatch: file /Users/shantanu/.virtualenvs/wut/lib LOG: Metadata fresh for cattr.multistrategy_dispatch: file /Users/shantanu/.virtualenvs/wut/lib LOG: Metadata fresh for re: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/m LOG: Metadata fresh for re: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/m LOG: Metadata fresh for operator: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for operator: file /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-pack LOG: Metadata fresh for cattr.function_dispatch: file /Users/shantanu/.virtualenvs/wut/lib/pyth LOG: Metadata fresh for cattr.function_dispatch: file /Users/shantanu/.virtualenvs/wut/lib/pyth LOG: Loaded graph with 83 nodes (0.059 sec) | LOG: Loaded graph with 84 nodes (0.059 sec) LOG: Found 54 SCCs; largest has 21 nodes | LOG: Found 55 SCCs; largest has 21 nodes LOG: Processing 49 queued fresh SCCs | LOG: Processing 23 queued fresh SCCs LOG: Processing SCC singleton (aws_cdk.cx_api._jsii) as inherently stale | LOG: Processing SCC singleton (aws_cdk) as inherently stale > LOG: Writing aws_cdk /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk aws_c > LOG: Cached module aws_cdk has changed interface > LOG: Processing 26 queued fresh SCCs > LOG: Processing SCC singleton (aws_cdk.cx_api._jsii) as inherently stale with stale deps (aws_c LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/cx_api/_jsii/ LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/cx_api/_jsii/ LOG: Writing aws_cdk.cx_api._jsii /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/ LOG: Writing aws_cdk.cx_api._jsii /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/ LOG: Cached module aws_cdk.cx_api._jsii has changed interface LOG: Cached module aws_cdk.cx_api._jsii has changed interface LOG: Processing SCC singleton (aws_cdk.cx_api) as inherently stale with stale deps (aws_cdk.cx_ | LOG: Processing SCC singleton (aws_cdk.cx_api) as inherently stale with stale deps (aws_cdk aws LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/cx_api/__init LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/cx_api/__init LOG: Writing aws_cdk.cx_api /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cd LOG: Writing aws_cdk.cx_api /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cd LOG: Cached module aws_cdk.cx_api has changed interface LOG: Cached module aws_cdk.cx_api has changed interface LOG: Processing SCC singleton (aws_cdk.core._jsii) as inherently stale with stale deps (aws_cdk | LOG: Processing SCC singleton (aws_cdk.core._jsii) as inherently stale with stale deps (aws_cdk LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/core/_jsii/__ LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/core/_jsii/__ LOG: Writing aws_cdk.core._jsii /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aw LOG: Writing aws_cdk.core._jsii /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aw LOG: Cached module aws_cdk.core._jsii has changed interface LOG: Cached module aws_cdk.core._jsii has changed interface LOG: Processing SCC singleton (aws_cdk.core) as inherently stale with stale deps (aws_cdk.core. | LOG: Processing SCC singleton (aws_cdk.core) as inherently stale with stale deps (aws_cdk aws_c LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/core/__init__ LOG: Parsing /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/core/__init__ LOG: Writing aws_cdk.core /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/ LOG: Writing aws_cdk.core /Users/shantanu/.virtualenvs/wut/lib/python3.9/site-packages/aws_cdk/ LOG: Cached module aws_cdk.core has changed interface LOG: Cached module aws_cdk.core has changed interface LOG: Processing SCC singleton (repro) as inherently stale with stale deps (aws_cdk.core) | LOG: Processing SCC singleton (repro) as inherently stale with stale deps (aws_cdk aws_cdk.core LOG: Parsing repro.py (repro) | LOG: Writing repro repro.py repro.meta.json repro.data.json repro.py:1: error: Skipping analyzing 'aws_cdk': found module but no type hints or library stubs | LOG: Cached module repro has changed interface repro.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports < LOG: Deleting repro repro.py repro.meta.json repro.data.json < LOG: No fresh SCCs left in queue LOG: No fresh SCCs left in queue LOG: Build finished in 2.996 seconds with 83 modules, and 2 errors | LOG: Build finished in 2.980 seconds with 84 modules, and 0 errors Found 1 error in 1 file (checked 1 source file) | Success: no issues found in 1 source file ```
hauntsaninja commented 3 years ago

Looks like this was previously reported at https://github.com/python/mypy/issues/9777

hauntsaninja commented 3 years ago

I suspect it's the same as https://github.com/python/mypy/issues/7276 as well.

KaleabTessera commented 3 years ago

I have a similar issue, any new info on this?

ssbarnea commented 3 years ago

I reported the same bug on https://github.com/pre-commit/pre-commit/issues/1966 as it happened only when I was running mypy from inside pre-commit but this morning I managed to find an workaround for this bug.

I reconfigured the hook to force it to avoid use of progressive run. Mainly on hook that is args: ['--no-incremental'].

Interesting enough, I am also on MacOS and using py39 from pyenv. Maybe the messed cached issue may be specific to macos.

Cnoor0171 commented 3 years ago

@ssbarnea I have the same issue on linux. Probably not macos specific.

ssbarnea commented 3 years ago

I am very curious on what is happening as that is a real PITA. It does not happen with all projects but is still common enough.

hauntsaninja commented 3 years ago

This a pretty bad bug, non-exhaustive list of reports: #10056 #7276 #9852 #9777 #10906 #10376 #10644 #10906

I found a "fix", but unfortunately, I don't really understand the code. But maybe in posting I can snipe @msullivan into fixing this for real :-)

First note that in #10056 there's a pretty minimal repro, scriptified as:

rm -rf lib env
mkdir -p lib/ns_package/reg_package

echo 'from ns_package import reg_package' > script.py
echo 'something: int' > lib/ns_package/reg_package/__init__.py
touch lib/ns_package/reg_package/py.typed
cat << EOF > lib/setup.py
from setuptools import setup, find_namespace_packages
setup(
    name="ns_package.reg_package",
    packages=find_namespace_packages(),
    package_data={"": ["py.typed"]},
)
EOF

python3 -m venv env
source env/bin/activate
pip install mypy -e lib

mypy script.py
mypy script.py
mypy script.py
mypy script.py

I'm also not sure the best way to turn this into a test. I haven't been able to repro without the PEP 561 package.

Here's the diff that fixes it:

diff --git a/mypy/build.py b/mypy/build.py
index b8831b21a..21dbb3b4f 100644
--- a/mypy/build.py
+++ b/mypy/build.py
@@ -767,8 +767,9 @@ class BuildManager:
                     # As a workaround for for some bugs in cycle handling (#4498),
                     # if all of the imports are submodules, do the import at a lower
                     # priority.
-                    pri = import_priority(imp, PRI_HIGH if not all_are_submodules else PRI_LOW)
-                    res.insert(pos, ((pri, cur_id, imp.line)))
+                    if not all_are_submodules:
+                        pri = import_priority(imp, PRI_HIGH if not all_are_submodules else PRI_LOW)
+                        res.insert(pos, ((pri, cur_id, imp.line)))
                 elif isinstance(imp, ImportAll):
                     pri = import_priority(imp, PRI_HIGH)
                     res.append((pri, correct_rel_imp(imp), imp.line))

The only test failure this causes is testIncrementalPackageNameOverload, which isn't the worst thing.

This code was previously touched in: https://github.com/python/mypy/pull/4910 https://github.com/python/mypy/pull/5016 (Guido's comment on the latter has aged well)

emmatyping commented 3 years ago

I had a few minutes so I went back and looked at old mypy releases and based on the above repro this started when namespace packages were added all the way back in 0.630. My gut tells me the real issue is modulefinder, but I'll take a closer look this weekend.

nacitar commented 2 years ago

This issue still persists with mypy 0.910. Every second run fails. This has either not been fixed or isn't fixed in a released version.

JelleZijlstra commented 2 years ago

I don't think the fix is in 0.910, unfortunately.

MaxG87 commented 2 years ago

I have a similar issue, involving from google.cloud import storage with 0.931. However, the minimal repo given at above does not show the bug anymore.

hauntsaninja commented 2 years ago

This issue was fixed. Could you open a new issue with details and preferably a repro?