Skip to content

Cache causes mypy to fail every 2nd run for module importing from google.cloud #12232

Closed
@MaxG87

Description

@MaxG87

Bug Report
I have a project that imports things from google.cloud, which is a namespace package as far as I know. In a certain, very specific configuration mypy fails on every second run. This is very similar to #9852. However, this bug affects the most recent mypy, 0.931. Since the reproducer of #9852 is fixed, I was asked to open a bug report here.

To Reproduce

The following script does reproduce the problem on Debian Stable and inside the Docker image python:latest.

#!/usr/bin/env bash

rm -rf env

# The order of the imports matters. If one imports datastore first, the error
# does not occur. Also, one must suppress the type error on the import of
# `storage`, otherwise the error does not appear neither.
cat <<EOF > script.py
from google.cloud import storage  # type: ignore[attr-defined]
from google.cloud import datastore
EOF

python3 -m venv env
source env/bin/activate
python3 -m pip install mypy==0.931 google-cloud-storage==2.0.0 google-cloud-datastore==2.4.0

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

Expected Behavior
Pass or fail every time. I am not sure what would be correct in this case.

Actual Behavior
Mypy accepts and rejects the code every 2nd run.

Your Environment

Debian Stable and python:latest. The reproducing script should cover all relevant details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions