python / python/mypy

importing google.cloud.logging causes untyped modules in the namespace to be considered missing

Open
#10,360 9 comments 20 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-0-high topic-pep-561
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

To Reproduce

with the mypy config:

[mypy]

[mypy-google.cloud.*]
ignore_missing_imports=true

and the .py file:

from google.cloud import bigquery
from google.cloud import logging

Actual Behavior

I get

foo.py:1: error: Module "google.cloud" has no attribute "bigquery"

however if I comment out:

from google.cloud import bigquery
# from google.cloud import logging

I get

Success: no issues found in 1 source file

Expected Behavior

I don't expect importing a module in a namespace with stubs to affect other modules in that namespace

(Write what happened.)

Your Environment

  • Mypy version used: 0.812 and d326952f88214b36d302c7fcbc92320b3c68fa18
  • Mypy command-line flags: mypy.
  • Mypy configuration options from mypy.ini (and other config files): see above
  • Python version used: Python 3.8.5 (default, Jan 27 2021, 15:41:15)
  • Operating system and version: Ubuntu 20.04.2 LTS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported mypy configuration and the foo.py imports that reproduce the error, then inspect how mypy handles google.cloud namespace imports when ignore_missing_imports is enabled. Run mypy on the reproducer with and without the google.cloud.logging import. Done means importing google.cloud.logging no longer causes google.cloud.bigquery to be reported as missing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.