From 3bcd807ea9d4f8ff8595815c0d49d08dccd6e14e Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Fri, 25 Sep 2026 10:25:34 -0500 Subject: [PATCH 1/2] Apply minor optimizations to scope parsing 1. Don't build methods we don't need on an internal dataclass (ScopeTreeNode) by setting `repr=False, eq=False, order=False` for that class 2. Replace `any()` with a regex search in Scope __post_init__. --- src/globus_sdk/scopes/_graph_parser.py | 2 +- src/globus_sdk/scopes/representation.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/globus_sdk/scopes/_graph_parser.py b/src/globus_sdk/scopes/_graph_parser.py index 1718e0b73..9e7e7b649 100644 --- a/src/globus_sdk/scopes/_graph_parser.py +++ b/src/globus_sdk/scopes/_graph_parser.py @@ -113,7 +113,7 @@ def _convert_trees(cls, trees: list[ScopeTreeNode]) -> ScopeGraph: _add_dataclass_kwargs: dict[str, bool] = {} -@dataclasses.dataclass(**_add_dataclass_kwargs) +@dataclasses.dataclass(repr=False, eq=False, order=False, **_add_dataclass_kwargs) class ScopeTreeNode: # # This is an intermediate representation for scope parsing. diff --git a/src/globus_sdk/scopes/representation.py b/src/globus_sdk/scopes/representation.py index bb031ad82..a7131fdef 100644 --- a/src/globus_sdk/scopes/representation.py +++ b/src/globus_sdk/scopes/representation.py @@ -1,6 +1,7 @@ from __future__ import annotations import dataclasses +import re import sys import typing as t @@ -12,6 +13,9 @@ _add_dataclass_kwargs: dict[str, bool] = {} +_BAD_SCOPE_CHARS_PATTERN: re.Pattern[str] = re.compile(r"(?:[\[\]\* ])") + + @dataclasses.dataclass(frozen=True, repr=False, **_add_dataclass_kwargs) class Scope: """ @@ -40,7 +44,7 @@ class Scope: def __post_init__( self, ) -> None: - if any(c in self.scope_string for c in "[]* "): + if _BAD_SCOPE_CHARS_PATTERN.search(self.scope_string): raise ValueError( "Scope instances may not contain the special characters '[]* '. " "Use Scope.parse instead." From 5920be675e338d181d55e99b2d91c358870fe631 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Fri, 25 Sep 2026 16:14:22 -0500 Subject: [PATCH 2/2] Update src/globus_sdk/scopes/representation.py Co-authored-by: Kurt McKee --- src/globus_sdk/scopes/representation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globus_sdk/scopes/representation.py b/src/globus_sdk/scopes/representation.py index a7131fdef..5e215f23c 100644 --- a/src/globus_sdk/scopes/representation.py +++ b/src/globus_sdk/scopes/representation.py @@ -13,7 +13,7 @@ _add_dataclass_kwargs: dict[str, bool] = {} -_BAD_SCOPE_CHARS_PATTERN: re.Pattern[str] = re.compile(r"(?:[\[\]\* ])") +_BAD_SCOPE_CHARS_PATTERN: re.Pattern[str] = re.compile(r"[\[\]* ]") @dataclasses.dataclass(frozen=True, repr=False, **_add_dataclass_kwargs)