googleapis / google-auth-library-python

Google Auth Python Library
https://googleapis.dev/python/google-auth/latest/
Apache License 2.0
752 stars 301 forks source link

mypy disallow-untyped-calls check fails for google-auth 2.30 #1543

Open n0jam opened 1 week ago

n0jam commented 1 week ago

Environment details

Steps to reproduce

  1. Install mypy and google-auth in a virtualenv
  2. Create a sample script only containing:
    import google.auth
    source_credentials, project = google.auth.default()
  3. Run mypy --ignore-missing-imports --disallow-untyped-calls ./

    With google-auth==2.29 this works fine. With google-auth==2.30 this fails with error: Call to untyped function "default" in typed context [no-untyped-call]

Did something change from google-auth 2.29 -> 2.30 regarding the typing? Thanks in advance!

clundin25 commented 1 week ago

I can reproduce this.

I do not see any commit that seems suspicious.

When I try to reproduce by pip installing from my filesystem this always fails for me, which makes it difficult to pinpoint any specific regression.

How important is this to you?

n0jam commented 1 week ago

It is not that important. We can ignore this mypy check for now, and test if it is resolved in the next google-auth version. It was more out of interest to understand why this error is raised.

antoni-szych-rtbhouse commented 1 week ago

This commit caused issues: https://github.com/googleapis/google-auth-library-python/commit/c99350455d0f7fd3aab950ac47b43000c73dd312

You can reproduce this with:

(previous commit)
>pip install git+https://github.com/googleapis/google-auth-library-python@dc6a4c15f259d6cff03dccfef2ae6958636c9d8e
...

> mypy sample_script.py
Success: no issues found in 1 source file

> pip uninstall google-auth
...

> pip install git+https://github.com/googleapis/google-auth-library-python@c99350455d0f7fd3aab950ac47b43000c73dd312
...

> mypy my_example.py
...
error: Call to untyped function "default" in typed context  [no-untyped-call]
error: Call to untyped function "Credentials" in typed context  [no-untyped-call]

I guess that something changed in the process of releasing of wheels after 2.29? In 2.29 install from git vs install from pypi gives different results (additional py.typed files on github, missing in pypi wheels):

# install from git
pip install git+https://github.com/googleapis/google-auth-library-python@v2.29.0

$ ls /home/.../lib/python3.11/site-packages/google/auth/*py.t*
/home/.../lib/python3.11/site-packages/google/auth/py.typed

$ ls /home/.../lib/python3.11/site-packages/google/oauth2/*py.t*
/home/.../lib/python3.11/site-packages/google/oauth2/py.typed

$ pip uninstall google-auth
Found existing installation: google-auth 2.29.0
Uninstalling google-auth-2.29.0:
  Would remove:
.../lib/python3.11/site-packages/google/auth/*
.../lib/python3.11/site-packages/google/oauth2/*
.../lib/python3.11/site-packages/google_auth-2.29.0.dist-info/*

Proceed (Y/n)? y
  Successfully uninstalled google-auth-2.29.0

# install from pypi

$ pip install google-auth==2.29.0
Collecting google-auth==2.29.0
  Using cached google_auth-2.29.0-py2.py3-none-any.whl (189 kB)
Installing collected packages: google-auth
Successfully installed google-auth-2.29.0

$ ls /home/.../lib/python3.11/site-packages/google/auth/py.typed
ls: cannot access /home/.../lib/python3.11/site-packages/google/auth/py.typed: No such file or directory

$ ls /home/.../lib/python3.11/site-packages/google/oauth2/py.typed
ls: cannot access /home/.../lib/python3.11/site-packages/google/oauth2/py.typed: No such file or directory

seems like there was an update:

- gcp-releasetool==1.16.0 \
+ gcp-releasetool==2.0.0 \

in https://github.com/googleapis/google-auth-library-python/commit/f01a6909ece647ef5641d33eb8be5bb8ca1180b6

I would guess that's the reason for github vs pypi installs being different for 2.29 and older (mypy error only for github versions, but no errors for pypi releases), while being the same (mypy error for both pypy and github releases) for 2.30.

n0jam commented 1 day ago

thanks for debugging this further! I tried version 2.31 but the behavior is the same as for 2.30.