Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit

Permalink
Remove deprecated imports from a few more apps (#8696)
Browse files Browse the repository at this point in the history
This is a continuation of #8626.
  • Loading branch information
SpecLad authored Nov 14, 2024
1 parent 6d929fa commit 111feec
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cvat/apps/events/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
7 changes: 4 additions & 3 deletions cvat/apps/iam/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion cvat/apps/iam/rules/tests/generate_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions cvat/apps/iam/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions cvat/apps/iam/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from typing import Tuple
import functools
import hashlib
import importlib
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/lambda_manager/tests/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions cvat/apps/lambda_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 111feec

Please sign in to comment.