Skip to content

Conversation

@sirosen
Copy link
Member

@sirosen sirosen commented Jul 25, 2025

sc-41886

These changes seek to get some better control over the scope interfaces in SDK v4.
Primarily, the outstanding 'odd things' are scope normalizing functions which were added for internal use-cases but declared as public, user-facing functions.

scopes_to_str is here deemed reasonable to expose, but makes a great deal of sense to attach to the ScopeParser object.
It is now provided as ScopeParser.serialize and features a new flag, reject_empty (defaults to True) which replaces some internal functionality smoothly.
Attachment as a public method to a public object also helps to clarify for internal and external developers that the function is intentionally public (vs name leakage).

scopes_to_scope_list gets the opposite treatment.
This is only used inside of GlobusApp for some normalization, and it supports a variety of types at runtime which we have declared unsupported in our typing-time contracts.
It is replaced with an internal GlobusApp._iter_scopes helper, which we can change at will to suit the needs of the SDK itself.

The relevant tests for these functions have been ported, as appropriate, to their new implementations.

Because direct usage of these functions is relatively niche, I have opted not to include them in the upgrading guide.
They are called out unceremoniously in the changelog as Breaking Changes.


📚 Documentation preview 📚: https://globus-sdk-python--1289.org.readthedocs.build/en/1289/

sirosen added 4 commits July 25, 2025 17:09
This moves the function to the parser class, but also slightly
simplifies its behavior. It now refrains from any "re-parsing" of
data, and simply joins together strings provided by the user.

Users who want to do more normalization have access to
`ScopeParser.merge_scopes`, which does more rigorous handling than
what was present in `scopes_to_str`.
This function was supported as a public interface but only had one
known usage site, in `GlobusApp`. It has been removed and replaced
with an internal method, `GlobusApp._iter_scopes`.

Unit tests are updated to test the new replacement helper. Because the
helper has a tighter contract in terms of what it supports and in what
context, it is greatly simplified in the process as well. The older
helper structure shows evidence of past iterations in terms of
handling nested iterables.
Rather than a helper specific to Globus Auth components doing this as
a post-processing step, handling for `""` as the output is now baked
into `ScopeParser.serialize`. By default, it will raise an error if it
finds that the serialized data is `""`.

For example, `ScopeParser.serialize([])` errors.

A new flag, `reject_empty=False`, can be passed to explicitly disable
the check, if users have a desire to handle an unknown iterable and
check if it's empty *after* serialization.
Copy link
Contributor

@ada-globus ada-globus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree w/ these decisions. Replacing scopes_to_str and stringify_requested_scopes with serialize is a nice win for clarity.

@sirosen sirosen merged commit db21ddd into globus:4.x-dev Jul 29, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants