Skip to content

Cannot resolve google imports when types-protobuf is installed (see #2113) #3745

Closed

Description

@meangrape

Describe the bug
Running pyright against code including google modules results in reportMissingImport and reportGeneralTypeIssues errors. See #2113

Screenshots or Code

Could not import 'google.api_core' in file '/Users/jayed/repos/create_cluster/src/create_cluster.py'
  Looking in stubPath '/Users/jayed/repos/create_cluster/typings'
  Attempting to resolve stub package using root path '/Users/jayed/repos/create_cluster/typings'
  Attempting to resolve using root path '/Users/jayed/repos/create_cluster/typings'
  Looking in root directory of execution environment '/Users/jayed/repos/create_cluster'
  Attempting to resolve stub package using root path '/Users/jayed/repos/create_cluster'
  Attempting to resolve using root path '/Users/jayed/repos/create_cluster'
  Looking in python search path '/Users/jayed/Library/Caches/pypoetry/virtualenvs/create-cluster-PmxHvHbg-py3.10/lib/python3.10/site-packages'
  Attempting to resolve stub package using root path '/Users/jayed/Library/Caches/pypoetry/virtualenvs/create-cluster-PmxHvHbg-py3.10/lib/python3.10/site-packages'
  Resolved import with file '/Users/jayed/Library/Caches/pypoetry/virtualenvs/create-cluster-PmxHvHbg-py3.10/lib/python3.10/site-packages/google-stubs/__init__.pyi'
  Looking in python search path '/Users/jayed/repos/create_cluster'
  Attempting to resolve stub package using root path '/Users/jayed/repos/create_cluster'
  Attempting to resolve using root path '/Users/jayed/repos/create_cluster'
  Looking for typeshed stdlib path
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/Users/jayed/.npm/_npx/6f75558c21262cab/node_modules/pyright/dist/typeshed-fallback/stdlib'
  Typeshed path not found
  Looking for typeshed third-party path
  Looking for typeshed stubs path
  Attempting to resolve using root path '/Users/jayed/.npm/_npx/6f75558c21262cab/node_modules/pyright/dist/typeshed-fallback/stubs/google-cloud-ndb'
  Attempting to resolve using root path '/Users/jayed/.npm/_npx/6f75558c21262cab/node_modules/pyright/dist/typeshed-fallback/stubs/protobuf'
  Resolved import with file '/Users/jayed/.npm/_npx/6f75558c21262cab/node_modules/pyright/dist/typeshed-fallback/stubs/protobuf/google/__init__.pyi'
  Typeshed path not found
... [EDITED]
pyright 1.1.263
/Users/jayed/repos/create_cluster/src/create_cluster.py
  /Users/jayed/repos/create_cluster/src/create_cluster.py:41:6 - error: Import "google.api_core" could not be resolved (reportMissingImports)

from google.api_core import client_options
Version: 2.8.2

types-protobuf version: 3.19.22

VS Code extension or command-line
pyright --verbose src/create_cluster.py

Additional context
Uninstalling types-protobuf makes the errors go away.

Activity

  1. hmc-cs-mdrissi commented on Jul 25, 2022

    @hmc-cs-mdrissi

    Which version of types-protobuf? I recommend using types-protobuf==3.19.14. This is probably upstream bug caused by wrong __init__.pyi in typeshed. There was a time it was "fixed", but the fix breaks mypy until this pr is merged python/mypy#9636

  2. meangrape commented on Jul 25, 2022

    @meangrape
    Author

    Downgrading types-protobuf from 3.19.22 to 3.19.14 fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions