diff --git a/cloudfoundry_client/common_objects.py b/cloudfoundry_client/common_objects.py index 99e9c49..f967c7b 100644 --- a/cloudfoundry_client/common_objects.py +++ b/cloudfoundry_client/common_objects.py @@ -1,5 +1,5 @@ import json -from typing import Callable, TypeVar, Generic, List +from typing import Callable, TypeVar, Generic class Request(dict): @@ -22,7 +22,7 @@ class Pagination(Generic[ENTITY]): def __init__(self, first_page: JsonObject, total_result: int, next_page_loader: Callable[[JsonObject], JsonObject | None], - resources_accessor: Callable[[JsonObject], List[JsonObject]], + resources_accessor: Callable[[JsonObject], list[JsonObject]], instance_creator: Callable[[JsonObject], ENTITY]): self._first_page = first_page self._total_results = total_result diff --git a/cloudfoundry_client/main/command_domain.py b/cloudfoundry_client/main/command_domain.py index 334b019..06d9e46 100644 --- a/cloudfoundry_client/main/command_domain.py +++ b/cloudfoundry_client/main/command_domain.py @@ -5,7 +5,7 @@ from argparse import _SubParsersAction, Namespace from collections import OrderedDict from http import HTTPStatus -from typing import Callable, Any, List +from typing import Callable, Any from cloudfoundry_client.client import CloudFoundryClient from cloudfoundry_client.errors import InvalidStatusCode @@ -60,7 +60,7 @@ def __init__( self.commands[command[0].entry] = command[0] self.extra_description[command[0].entry] = command[1] - def description(self) -> List[str]: + def description(self) -> list[str]: description = [ " %s" % self.display_name, " %s : List %ss" % (self._list_entry(), self.entity_name), diff --git a/cloudfoundry_client/networking/entities.py b/cloudfoundry_client/networking/entities.py index 02fbe09..73a453b 100644 --- a/cloudfoundry_client/networking/entities.py +++ b/cloudfoundry_client/networking/entities.py @@ -1,6 +1,6 @@ import logging from functools import reduce -from typing import Callable, List, Tuple, Any, Generator, TYPE_CHECKING +from typing import Callable, Tuple, Any, Generator, TYPE_CHECKING from urllib.parse import quote from requests import Response @@ -31,7 +31,7 @@ def __init__(self, target_endpoint: str, client: "CloudFoundryClient", *args, ** raise InvalidEntity(**self) -EntityBuilder = Callable[[List[Tuple[str, Any]]], Entity] +EntityBuilder = Callable[[list[Tuple[str, Any]]], Entity] class EntityManager(object): @@ -105,7 +105,7 @@ def _get_entity_builder(self, entity_builder: EntityBuilder | None) -> EntityBui return entity_builder def _get_url_filtered(self, url: str, **kwargs) -> str: - def _append_encoded_parameter(parameters: List[str], args: Tuple[str, Any]) -> List[str]: + def _append_encoded_parameter(parameters: list[str], args: Tuple[str, Any]) -> list[str]: parameter_name, parameter_value = args[0], args[1] if parameter_name in self.list_query_parameters: parameters.append("%s=%s" % (parameter_name, str(parameter_value))) diff --git a/cloudfoundry_client/networking/v1/external/policies.py b/cloudfoundry_client/networking/v1/external/policies.py index 3b7c094..826093f 100644 --- a/cloudfoundry_client/networking/v1/external/policies.py +++ b/cloudfoundry_client/networking/v1/external/policies.py @@ -1,6 +1,5 @@ import logging from cloudfoundry_client.networking.entities import EntityManager -from typing import List _logger = logging.getLogger(__name__) @@ -45,7 +44,7 @@ class PolicyManager(EntityManager): def __init__(self, target_endpoint, client): super(PolicyManager, self).__init__(target_endpoint, client, "/networking/v1/external/policies") - def create(self, policies: List[Policy]): + def create(self, policies: list[Policy]): """create a new network policy Responses: @@ -62,7 +61,7 @@ def create(self, policies: List[Policy]): data.append(policy.dump()) return super(PolicyManager, self)._create({"policies": data}) - def delete(self, policies: List[Policy]): + def delete(self, policies: list[Policy]): """remove a new network policy Responses: diff --git a/cloudfoundry_client/operations/push/cf_ignore.py b/cloudfoundry_client/operations/push/cf_ignore.py index e04033f..7436582 100644 --- a/cloudfoundry_client/operations/push/cf_ignore.py +++ b/cloudfoundry_client/operations/push/cf_ignore.py @@ -1,7 +1,6 @@ import fnmatch import logging import os -from typing import List _logger = logging.getLogger(__name__) @@ -26,7 +25,7 @@ def is_relative_file_ignored(cf_ignore_entry): return any([is_relative_file_ignored(ignore_item) for ignore_item in self.ignore_items]) @staticmethod - def _pattern(pattern: str) -> List[str]: + def _pattern(pattern: str) -> list[str]: if pattern.find("/") < 0: return [pattern, os.path.join("**", pattern)] elif pattern.endswith("/"): diff --git a/cloudfoundry_client/operations/push/file_helper.py b/cloudfoundry_client/operations/push/file_helper.py index d4ac4fd..9f0afaa 100644 --- a/cloudfoundry_client/operations/push/file_helper.py +++ b/cloudfoundry_client/operations/push/file_helper.py @@ -2,7 +2,7 @@ import os import stat import zipfile -from typing import Callable, Generator, Tuple, List +from typing import Callable, Generator, Tuple class FileHelper(object): @@ -32,7 +32,7 @@ def unzip(path: str, tmp_dir: str): zip_ref.extract(entry, tmp_dir) @staticmethod - def walk(path: str) -> Generator[Tuple[str, List[str]], None, None]: + def walk(path: str) -> Generator[Tuple[str, list[str]], None, None]: for dir_path, _, files in os.walk(path, topdown=True): yield dir_path[len(path) :].lstrip("/"), files diff --git a/cloudfoundry_client/operations/push/push.py b/cloudfoundry_client/operations/push/push.py index b7f0f3b..fd95ef0 100644 --- a/cloudfoundry_client/operations/push/push.py +++ b/cloudfoundry_client/operations/push/push.py @@ -5,7 +5,7 @@ import shutil import tempfile import time -from typing import Tuple, List, Dict +from typing import Tuple, Dict from cloudfoundry_client.client import CloudFoundryClient from cloudfoundry_client.operations.push.cf_ignore import CfIgnore @@ -105,7 +105,7 @@ def _merge_environment(app: Entity | None, app_manifest: dict) -> dict: return environment def _route_application( - self, organization: Entity, space: Entity, app: Entity, no_route: bool, routes: List[str], random_route: bool + self, organization: Entity, space: Entity, app: Entity, no_route: bool, routes: list[str], random_route: bool ): existing_routes = [route for route in app.routes()] if no_route: @@ -115,7 +115,7 @@ def _route_application( else: self._build_new_requested_routes(organization, space, app, existing_routes, routes) - def _remove_all_routes(self, app: Entity, routes: List[Entity]): + def _remove_all_routes(self, app: Entity, routes: list[Entity]): for route in routes: self.client.v2.apps.remove_route(app["metadata"]["guid"], route["metadata"]["guid"]) @@ -142,7 +142,7 @@ def _build_default_route(self, space: Entity, app: Entity, random_route: bool): self.client.v2.apps.associate_route(app["metadata"]["guid"], route["metadata"]["guid"]) def _build_new_requested_routes( - self, organization: Entity, space: Entity, app: Entity, existing_routes: List[Entity], requested_routes: List[str] + self, organization: Entity, space: Entity, app: Entity, existing_routes: list[Entity], requested_routes: list[str] ): private_domains = {domain["entity"]["name"]: domain for domain in organization.private_domains()} shared_domains = {domain["entity"]["name"]: domain for domain in self.client.v2.shared_domains.list()} @@ -310,7 +310,7 @@ def _load_all_resources(top_directory: str) -> dict: ) return application_items - def _bind_services(self, space: Entity, app: Entity, services: List[str]): + def _bind_services(self, space: Entity, app: Entity, services: list[str]): service_instances = [ service_instance for service_instance in space.service_instances(return_user_provided_service_instances="true") ] diff --git a/cloudfoundry_client/v2/entities.py b/cloudfoundry_client/v2/entities.py index 0fac7bf..5196dd2 100644 --- a/cloudfoundry_client/v2/entities.py +++ b/cloudfoundry_client/v2/entities.py @@ -1,5 +1,5 @@ from functools import partial, reduce -from typing import Callable, List, Tuple, Any, TYPE_CHECKING +from typing import Callable, Tuple, Any, TYPE_CHECKING from urllib.parse import quote from requests import Response @@ -39,7 +39,7 @@ def __init__(self, target_endpoint: str, client: "CloudFoundryClient", *args, ** raise InvalidEntity(**self) -EntityBuilder = Callable[[List[Tuple[str, Any]]], Entity] +EntityBuilder = Callable[[list[Tuple[str, Any]]], Entity] class EntityManager(object): @@ -141,7 +141,7 @@ def _get_entity_builder(self, entity_builder: EntityBuilder | None) -> EntityBui return entity_builder def _get_url_filtered(self, url: str, **kwargs) -> str: - def _append_encoded_parameter(parameters: List[str], args: Tuple[str, Any]) -> List[str]: + def _append_encoded_parameter(parameters: list[str], args: Tuple[str, Any]) -> list[str]: parameter_name, parameter_value = args[0], args[1] if parameter_name in self.list_query_parameters: parameters.append("%s=%s" % (parameter_name, str(parameter_value))) diff --git a/cloudfoundry_client/v2/resources.py b/cloudfoundry_client/v2/resources.py index d962daa..a7fee10 100644 --- a/cloudfoundry_client/v2/resources.py +++ b/cloudfoundry_client/v2/resources.py @@ -1,4 +1,4 @@ -from typing import List, TYPE_CHECKING +from typing import TYPE_CHECKING from cloudfoundry_client.common_objects import JsonObject @@ -11,6 +11,6 @@ def __init__(self, target_endpoint: str, client: "CloudFoundryClient"): self.target_endpoint = target_endpoint self.client = client - def match(self, items: List[dict]) -> List[JsonObject]: + def match(self, items: list[dict]) -> list[JsonObject]: response = self.client.put("%s/v2/resource_match" % self.client.info.api_endpoint, json=items) return response.json(object_pairs_hook=JsonObject) diff --git a/cloudfoundry_client/v2/service_instances.py b/cloudfoundry_client/v2/service_instances.py index 8d6ebbd..2ac59db 100644 --- a/cloudfoundry_client/v2/service_instances.py +++ b/cloudfoundry_client/v2/service_instances.py @@ -1,4 +1,4 @@ -from typing import List, Dict, TYPE_CHECKING +from typing import Dict, TYPE_CHECKING from cloudfoundry_client.v2.entities import EntityManager, Entity @@ -18,7 +18,7 @@ def create( instance_name: str, plan_guid: str, parameters: dict | None = None, - tags: List[str] = None, + tags: list[str] = None, accepts_incomplete: bool | None = False, ) -> Entity: request = self._request(name=instance_name, space_guid=space_guid, service_plan_guid=plan_guid) @@ -33,7 +33,7 @@ def update( instance_name: str | None = None, plan_guid: str | None = None, parameters: dict | None = None, - tags: List[str] = None, + tags: list[str] = None, accepts_incomplete: bool | None = False, ) -> Entity: request = self._request() diff --git a/cloudfoundry_client/v3/entities.py b/cloudfoundry_client/v3/entities.py index 64f4d64..6c4c55e 100644 --- a/cloudfoundry_client/v3/entities.py +++ b/cloudfoundry_client/v3/entities.py @@ -1,6 +1,6 @@ import functools from json import JSONDecodeError -from typing import Any, List, Tuple, TypeVar, TYPE_CHECKING, Callable, Type +from typing import Any, Tuple, TypeVar, TYPE_CHECKING, Callable, Type from urllib.parse import quote, urlparse from requests import Response @@ -296,7 +296,7 @@ def _entity(self, result: JsonObject, entity_type: ENTITY_TYPE | None) -> JsonOb @staticmethod def _get_url_with_encoded_params(url: str, **kwargs) -> str: - def _append_encoded_parameter(parameters: List[str], args: Tuple[str, Any]) -> List[str]: + def _append_encoded_parameter(parameters: list[str], args: Tuple[str, Any]) -> list[str]: parameter_name, parameter_value = args[0], args[1] if isinstance(parameter_value, (list, tuple)): parameters.append("%s=%s" % (parameter_name, quote(",".join(parameter_value)))) diff --git a/cloudfoundry_client/v3/security_groups.py b/cloudfoundry_client/v3/security_groups.py index 43c32bc..dcbc459 100644 --- a/cloudfoundry_client/v3/security_groups.py +++ b/cloudfoundry_client/v3/security_groups.py @@ -1,6 +1,6 @@ from dataclasses import dataclass, asdict from enum import Enum, auto -from typing import TYPE_CHECKING, List +from typing import TYPE_CHECKING from cloudfoundry_client.v3.entities import EntityManager, ToManyRelationship, Entity, ToOneRelationship @@ -41,7 +41,7 @@ def __init__(self, target_endpoint: str, client: "CloudFoundryClient"): def create(self, name: str, - rules: List[Rule] | None = None, + rules: list[Rule] | None = None, globally_enabled: GloballyEnabled | None = None, staging_spaces: ToManyRelationship | None = None, running_spaces: ToManyRelationship | None = None) -> Entity: @@ -51,7 +51,7 @@ def create(self, def update(self, security_group_id: str, name: str | None = None, - rules: List[Rule] | None = None, + rules: list[Rule] | None = None, globally_enabled: GloballyEnabled | None = None, staging_spaces: ToManyRelationship | None = None, running_spaces: ToManyRelationship | None = None) -> Entity: @@ -91,7 +91,7 @@ def _unbind_space(self, security_group_id: str, space_guid: ToOneRelationship, r @staticmethod def _generate_payload(name: str | None, - rules: List[Rule] | None, + rules: list[Rule] | None, globally_enabled: GloballyEnabled | None, staging_spaces: ToManyRelationship | None, running_spaces: ToManyRelationship | None): diff --git a/cloudfoundry_client/v3/service_instances.py b/cloudfoundry_client/v3/service_instances.py index cfa253f..d882604 100644 --- a/cloudfoundry_client/v3/service_instances.py +++ b/cloudfoundry_client/v3/service_instances.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, List +from typing import TYPE_CHECKING from cloudfoundry_client.common_objects import JsonObject from cloudfoundry_client.v3.entities import Entity, EntityManager, ToOneRelationship @@ -19,7 +19,7 @@ def create( meta_labels: dict | None = None, meta_annotations: dict | None = None, parameters: dict | None = None, - tags: List[str] | None = None, + tags: list[str] | None = None, ) -> Entity: data = { "name": name, @@ -48,7 +48,7 @@ def update( maintenance_info: str | None = None, meta_labels: dict | None = None, meta_annotations: dict | None = None, - tags: List[str] | None = None + tags: list[str] | None = None ) -> Entity: data = {} if name: diff --git a/cloudfoundry_client/v3/service_plans.py b/cloudfoundry_client/v3/service_plans.py index 0534cec..ab28ca5 100644 --- a/cloudfoundry_client/v3/service_plans.py +++ b/cloudfoundry_client/v3/service_plans.py @@ -1,4 +1,4 @@ -from typing import Dict, List, TYPE_CHECKING +from typing import Dict, TYPE_CHECKING from cloudfoundry_client.v3.entities import EntityManager, Entity @@ -32,7 +32,7 @@ def get_visibility(self, service_plan_guid: str) -> Dict: # Updates a service plan visibility. It behaves similar to the POST service plan visibility endpoint but # this endpoint will REPLACE the existing list of organizations when the service plan is organization visible. - def update_visibility(self, service_plan_guid: str, type: str, organizations: List[dict] | None = None) -> Dict: + def update_visibility(self, service_plan_guid: str, type: str, organizations: list[dict] | None = None) -> Dict: payload = {"type": type} if organizations: payload["organizations"] = organizations @@ -42,7 +42,7 @@ def update_visibility(self, service_plan_guid: str, type: str, organizations: Li # Applies a service plan visibility. It behaves similar to the PATCH service plan visibility endpoint but # this endpoint will APPEND to the existing list of organizations when the service plan is organization visible. - def apply_visibility_to_extra_orgs(self, service_plan_guid: str, organizations: List[dict]) -> Dict: + def apply_visibility_to_extra_orgs(self, service_plan_guid: str, organizations: list[dict]) -> Dict: payload = {"type": "organization", "organizations": organizations} return super(ServicePlanManager, self)._post( url=f"{self.target_endpoint}{self.entity_uri}/{service_plan_guid}/visibility", data=payload, files=None diff --git a/tests/v3/test_apps.py b/tests/v3/test_apps.py index 2ce85d2..6039f1b 100644 --- a/tests/v3/test_apps.py +++ b/tests/v3/test_apps.py @@ -1,7 +1,6 @@ import unittest import yaml from http import HTTPStatus -from typing import List from abstract_test_case import AbstractTestCase from cloudfoundry_client.common_objects import JsonObject, Pagination @@ -153,7 +152,7 @@ def test_get_manifest(self): self.assertIsInstance(application_services, list) self.assertEqual(len(application_services), 1) self.assertEqual(application_services[0], "my-service") - application_routes: List[dict | str] | None = application.get("routes") + application_routes: list[dict | str] | None = application.get("routes") self.assertIsInstance(application_routes, list) self.assertEqual(len(application_routes), 1) application_route: dict = application_routes[0]