Skip to content

Commit

Permalink
Merge pull request #912 from sirosen/fix-annotation
Browse files Browse the repository at this point in the history
Fix annotation for `IdentityMap.__init__` to allow `ConfidentialAppAuthClient`
  • Loading branch information
sirosen authored Dec 4, 2023
2 parents cb89f9a + 0e313b6 commit e9e3492
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog.d/20231204_112410_sirosen_fix_annotation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed
~~~~~

- Fix the type annotation for ``globus_sdk.IdentityMap`` init, which
incorrectly rejected ``ConfidentialAppAuthClient`` (:pr:`NUMBER`)
7 changes: 4 additions & 3 deletions src/globus_sdk/services/auth/identity_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import typing as t
import uuid

from .client import AuthClient
from .client import AuthClient, ConfidentialAppAuthClient


def is_username(val: str) -> bool:
Expand Down Expand Up @@ -114,7 +114,8 @@ class IdentityMap:
username = record["username"] if record is not None else "NO_SUCH_IDENTITY"
:param auth_client: The client object which will be used for lookups against Globus Auth
:type auth_client: :class:`AuthClient <globus_sdk.AuthClient>`
:type auth_client: :class:`AuthClient <globus_sdk.AuthClient>` or
:class:`ConfidentialAppAuthClient <globus_sdk.ConfidentialAppAuthClient>`
:param identity_ids: A list or other iterable of usernames or identity IDs (potentially
mixed together) which will be used to seed the ``IdentityMap`` 's tracking of
unresolved Identities.
Expand All @@ -135,7 +136,7 @@ class IdentityMap:

def __init__(
self,
auth_client: AuthClient,
auth_client: AuthClient | ConfidentialAppAuthClient,
identity_ids: t.Iterable[str] | None = None,
*,
id_batch_size: int | None = None,
Expand Down
18 changes: 18 additions & 0 deletions tests/non-pytest/mypy-ignore-tests/identity_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# check IdentityMap usages
import globus_sdk

# create clients for later usage
ac = globus_sdk.AuthClient()
nc = globus_sdk.NativeAppAuthClient("foo_client_id")
cc = globus_sdk.ConfidentialAppAuthClient("foo_client_id", "foo_client_secret")

# check init allows CC, but not NC
im = globus_sdk.IdentityMap(ac)
im = globus_sdk.IdentityMap(cc)
im = globus_sdk.IdentityMap(nc) # type: ignore[arg-type]

# getitem and delitem work, but setitem and contains do not
foo = im["foo"]
del im["foo"]
im["foo"] = "bar" # type: ignore[index]
somebool = "foo" in im # type: ignore[operator]

0 comments on commit e9e3492

Please sign in to comment.