Skip to content

Commit 91837ea

Browse files
committed
Fix incorrect type in ClientApp init signature
`scope_requirements` was annotated as `dict` in init for `ClientApp`, but the base class, `UserApp`, and the `add_scope_requirements` method all accept a `Mapping` -- allowing for an immutable mapping type. To confirm the fix, the typing test which currently checks the scope requirements type of app objects is expanded to cover - both UserApp and ClientApp - `add_scope_requirements` and `__init__` - a `dict` which is a subtype of `Mapping[K, V]` but not of `dict[K, V]` (for our specific `K, V`) and a `types.MappingProxyType` (an immutable dict proxy) fixes #1358
1 parent c8f27b8 commit 91837ea

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fixed
2+
-----
3+
4+
- The type of ``scope_requirements`` in the init signature for ``ClientApp``
5+
has been expanded to ``typing.Mapping`` to match other locations where a
6+
``scope_requirements`` mapping is accepted. (:pr:`NUMBER`)

src/globus_sdk/globus_app/client_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(
6161
client_id: uuid.UUID | str | None = None,
6262
client_secret: str | None = None,
6363
scope_requirements: (
64-
dict[str, str | Scope | t.Iterable[str | Scope]] | None
64+
t.Mapping[str, str | Scope | t.Iterable[str | Scope]] | None
6565
) = None,
6666
config: GlobusAppConfig = DEFAULT_CONFIG,
6767
) -> None:
Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from globus_sdk import UserApp
1+
from types import MappingProxyType
2+
3+
from globus_sdk import ClientApp, UserApp
4+
5+
my_user_app = UserApp("...", client_id="...")
6+
my_client_app = ClientApp("...", client_id="...", client_secret="...")
27

38
# declare scope data in the form of a subtype of the
49
# `str | Scope | t.Iterable[str | Scope]` (`list[str]`) indexed in a dict,
@@ -9,5 +14,26 @@
914
# `dict[str, str | Scope | t.Iterable[str | Scope]]` which will reject the input
1015
# type because `dict` is a mutable container, and therefore invariant
1116
scopes: dict[str, list[str]] = {"foo": ["bar"]}
12-
my_app = UserApp("...", client_id="...")
13-
my_app.add_scope_requirements(scopes)
17+
my_user_app.add_scope_requirements(scopes)
18+
my_client_app.add_scope_requirements(scopes)
19+
20+
# a mapping proxy is an immutable mapping (proxy) and should be accepted by apps as well
21+
# meaning that any mapping is fine, not just `dict` specifically (or MutableMapping)
22+
my_user_app.add_scope_requirements(MappingProxyType(scopes))
23+
my_client_app.add_scope_requirements(MappingProxyType(scopes))
24+
25+
26+
# both of the above tests repeated, but now on init
27+
my_user_app = UserApp("...", client_id="...", scope_requirements=scopes)
28+
my_user_app = UserApp(
29+
"...", client_id="...", scope_requirements=MappingProxyType(scopes)
30+
)
31+
my_client_app = ClientApp(
32+
"...", client_id="...", client_secret="...", scope_requirements=scopes
33+
)
34+
my_client_app = ClientApp(
35+
"...",
36+
client_id="...",
37+
client_secret="...",
38+
scope_requirements=MappingProxyType(scopes),
39+
)

0 commit comments

Comments
 (0)