Skip to content

Commit

Permalink
Update pyupgrade lower bound to 3.8 (#1128)
Browse files Browse the repository at this point in the history
This upgrades various version-dispatched imports of typing symbols,
mostly Literal but also Protocol.
  • Loading branch information
sirosen authored Jan 14, 2025
1 parent 7b49f56 commit f434f8e
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
rev: v3.19.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]
args: ["--py38-plus"]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
hooks:
Expand Down
12 changes: 3 additions & 9 deletions src/globus_sdk/_testing/models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from __future__ import annotations

import sys
import types
import typing as t

import responses

from ..utils import slash_join

if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal


class RegisteredResponse:
"""
Expand Down Expand Up @@ -63,7 +57,7 @@ def __init__(
# in `responses`, these are just `url`
path: str,
service: (
Literal[
t.Literal[
"auth",
"nexus",
"transfer",
Expand All @@ -78,7 +72,7 @@ def __init__(
) = None,
# method will be passed through to `responses.Response`, so we
# support all of the values which it supports
method: Literal[
method: t.Literal[
"GET",
"PUT",
"POST",
Expand Down Expand Up @@ -152,7 +146,7 @@ def metadata(self) -> dict[str, t.Any]:

def _add_or_replace(
self,
method: Literal["add", "replace"],
method: t.Literal["add", "replace"],
*,
requests_mock: responses.RequestsMock | None = None,
) -> RegisteredResponse:
Expand Down
8 changes: 1 addition & 7 deletions src/globus_sdk/_types.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
from __future__ import annotations

import datetime
import sys
import typing as t
import uuid

if sys.version_info < (3, 8):
from typing_extensions import Protocol
else:
from typing import Protocol

if t.TYPE_CHECKING:
from globus_sdk.scopes import MutableScope, Scope

Expand All @@ -27,7 +21,7 @@
]


class ResponseLike(Protocol):
class ResponseLike(t.Protocol):
@property
def http_status(self) -> int: ...

Expand Down
16 changes: 5 additions & 11 deletions src/globus_sdk/gare/_variants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import sys
import typing as t

from globus_sdk import exc
Expand All @@ -9,15 +8,10 @@

from ._auth_requirements_error import GARE, GlobusAuthorizationParameters

if sys.version_info >= (3, 8):
from typing import Literal, Protocol
else:
from typing_extensions import Literal, Protocol

V = t.TypeVar("V", bound="LegacyAuthRequirementsErrorVariant")


class LegacyAuthRequirementsErrorVariant(Protocol):
class LegacyAuthRequirementsErrorVariant(t.Protocol):
"""
Protocol for errors which can be converted to a Globus Auth Requirements Error.
"""
Expand All @@ -37,7 +31,7 @@ class LegacyConsentRequiredTransferError(Serializable):
def __init__(
self,
*,
code: Literal["ConsentRequired"],
code: t.Literal["ConsentRequired"],
required_scopes: list[str],
extra: dict[str, t.Any] | None = None,
) -> None:
Expand Down Expand Up @@ -68,7 +62,7 @@ class LegacyConsentRequiredAPError(Serializable):
def __init__(
self,
*,
code: Literal["ConsentRequired"],
code: t.Literal["ConsentRequired"],
required_scope: str,
extra: dict[str, t.Any] | None,
) -> None:
Expand Down Expand Up @@ -110,7 +104,7 @@ def __init__(
session_required_policies: str | list[str] | None = None,
session_required_single_domain: str | list[str] | None = None,
session_required_mfa: bool | None = None,
prompt: Literal["login"] | None = None,
prompt: t.Literal["login"] | None = None,
extra: dict[str, t.Any] | None = None,
) -> None:
self.session_message = validators.opt_str("session_message", session_message)
Expand Down Expand Up @@ -193,7 +187,7 @@ def to_auth_requirements_error(self) -> GARE:

def _validate_consent_required_literal(
name: str, value: t.Any
) -> Literal["ConsentRequired"]:
) -> t.Literal["ConsentRequired"]:
if value == "ConsentRequired":
return "ConsentRequired"
raise exc.ValidationError(f"'{name}' must be the string 'ConsentRequired'")
16 changes: 5 additions & 11 deletions src/globus_sdk/globus_app/protocols.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
from __future__ import annotations

import sys
import typing as t

from globus_sdk import AuthLoginClient
from globus_sdk._types import UUIDLike
from globus_sdk.login_flows import LoginFlowManager
from globus_sdk.tokenstorage import TokenStorage

if sys.version_info < (3, 8):
from typing_extensions import Protocol, runtime_checkable
else:
from typing import Protocol, runtime_checkable

if t.TYPE_CHECKING:
from globus_sdk.tokenstorage import TokenValidationError

from .app import GlobusApp
from .config import GlobusAppConfig


@runtime_checkable
class TokenStorageProvider(Protocol):
@t.runtime_checkable
class TokenStorageProvider(t.Protocol):
"""
A protocol for a factory which can create ``TokenStorages``.
Expand All @@ -47,8 +41,8 @@ def for_globus_app(
"""


@runtime_checkable
class LoginFlowManagerProvider(Protocol):
@t.runtime_checkable
class LoginFlowManagerProvider(t.Protocol):
"""
A protocol for a factory which can create ``LoginFlowManagers``.
Expand All @@ -68,7 +62,7 @@ def for_globus_app(
"""


class TokenValidationErrorHandler(Protocol):
class TokenValidationErrorHandler(t.Protocol):
"""
A handler invoked when a :class:`TokenValidationError` is raised during a
service client call.
Expand Down
16 changes: 5 additions & 11 deletions src/globus_sdk/services/auth/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
import logging
import sys
import typing as t

import jwt
Expand All @@ -14,11 +13,6 @@
from globus_sdk.response import GlobusHTTPResponse
from globus_sdk.scopes import AuthScopes, TransferScopes, scopes_to_str

if sys.version_info >= (3, 8):
from typing import Literal, Protocol, runtime_checkable
else:
from typing_extensions import Literal, Protocol, runtime_checkable

log = logging.getLogger(__name__)

_DEFAULT_REQUESTED_SCOPES = (
Expand Down Expand Up @@ -47,7 +41,7 @@ def stringify_requested_scopes(requested_scopes: ScopeCollectionType | None) ->
return requested_scopes_string


class _JWKGetCallbackProto(Protocol):
class _JWKGetCallbackProto(t.Protocol):
def __call__(
self,
path: str,
Expand Down Expand Up @@ -91,8 +85,8 @@ def pem_decode_jwk_data(
return jwk_as_pem


@runtime_checkable
class SupportsJWKMethods(Protocol):
@t.runtime_checkable
class SupportsJWKMethods(t.Protocol):
client_id: str | None

def get_openid_configuration(self) -> GlobusHTTPResponse: ...
Expand All @@ -102,15 +96,15 @@ def get_jwk(
self,
openid_configuration: None | GlobusHTTPResponse | dict[str, t.Any],
*,
as_pem: Literal[True],
as_pem: t.Literal[True],
) -> RSAPublicKey: ...

@t.overload
def get_jwk(
self,
openid_configuration: None | GlobusHTTPResponse | dict[str, t.Any],
*,
as_pem: Literal[False],
as_pem: t.Literal[False],
) -> dict[str, t.Any]: ...

def get_jwk(
Expand Down
12 changes: 3 additions & 9 deletions src/globus_sdk/services/auth/client/base_login_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import logging
import sys
import typing as t

from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
Expand All @@ -21,11 +20,6 @@
OAuthTokenResponse,
)

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal

log = logging.getLogger(__name__)

RT = t.TypeVar("RT", bound=GlobusHTTPResponse)
Expand Down Expand Up @@ -103,15 +97,15 @@ def get_jwk(
self,
openid_configuration: None | GlobusHTTPResponse | dict[str, t.Any],
*,
as_pem: Literal[True],
as_pem: t.Literal[True],
) -> RSAPublicKey: ...

@t.overload
def get_jwk(
self,
openid_configuration: None | GlobusHTTPResponse | dict[str, t.Any],
*,
as_pem: Literal[False],
as_pem: t.Literal[False],
) -> dict[str, t.Any]: ...

# FYI: this get_jwk method is duplicated in AuthClient
Expand Down Expand Up @@ -151,7 +145,7 @@ def oauth2_get_authorize_url(
session_required_single_domain: str | t.Iterable[str] | None = None,
session_required_policies: UUIDLike | t.Iterable[UUIDLike] | None = None,
session_required_mfa: bool | None = None,
prompt: Literal["login"] | None = None,
prompt: t.Literal["login"] | None = None,
query_params: dict[str, t.Any] | None = None,
) -> str:
"""
Expand Down
10 changes: 2 additions & 8 deletions src/globus_sdk/services/auth/client/service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import functools
import logging
import sys
import typing as t

from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
Expand Down Expand Up @@ -30,11 +29,6 @@
GetScopesResponse,
)

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal

log = logging.getLogger(__name__)

F = t.TypeVar("F", bound=t.Callable[..., GlobusHTTPResponse])
Expand Down Expand Up @@ -178,15 +172,15 @@ def get_jwk(
self,
openid_configuration: None | GlobusHTTPResponse | dict[str, t.Any],
*,
as_pem: Literal[True],
as_pem: t.Literal[True],
) -> RSAPublicKey: ...

@t.overload
def get_jwk(
self,
openid_configuration: None | GlobusHTTPResponse | dict[str, t.Any],
*,
as_pem: Literal[False],
as_pem: t.Literal[False],
) -> dict[str, t.Any]: ...

# FYI: this get_jwk method is duplicated in AuthLoginBaseClient
Expand Down
9 changes: 1 addition & 8 deletions src/globus_sdk/services/gcs/data/_common.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
from __future__ import annotations

import sys
import typing as t

from globus_sdk.utils import MISSING

if sys.version_info < (3, 8):
from typing_extensions import Protocol
else:
from typing import Protocol


VersionTuple = t.Tuple[int, int, int]

DatatypeCallback = t.Callable[["DocumentWithInducedDatatype"], t.Optional[VersionTuple]]


class DocumentWithInducedDatatype(Protocol):
class DocumentWithInducedDatatype(t.Protocol):
DATATYPE_BASE: str
DATATYPE_VERSION_IMPLICATIONS: dict[str, VersionTuple]
DATATYPE_VERSION_CALLBACKS: tuple[DatatypeCallback, ...]
Expand Down
Loading

0 comments on commit f434f8e

Please sign in to comment.