From cebc65945429fde68141743afcb99d97594854b1 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Tue, 12 Nov 2024 20:53:24 +0200 Subject: [PATCH] Remove deprecated imports from a few more apps --- cvat/apps/events/tests/test_events.py | 4 ++-- cvat/apps/iam/permissions.py | 7 ++++--- cvat/apps/iam/rules/tests/generate_tests.py | 3 ++- cvat/apps/iam/serializers.py | 6 +++--- cvat/apps/iam/utils.py | 3 +-- cvat/apps/lambda_manager/tests/test_lambda.py | 4 ++-- cvat/apps/lambda_manager/views.py | 10 +++++----- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/cvat/apps/events/tests/test_events.py b/cvat/apps/events/tests/test_events.py index 990daa1ea325..81b054171dce 100644 --- a/cvat/apps/events/tests/test_events.py +++ b/cvat/apps/events/tests/test_events.py @@ -5,7 +5,7 @@ import json import unittest from datetime import datetime, timedelta, timezone -from typing import List, Optional +from typing import Optional from django.contrib.auth import get_user_model from django.test import RequestFactory @@ -42,7 +42,7 @@ def _working_time(event: dict) -> int: return payload["working_time"] @staticmethod - def _deserialize(events: List[dict], previous_event: Optional[dict] = None) -> List[dict]: + def _deserialize(events: list[dict], previous_event: Optional[dict] = None) -> list[dict]: request = RequestFactory().post("/api/events") request.user = get_user_model()(id=100, username="testuser", email="testuser@example.org") request.iam_context = { diff --git a/cvat/apps/iam/permissions.py b/cvat/apps/iam/permissions.py index bb2ab44a414f..d4925426724a 100644 --- a/cvat/apps/iam/permissions.py +++ b/cvat/apps/iam/permissions.py @@ -8,9 +8,10 @@ import importlib import operator from abc import ABCMeta, abstractmethod +from collections.abc import Sequence from enum import Enum from pathlib import Path -from typing import Any, Dict, List, Optional, Sequence, TypeVar +from typing import Any, Optional, TypeVar from attrs import define, field from django.apps import AppConfig @@ -33,7 +34,7 @@ def __str__(self) -> str: @define class PermissionResult: allow: bool - reasons: List[str] = field(factory=list) + reasons: list[str] = field(factory=list) def get_organization(request, obj): @@ -83,7 +84,7 @@ def build_iam_context(request, organization: Optional[Organization], membership: } -def get_iam_context(request, obj) -> Dict[str, Any]: +def get_iam_context(request, obj) -> dict[str, Any]: organization = get_organization(request, obj) membership = get_membership(request, organization) diff --git a/cvat/apps/iam/rules/tests/generate_tests.py b/cvat/apps/iam/rules/tests/generate_tests.py index 254930e73d61..729de6732eb2 100755 --- a/cvat/apps/iam/rules/tests/generate_tests.py +++ b/cvat/apps/iam/rules/tests/generate_tests.py @@ -7,9 +7,10 @@ import subprocess import sys from argparse import ArgumentParser, Namespace +from collections.abc import Sequence from concurrent.futures import ThreadPoolExecutor from functools import partial -from typing import Optional, Sequence +from typing import Optional from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[5] diff --git a/cvat/apps/iam/serializers.py b/cvat/apps/iam/serializers.py index 862712454de0..967b696a4f21 100644 --- a/cvat/apps/iam/serializers.py +++ b/cvat/apps/iam/serializers.py @@ -19,7 +19,7 @@ from django.contrib.auth.models import User from drf_spectacular.utils import extend_schema_field -from typing import Optional, Union, Dict +from typing import Optional, Union from cvat.apps.iam.forms import ResetPasswordFormEx from cvat.apps.iam.utils import get_dummy_user @@ -32,11 +32,11 @@ class RegisterSerializerEx(RegisterSerializer): key = serializers.SerializerMethodField() @extend_schema_field(serializers.BooleanField) - def get_email_verification_required(self, obj: Union[Dict, User]) -> bool: + def get_email_verification_required(self, obj: Union[dict, User]) -> bool: return allauth_settings.EMAIL_VERIFICATION == allauth_settings.EmailVerificationMethod.MANDATORY @extend_schema_field(serializers.CharField(allow_null=True)) - def get_key(self, obj: Union[Dict, User]) -> Optional[str]: + def get_key(self, obj: Union[dict, User]) -> Optional[str]: key = None if isinstance(obj, User) and allauth_settings.EMAIL_VERIFICATION != \ allauth_settings.EmailVerificationMethod.MANDATORY: diff --git a/cvat/apps/iam/utils.py b/cvat/apps/iam/utils.py index a13de3367336..8095902769f3 100644 --- a/cvat/apps/iam/utils.py +++ b/cvat/apps/iam/utils.py @@ -1,5 +1,4 @@ from pathlib import Path -from typing import Tuple import functools import hashlib import importlib @@ -14,7 +13,7 @@ } @functools.lru_cache(maxsize=None) -def get_opa_bundle() -> Tuple[bytes, str]: +def get_opa_bundle() -> tuple[bytes, str]: bundle_file = io.BytesIO() with tarfile.open(fileobj=bundle_file, mode='w:gz') as tar: diff --git a/cvat/apps/lambda_manager/tests/test_lambda.py b/cvat/apps/lambda_manager/tests/test_lambda.py index 8fe9c1f42c06..f9292b278b45 100644 --- a/cvat/apps/lambda_manager/tests/test_lambda.py +++ b/cvat/apps/lambda_manager/tests/test_lambda.py @@ -5,7 +5,7 @@ from collections import Counter, OrderedDict from itertools import groupby -from typing import Dict, Optional +from typing import Optional from unittest import mock, skip import json import os @@ -1440,7 +1440,7 @@ class Issue4996_Cases(_LambdaTestCaseBase): # We need to check that job assignee can call functions in the assigned jobs # This requires to pass the job id in the call request. - def _create_org(self, *, owner: int, members: Dict[int, str] = None) -> dict: + def _create_org(self, *, owner: int, members: dict[int, str] = None) -> dict: org = self._post_request('/api/organizations', user=owner, data={ "slug": "testorg", "name": "test Org", diff --git a/cvat/apps/lambda_manager/views.py b/cvat/apps/lambda_manager/views.py index b7e10fc729e9..c5401792c354 100644 --- a/cvat/apps/lambda_manager/views.py +++ b/cvat/apps/lambda_manager/views.py @@ -12,7 +12,7 @@ from copy import deepcopy from datetime import timedelta from functools import wraps -from typing import Any, Dict, Optional +from typing import Any, Optional import datumaro.util.mask_tools as mask_tools import django_rq @@ -231,7 +231,7 @@ def to_dict(self): def invoke( self, db_task: Task, - data: Dict[str, Any], + data: dict[str, Any], *, db_job: Optional[Job] = None, is_interactive: Optional[bool] = False, @@ -262,7 +262,7 @@ def mandatory_arg(name: str) -> Any: model_labels = self.labels task_labels = db_task.get_labels(prefetch=True) - def labels_compatible(model_label: Dict, task_label: Label) -> bool: + def labels_compatible(model_label: dict, task_label: Label) -> bool: model_type = model_label['type'] db_type = task_label.type compatible_types = [[ShapeType.MASK, ShapeType.POLYGON]] @@ -654,9 +654,9 @@ def _call_detector( cls, function: LambdaFunction, db_task: Task, - labels: Dict[str, Dict[str, Any]], + labels: dict[str, dict[str, Any]], threshold: float, - mapping: Optional[Dict[str, str]], + mapping: Optional[dict[str, str]], conv_mask_to_poly: bool, *, db_job: Optional[Job] = None