Skip to content

Commit

Permalink
Merge pull request #433 from microsoft/andrueastman/python38drop
Browse files Browse the repository at this point in the history
feat: drop support for python 3.8
  • Loading branch information
andrueastman authored Jan 10, 2025
2 parents 81ff8e8 + 3ef136c commit 63e157b
Show file tree
Hide file tree
Showing 70 changed files with 352 additions and 350 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
max-parallel: 10
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
library :
- name: "kiota_abstractions"
path: "./packages/abstractions"
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
strategy:
max-parallel: 10
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable
from collections.abc import Callable

from .serialization import (
ParseNodeFactory,
Expand Down
4 changes: 2 additions & 2 deletions packages/abstractions/kiota_abstractions/api_error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Dict, Optional
from typing import Optional


@dataclass
Expand All @@ -8,7 +8,7 @@ class APIError(Exception):

message: Optional[str] = None
response_status_code: Optional[int] = None
response_headers: Optional[Dict[str, str]] = None
response_headers: Optional[dict[str, str]] = None

def __str__(self) -> str:
error = getattr(self, "error", None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ------------------------------------------------------------------------------

from abc import ABC, abstractmethod
from typing import Any, Dict
from typing import Any

from .allowed_hosts_validator import AllowedHostsValidator

Expand All @@ -16,7 +16,7 @@ class AccessTokenProvider(ABC):

@abstractmethod
async def get_authorization_token(
self, uri: str, additional_authentication_context: Dict[str, Any] = {}
self, uri: str, additional_authentication_context: dict[str, Any] = {}
) -> str:
"""This method is called by the BaseBearerTokenAuthenticationProvider class to get the
access token.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import List, Set
from urllib.parse import urlparse


Expand All @@ -7,31 +6,31 @@ class AllowedHostsValidator:
a host is valid before authenticating a request
"""

def __init__(self, allowed_hosts: List[str]) -> None:
def __init__(self, allowed_hosts: list[str]) -> None:
"""Creates a new AllowedHostsValidator object with provided values.
Args:
allowed_hosts (List[str]): A list of valid hosts. If the list is empty, all hosts
allowed_hosts (list[str]): A list of valid hosts. If the list is empty, all hosts
are valid.
"""
if not isinstance(allowed_hosts, list):
raise TypeError("Allowed hosts must be a list of strings")

self.allowed_hosts: Set[str] = {x.lower() for x in allowed_hosts}
self.allowed_hosts: set[str] = {x.lower() for x in allowed_hosts}

def get_allowed_hosts(self) -> List[str]:
def get_allowed_hosts(self) -> list[str]:
"""Gets the list of valid hosts. If the list is empty, all hosts are valid.
Returns:
List[str]: A list of valid hosts. If the list is empty, all hosts are valid.
list[str]: A list of valid hosts. If the list is empty, all hosts are valid.
"""
return list(self.allowed_hosts)

def set_allowed_hosts(self, allowed_hosts: List[str]) -> None:
def set_allowed_hosts(self, allowed_hosts: list[str]) -> None:
"""Sets the list of valid hosts. If the list is empty, all hosts are valid.
Args:
allowed_hosts (List[str]): A list of valid hosts. If the list is empty, all hosts
allowed_hosts (list[str]): A list of valid hosts. If the list is empty, all hosts
are valid
"""
if not isinstance(allowed_hosts, list):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from typing import Any, Dict
from typing import Any

from ..request_information import RequestInformation
from .authentication_provider import AuthenticationProvider
Expand All @@ -20,7 +20,7 @@ class AnonymousAuthenticationProvider(AuthenticationProvider):
async def authenticate_request(
self,
request: RequestInformation,
additional_authentication_context: Dict[str, Any] = {}
additional_authentication_context: dict[str, Any] = {}
) -> None:
"""Authenticates the provided request information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ------------------------------------------------------------------------------

from enum import Enum
from typing import Any, Dict, List
from typing import Any
from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse

from kiota_abstractions.request_information import RequestInformation
Expand Down Expand Up @@ -33,7 +33,7 @@ def __init__(
key_location: KeyLocation,
api_key: str,
parameter_name: str,
allowed_hosts: List[str] = [],
allowed_hosts: list[str] = [],
) -> None:
if not isinstance(key_location, KeyLocation):
err = "key_location can only be 'query_parameter' or 'header'"
Expand All @@ -56,7 +56,7 @@ def __init__(
async def authenticate_request(
self,
request: RequestInformation,
additional_authentication_context: Dict[str, Any] = {}
additional_authentication_context: dict[str, Any] = {}
) -> None:
"""
Ensures that the API key is placed in the correct location for a request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ------------------------------------------------------------------------------

from abc import ABC, abstractmethod
from typing import Any, Dict
from typing import Any

from ..request_information import RequestInformation

Expand All @@ -19,7 +19,7 @@ class AuthenticationProvider(ABC):
async def authenticate_request(
self,
request: RequestInformation,
additional_authentication_context: Dict[str, Any] = {}
additional_authentication_context: dict[str, Any] = {}
) -> None:
"""Authenticates the application request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See License in the project root for license information.
# ------------------------------------------------------------------------------

from typing import Any, Dict
from typing import Any

from ..headers_collection import HeadersCollection
from ..request_information import RequestInformation
Expand All @@ -24,7 +24,7 @@ def __init__(self, access_token_provider: AccessTokenProvider) -> None:
async def authenticate_request(
self,
request: RequestInformation,
additional_authentication_context: Dict[str, Any] = {}
additional_authentication_context: dict[str, Any] = {}
) -> None:
"""Authenticates the provided RequestInformation instance using the provided
authorization token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------
from typing import Any, Dict, Optional, Union
from typing import Any, Optional, Union

from .request_adapter import RequestAdapter
from .request_information import RequestInformation
Expand All @@ -14,7 +14,7 @@ class BaseRequestBuilder:

def __init__(
self, request_adapter: RequestAdapter, url_template: str,
path_parameters: Optional[Union[Dict[str, Any], str]]
path_parameters: Optional[Union[dict[str, Any], str]]
) -> None:
"""Initializes a new instance of the BaseRequestBuilder class."""
if path_parameters is None:
Expand All @@ -28,7 +28,7 @@ def __init__(
raise TypeError("url_template cannot be null.") # Empty string is allowed

# Path parameters for the request
self.path_parameters: Dict[str, Any] = path_parameters
self.path_parameters: dict[str, Any] = path_parameters
# Url template to use to build the URL for the current request builder
self.url_template: str = url_template
# The request adapter to use to execute the requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See License in the project root for license information.
# ------------------------------------
from dataclasses import dataclass
from typing import Generic, List, Optional, TypeVar
from typing import Generic, Optional, TypeVar
from warnings import warn

from .headers_collection import HeadersCollection
Expand All @@ -21,7 +21,7 @@ class RequestConfiguration(Generic[QueryParameters]):
# Request headers
headers: HeadersCollection = HeadersCollection()
# Request options
options: Optional[List[RequestOption]] = None
options: Optional[list[RequestOption]] = None
# Request query parameters
query_parameters: Optional[QueryParameters] = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# See License in the project root for license information.
# ------------------------------------
from dataclasses import dataclass
from typing import List, Optional
from warnings import warn


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Any, Dict, Optional, Union
from typing import Any, Optional, Union

from .request_information import RequestInformation


def get_path_parameters(parameters: Union[Dict[str, Any], Optional[str]]) -> Dict[str, Any]:
result: Dict[str, Any] = {}
def get_path_parameters(parameters: Union[dict[str, Any], Optional[str]]) -> dict[str, Any]:
result: dict[str, Any] = {}
if isinstance(parameters, str):
result[RequestInformation.RAW_URL_KEY] = parameters
elif isinstance(parameters, dict):
Expand Down
32 changes: 16 additions & 16 deletions packages/abstractions/kiota_abstractions/headers_collection.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
from __future__ import annotations

from typing import Dict, List, Set, Union
from typing import Union


class HeadersCollection():
"Represents a collection of request/response headers"
SINGLE_VALUE_HEADERS: Set[str] = {"content-type", "content-encoding", "content-length"}
SINGLE_VALUE_HEADERS: set[str] = {"content-type", "content-encoding", "content-length"}

def __init__(self) -> None:
self._headers: Dict[str, Set[str]] = {}
self._headers: dict[str, set[str]] = {}

def try_get(self, key: str) -> Union[bool, Set[str]]:
def try_get(self, key: str) -> Union[bool, set[str]]:
"""Gets the header values corresponding to a specific header name.
Args:
key (str): Header key.
Returns:
Union[bool, Set[str]]: The header values for the specified header key or False.
Union[bool, set[str]]: The header values for the specified header key or False.
"""
if not key:
raise ValueError("Header name cannot be null")
Expand All @@ -27,22 +27,22 @@ def try_get(self, key: str) -> Union[bool, Set[str]]:
return values
return False

def get_all(self) -> Dict[str, Set[str]]:
def get_all(self) -> dict[str, set[str]]:
"""Get all headers and values stored so far.
Returns:
Dict[str, str]: The headers
dict[str, str]: The headers
"""
return self._headers

def get(self, header_name: str) -> Set[str]:
def get(self, header_name: str) -> set[str]:
"""Get header values corresponding to a specific header.
Args:
header_name (str): Header key.
Returns:
Set[str]: Values for the header key
set[str]: Values for the header key
"""
if not header_name:
raise ValueError("Header name cannot be null")
Expand Down Expand Up @@ -76,20 +76,20 @@ def add_all(self, headers: HeadersCollection) -> None:
"""Adds the specified headers to the collection.
Args:
headers (Dict[str, str]): The headers to add.
headers (dict[str, str]): The headers to add.
"""
if not headers:
raise ValueError("Headers cannot be null")
for key, values in headers.get_all().items():
for value in values:
self.add(key, value)

def add(self, header_name: str, header_values: Union[str, List[str]]) -> None:
def add(self, header_name: str, header_values: Union[str, list[str]]) -> None:
"""Adds values to the header with the specified name.
Args:
header_name (str): The name of the header to add values to.
header_values (List[str]): The values to add to the header.
header_values (list[str]): The values to add to the header.
"""
if not header_name:
raise ValueError("Header name cannot be null")
Expand All @@ -112,18 +112,18 @@ def add(self, header_name: str, header_values: Union[str, List[str]]) -> None:
else:
self._headers[header_name] = {header_values}

def keys(self) -> List[str]:
def keys(self) -> list[str]:
"""Gets the header names present in the collection.
Returns:
List[str]: The header names present in the collection.
list[str]: The header names present in the collection.
"""
return list(self._headers.keys())

def count(self):
"""Gets the number of headers present in the collection."""
return len(self._headers)

def remove_value(self, header_name: str, header_value: str) -> Union[bool, Set[str]]:
def remove_value(self, header_name: str, header_value: str) -> Union[bool, set[str]]:
"""Removes the specified value from the header with the specified name.
Args:
Expand All @@ -147,7 +147,7 @@ def remove_value(self, header_name: str, header_value: str) -> Union[bool, Set[s

return False

def remove(self, header_name: str) -> Union[bool, Set[str]]:
def remove(self, header_name: str) -> Union[bool, set[str]]:
"""Removes the header with the specified name.
Args:
Expand Down
Loading

0 comments on commit 63e157b

Please # to comment.