-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Incremental parsing issue with namespace packages #12664
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
Comments
Thanks, I can repro on master, which means the unreleased #12250 does not fix either edit: this still repros as of 2022/10/28, so I guess #13124 didn't fix either (looks unrelated to the |
I'm getting the same issue. I'm running python 3.10.7, mypy 0.982, mypy-extensions 0.4.3, ruamel.yaml 0.17.21 and ruamel.yaml.clib 0.2.7 in a larger project. I followed the exact steps above to repro with a new virtual environment after
Python 3.10.7, Windows 11. |
Hitting the same issue. Do we know what causes this? |
The no incremental does not help with runamel.yaml because the final behavior of mypy depends on presence or absence of the optional binary dependency of it, When |
Related: python/mypy#12664 Related: python/mypy#8823
I can confirm this on Ubuntu 20.04.6 LTS, python 3.8.10, mypy 1.3.0. In my case the problem appears only in a package that depends on ruamel-yaml very indirectly (it's a dep of a dep of a dep), while in the original package that has the direct dependency and all others in the chain all seems OK, for now. I noted that the problematic package has a lot of Some more details:
|
I can confirm this issue on MacOS 14.1.2, python 3.11.6, mypy 1.7.1 |
Allow uploading a profile image that gets served / stored by recipeyak New flow for avatar urls is: 1. if upload is null, generate gravatar 2. if upload is not null, generate link to s3 not strictly related, but the new yaml package is surfacing a bug in mypy: python/mypy#12664
I can confirm this issue on MacOS 13.2.1, python 3.10.10, mypy 1.8.0 |
Similarly still seeing this issue on intermitant On
|
We are affected by this issue as well. Using We are using Poetry and this are the relevant versions from our poetry.lock:
I want to say that using mypy is very valuable to us, but this is a small annoyance. Is there a workaround that works with the cache? |
Likely not relevant, but this does not ever appear to happen with It's also not deterministic, but I can confirm the behavior where it always succeeds when the cache is empty. |
after a year, this issue is still haunting me and costing me a significant amount of CI running time |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thank god for the OP perfectly describing the issue. I encounter it here. Using All the best. |
One hack "fix" is to add this to your pyproject.toml under
Another one is to just |
Thanks @hauntsaninja! This alternative monkeypatch is much more appropriate to me. It allows caching to work properly only at the cost of not following this specific package, which does not really need type checking in my project. It'll save me a lot of time <3 |
Fixes python#12664 A root cause is there is this stateful `_update_ns_ancestors` thing in `modulefinder`, so if things get called in the wrong order, you can get incorrect results. See also the logic in `all_imported_modules_in_file` where we've fixed several bugs like this previously, like python#13124 and python#10937 As a result of (seemingly accidentally) reusing imports across modules, we can end up in a situation where the namespace gets added as a dependency to other modules and so on the cached run we attempt to find namespace before package, which does not work I am not sure this `imports` code path is even needed, so I will open an alternate PR. I can't write a good test for this because it requires something in site_packages, but here's a minimal repro: ``` set -eux rm -rf repro mkdir repro cd repro SITEPACK=env/site-packages mkdir -p $SITEPACK mkdir $SITEPACK/ruamel mkdir $SITEPACK/ruamel/yaml printf 'from ruamel.yaml.main import *' > $SITEPACK/ruamel/yaml/__init__.py printf 'import ruamel.yaml' > $SITEPACK/ruamel/yaml/main.py printf '' > $SITEPACK/ruamel/yaml/py.typed printf 'import ruamel.yaml' > a.py printf 'import a' > main.py rm -rf .mypy_cache PYTHONPATH=$SITEPACK mypy main.py PYTHONPATH=$SITEPACK mypy main.py ```
Fixes python#12664 See python#18907 which is another possible fix I'm not sure why this logic is actually needed given that we should record the dependency from import analysis in fastparse... maybe just because it adjusts priority? I can't write a good test for this because it requires something in site_packages, but here's a minimal repro: ``` set -eux rm -rf repro mkdir repro cd repro SITEPACK=env/site-packages mkdir -p $SITEPACK mkdir $SITEPACK/ruamel mkdir $SITEPACK/ruamel/yaml printf 'from ruamel.yaml.main import *' > $SITEPACK/ruamel/yaml/__init__.py printf 'import ruamel.yaml' > $SITEPACK/ruamel/yaml/main.py printf '' > $SITEPACK/ruamel/yaml/py.typed printf 'import ruamel.yaml' > a.py printf 'import a' > main.py rm -rf .mypy_cache PYTHONPATH=$SITEPACK mypy main.py PYTHONPATH=$SITEPACK mypy main.py ```
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
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 withtype: ignore[import]
ends up generating more errors as the ignores appear unused on a "successful" run (and you havewarn_unused_ignores
enabled).Setup & versions
python3.9 -m venv venv . venv/bin/activate pip install -U pip setuptools wheel pip install mypy ruamel.yaml
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: