Closed RobbieClarken closed 3 years ago
Huh, that's an interesting one. I can repro, including with master. But weirdly, not with my editable install of mypy.
Here's a side by side of mypy -v
from a successful and a failing run:
Looks like this was previously reported at https://github.com/python/mypy/issues/9777
I suspect it's the same as https://github.com/python/mypy/issues/7276 as well.
I have a similar issue, any new info on this?
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.
@ssbarnea I have the same issue on linux. Probably not macos specific.
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.
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)
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.
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.
I don't think the fix is in 0.910, unfortunately.
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.
This issue was fixed. Could you open a new issue with details and preferably a repro?
Bug Report
When
mypy
is run multiple times on a Python module containingfrom 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 inmypy
passing every time.To Reproduce
mypy
andaws-cdk.core
.from aws_cdk import core
.mypy
on the module and it will pass.mypy
on the module again and it will fail. Subsequent runs will cycle between passing and failing.Expected Behavior
Running
mypy
on a module containing onlyfrom 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.ini
(and other config files): noneaws-cdk.core
version used: 1.80.0The problem may be related to how the package that is installed is
aws-cdk.core
but the namespace being imported from isaws_cdk
. A workaround is to change:to:
The first form is what is generated by the
cdk
tool and used in the cdk example code.