Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RobbieClarken opened this issue Dec 29, 2020 · 14 comments · Fixed by #10937
Closed

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

RobbieClarken opened this issue Dec 29, 2020 · 14 comments · Fixed by #10937

Comments

@RobbieClarken
Copy link

RobbieClarken commented Dec 29, 2020

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

  • 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.

@RobbieClarken RobbieClarken added the bug mypy got something wrong label Dec 29, 2020
@hauntsaninja
Copy link
Collaborator

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

@hauntsaninja
Copy link
Collaborator

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
Copy link
Collaborator

Looks like this was previously reported at #9777

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Dec 30, 2020

I suspect it's the same as #7276 as well.

@KaleabTessera
Copy link

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

@ssbarnea
Copy link
Contributor

ssbarnea commented Jul 5, 2021

I reported the same bug on pre-commit/pre-commit#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
Copy link

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

@ssbarnea
Copy link
Contributor

ssbarnea commented Aug 3, 2021

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
Copy link
Collaborator

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:
#4910
#5016
(Guido's comment on the latter has aged well)

msullivan added a commit that referenced this issue Aug 4, 2021
As part of doing this I upgraded the pep561 tests to support
incremental tests, and removed at least a little of the duplication
between different incremental test suites.
msullivan added a commit that referenced this issue Aug 5, 2021
As part of doing this I upgraded the pep561 tests to support
incremental tests, and removed at least a little of the duplication
between different incremental test suites.
@ethanhs
Copy link
Collaborator

ethanhs commented Aug 5, 2021

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.

msullivan added a commit that referenced this issue Aug 6, 2021
Since PEP561-installed namespace packages only show up in
FindModuleCache as a side-effect, the submodules need to be listed
first in the dependencies for things to work. This was handled already
in the Import case but not the ImportFrom case.

Also fix the cache handling of namespace packages so it doesn't always
get reported stale.

Fixes #9852.
msullivan added a commit that referenced this issue Aug 6, 2021
Since PEP561-installed namespace packages only show up in
FindModuleCache as a side-effect, the submodules need to be listed
first in the dependencies for things to work. This was handled already
in the Import case but not the ImportFrom case.

Also fix the cache handling of namespace packages so it doesn't always
get reported stale.

Fixes #9852.
hauntsaninja pushed a commit that referenced this issue Aug 6, 2021
Since PEP561-installed namespace packages only show up in
FindModuleCache as a side-effect, the submodules need to be listed
first in the dependencies for things to work. This was handled already
in the Import case but not the ImportFrom case.

Also fix the cache handling of namespace packages so it doesn't always
get reported stale.

Fixes #9852.
bonzini pushed a commit to qemu/qemu that referenced this issue Nov 1, 2021
This one is insidious: if you write an import as "from {namespace}
import {subpackage}" as mirror-top-perms (now) does, mypy will fail on
every-other invocation *if* the package being imported is a typed,
installed, namespace-scoped package.

Upsettingly, that's exactly what 'qemu.[aqmp|qmp|machine]' et al are in
the context of Python CI tests.

Now, I could just edit mirror-top-perms to avoid this invocation, but
since I tripped on a landmine, I might as well head it off at the pass
and make sure nobody else trips on that same landmine.

It seems to have something to do with the order in which files are
checked as well, meaning the random order in which set(os.listdir())
produces the list of files to test will cause problems intermittently
and not just strictly "every other run".

This will be fixed in mypy >= 0.920, which is not released yet. The
workaround for now is to disable incremental checking, which avoids the
issue.

Note: This workaround is not applied when running iotest 297 directly,
because the bug does not surface there! Given the nature of CI jobs not
starting with any stale cache to begin with, this really only has a
half-second impact on manual runs of the Python test suite when executed
directly by a developer on their local machine. The workaround may be
removed when the Python package requirements can stipulate mypy 0.920 or
higher, which can happen as soon as it is released. (Barring any
unforseen compatibility issues that 0.920 may bring with it.)

See also:
 python/mypy#11010
 python/mypy#9852

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-id: 20211019144918.3159078-14-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
stsquad pushed a commit to stsquad/qemu that referenced this issue Nov 2, 2021
This one is insidious: if you write an import as "from {namespace}
import {subpackage}" as mirror-top-perms (now) does, mypy will fail on
every-other invocation *if* the package being imported is a typed,
installed, namespace-scoped package.

Upsettingly, that's exactly what 'qemu.[aqmp|qmp|machine]' et al are in
the context of Python CI tests.

Now, I could just edit mirror-top-perms to avoid this invocation, but
since I tripped on a landmine, I might as well head it off at the pass
and make sure nobody else trips on that same landmine.

It seems to have something to do with the order in which files are
checked as well, meaning the random order in which set(os.listdir())
produces the list of files to test will cause problems intermittently
and not just strictly "every other run".

This will be fixed in mypy >= 0.920, which is not released yet. The
workaround for now is to disable incremental checking, which avoids the
issue.

Note: This workaround is not applied when running iotest 297 directly,
because the bug does not surface there! Given the nature of CI jobs not
starting with any stale cache to begin with, this really only has a
half-second impact on manual runs of the Python test suite when executed
directly by a developer on their local machine. The workaround may be
removed when the Python package requirements can stipulate mypy 0.920 or
higher, which can happen as soon as it is released. (Barring any
unforseen compatibility issues that 0.920 may bring with it.)

See also:
 python/mypy#11010
 python/mypy#9852

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-id: 20211019144918.3159078-14-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
@nacitar
Copy link

nacitar commented Dec 7, 2021

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
Copy link
Member

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

@MaxG87
Copy link

MaxG87 commented Feb 21, 2022

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants