From f6fbc5c1fd6553de2186711fda902aba104fd1cb Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Fri, 25 Aug 2023 13:02:11 +0200 Subject: [PATCH] Issue #460 use typing.NamedTuple in oidc.py --- openeo/rest/auth/oidc.py | 31 ++++++++++++++++++------------- tests/udf/test_xarraydatacube.py | 1 - 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/openeo/rest/auth/oidc.py b/openeo/rest/auth/oidc.py index c99da91f3..8d598db8b 100644 --- a/openeo/rest/auth/oidc.py +++ b/openeo/rest/auth/oidc.py @@ -12,7 +12,6 @@ import inspect import json import logging -import math import random import string import threading @@ -20,9 +19,8 @@ import urllib.parse import warnings import webbrowser -from collections import namedtuple from queue import Empty, Queue -from typing import Callable, List, Optional, Tuple, Union +from typing import Callable, List, NamedTuple, Optional, Tuple, Union import requests @@ -200,11 +198,12 @@ class OidcException(OpenEoClientException): pass -# Container for result of access_token request. -AccessTokenResult = namedtuple( - typename="AccessTokenResult", - field_names=["access_token", "id_token", "refresh_token"] -) +class AccessTokenResult(NamedTuple): + """Container for result of access_token request.""" + + access_token: str + id_token: Optional[str] = None + refresh_token: Optional[str] = None def jwt_decode(token: str) -> Tuple[dict, dict]: @@ -451,7 +450,11 @@ def sha256_hash(code: str) -> str: return base64.urlsafe_b64encode(data).decode('ascii').replace('=', '') -AuthCodeResult = namedtuple("AuthCodeResult", ["auth_code", "nonce", "code_verifier", "redirect_uri"]) +class AuthCodeResult(NamedTuple): + auth_code: str + nonce: str + code_verifier: str + redirect_uri: str class OidcAuthCodePkceAuthenticator(OidcAuthenticator): @@ -664,10 +667,12 @@ def _get_token_endpoint_post_data(self) -> dict: return data -VerificationInfo = namedtuple( - "VerificationInfo", - ["verification_uri", "verification_uri_complete", "device_code", "user_code", "interval"] -) +class VerificationInfo(NamedTuple): + verification_uri: str + verification_uri_complete: Optional[str] + device_code: str + user_code: str + interval: int def _like_print(display: Callable) -> Callable: diff --git a/tests/udf/test_xarraydatacube.py b/tests/udf/test_xarraydatacube.py index b459ea91a..1144ba192 100644 --- a/tests/udf/test_xarraydatacube.py +++ b/tests/udf/test_xarraydatacube.py @@ -1,6 +1,5 @@ import itertools from typing import Union, Optional, List, Tuple, Iterator, NamedTuple -import collections import numpy import pytest import xarray