Skip to content

module google.cloud has no attribute firestore - Incorrect #12985

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

Closed
adamcunnington-mlg opened this issue Jun 15, 2022 · 5 comments
Closed

module google.cloud has no attribute firestore - Incorrect #12985

adamcunnington-mlg opened this issue Jun 15, 2022 · 5 comments
Assignees
Labels
bug mypy got something wrong

Comments

@adamcunnington-mlg
Copy link

adamcunnington-mlg commented Jun 15, 2022

Bug Report

module google.cloud has no attribute firestore
The bug is that this statement is not true.

There have been a few related stackoverflow issues (e.g. 1, 2) relating to incorrect "module x as no attribute y" specifically relating to google.cloud.
Some issues were sorted by recreating the virtual env.
Other issues on this repo were historically traced back to using incremental mode but solution seemed incomplete (e.g. 1, 2).
We disabled mypy cache (e.g. incremental mode) which dealt with a chunk of the problem

To Reproduce
Hard to know exactly how to reproduce because the problem with this issue is it seems random and indeterministic - even after disabling incremental mode.

All I can tell you is in our code we do:

from google.cloud import bigquery, firestore

Both google-cloud-bigquery and google-cloud-firestore are in setup.cfg/requirements.txt and installed in the virtual environment which mypy is being activated from.

We have no issues (currently) with the bigquery import but we do with firestore. They are completely identical for all intents and purposes here.

Expected Behaviour

No complaint about missing attribute.

Actual Behaviour

Incorrect complaint about missing attribute.

Your Environment

mypy 0.950 (compiled: yes)
python 3.9.x

Please can we get to the bottom of this once and for all?

@adamcunnington-mlg adamcunnington-mlg added the bug mypy got something wrong label Jun 15, 2022
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jun 15, 2022

Are you using namespace_packages=True? If not, please try with that. This will be made the default at some point soon.

0.950 should have fixes for all known incremental mode bugs, in particular, #12250 . If you do get a repro, that would be helpful.

@adamcunnington-mlg
Copy link
Author

Will try and see if it fixes

@adamcunnington-mlg
Copy link
Author

adamcunnington-mlg commented Jun 16, 2022

It has no effect unfortunately - which is unsurprising anyway because then we'd have to understand why bigquery wasn't causing an issue here but firestore was.

For now, we will just type: ignore.
I don't know how we can reproduce it.

@shevron
Copy link

shevron commented Jun 19, 2022

I'm seeing a similar behavior - with:

from google.cloud import bigquery, storage

I get:

$ mypy --no-incremental mynamespace/
mynamespace/package/module.py:19: error: Module "google.cloud" has no attribute "storage"

This is with mypy 0.961;
My code is using namespace packages (i.e. mynamespace in the example above is a namespace package), but so far I haven't had any issues.

I was able to work around it for now by doing:

from google.cloud import bigquery
from google.cloud.storage import Client as StorageClient

which of course may not work for everyone, but for me it's good enough. I am not sure why it would work, but it does.

EDIT: this is on Python 3.10.2 + Poetry

@hauntsaninja hauntsaninja self-assigned this Jul 8, 2022
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jul 15, 2022

Okay, had some free time, so looked into this. There are a couple different things alluded to in this issue:

The first issue is that google-cloud-firestore (and google-cloud-storage) are not py.typed packages. This means that mypy does not know anything about them and things are expected to fail. Note that google-cloud-bigquery does have a py.typed, which is why it doesn't cause any issues.

λ mypy -c 'from google.cloud import firestore'
<string>:1: error: Skipping analyzing "google.cloud": module is installed, but missing library stubs or py.typed marker
<string>:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

The second issue is that mypy gives an unhelpful diagnostic / gives a diagnostic with an inconsistent error code in cases involving multiple imports from the same namespace package ("no attribute" instead of the clearer message mentioning py.typed above). See #10360 for more details. I believe this issue is mainly just a duplicate of that one, so I'll be closing this.

The third issue (alluded to here, but without repro) is with incremental mode. Several issues with these have been fixed, but there is one recently reported issue that is not yet fixed, see #13085. I'll have a fix for this soon (which should hopefully be more robust than patches to similar prior issues).

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2022
DanielRyanSmith added a commit to GoogleChrome/chromium-dashboard that referenced this issue Oct 12, 2022
DanielRyanSmith added a commit to GoogleChrome/chromium-dashboard that referenced this issue Oct 12, 2022
DanielRyanSmith added a commit to GoogleChrome/chromium-dashboard that referenced this issue Oct 16, 2022
DanielRyanSmith added a commit to GoogleChrome/chromium-dashboard that referenced this issue Oct 24, 2022
* run mypy in CI

* more type hint fixing

* Update requirements.txt

* google.cloud import workaround

python/mypy#10360

* Revert "google.cloud import workaround"

This reverts commit e03dbc7.

* mypy google.cloud workaround

python/mypy#12985

* fix regular tests

* remove --install-types flag

* last mypy fix

* type fixes for address_reasons

* move email lists creation

* update for newly merged changes

* Fix regular tests

* Changes suggested by @jrobbins

* Catch invalid requests

* small type hint

* Change methods to properly override

* revert to previous implementation

* revert test

* add back original validate request type method

* remove unused import and rearrange methods

* remove comment string casting; add test back

* add ndb ignore

* Update test_html_rendering.html

* mypy fix

* remove merge addition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants