Skip to content

Incremental parsing issue with namespace packages #12664

Closed
@PeterJCLaw

Description

@PeterJCLaw

Given a local file which uses something which is a namespace package and then another local file which uses the first one, there's an intermittent bug where the namespace packaged module's types aren't found.
This seems likely similar to #7276, however even with #10937 in place (i.e: on a more recent mypy release) the issue remains.

To Reproduce

$ mkdir demo
$ echo 'import ruamel.yaml' > demo/wrapper.py 
$ echo 'import wrapper' > demo/consumer.py
$ mypy demo  # first run
Success: no issues found in 2 source files
$ mypy demo  # second run
demo/wrapper.py:1: error: Skipping analyzing "ruamel": module is installed, but missing library stubs or py.typed marker
demo/consumer.py:1: error: Skipping analyzing "ruamel": module is installed, but missing library stubs or py.typed marker
demo/consumer.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 2 errors in 2 files (checked 2 source files)

Subsequent runs will alternate between success and failure. Any additional source files in the project (whether they import the wrapper or not) will also have the error message applied to them, which makes failing runs vastly less useful.

Running with --no-incremental appears to avoid the issue; I can run several times in a row with --no-incremental without encountering the failure mode (and have not seen it with that flag enabled).

Running with --namespace-packages appears to have no effect.

Unfortunately as ruamel.yaml is a typed library, ignoring the imports with type: ignore[import] ends up generating more errors as the ignores appear unused on a "successful" run (and you have warn_unused_ignores enabled).

Setup & versions
python3.9 -m venv venv
. venv/bin/activate
pip install -U pip setuptools wheel
pip install mypy ruamel.yaml
$ pip list
Package           Version
----------------- -------
mypy              0.942
mypy-extensions   0.4.3
pip               22.0.4
ruamel.yaml       0.17.21
ruamel.yaml.clib  0.2.6
setuptools        62.1.0
tomli             2.0.1
typing_extensions 4.2.0
wheel             0.37.1

Your Environment

  • Mypy version used: 0.942
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9 (though similar behaviour observed on other versions; at least on 3.8)
  • Operating system and version: Ubuntu 20.04 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions