From de353cab4cef918585475d67094b57ab8171c5ac Mon Sep 17 00:00:00 2001 From: Valentin Rigal Date: Thu, 3 Oct 2024 15:20:15 +0200 Subject: [PATCH] Fix linters deprecation errors --- .../perf/auto_sheriffing_criteria/test_common_behaviour.py | 2 +- treeherder/etl/perf.py | 3 +-- treeherder/perf/auto_perf_sheriffing/backfill_reports.py | 3 +-- treeherder/perf/auto_perf_sheriffing/backfill_tool.py | 3 +-- treeherder/perf/email.py | 6 ++---- treeherder/perf/models.py | 7 +++---- treeherder/perf/sheriffing_criteria/criteria_tracking.py | 5 ++--- 7 files changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/perf/auto_sheriffing_criteria/test_common_behaviour.py b/tests/perf/auto_sheriffing_criteria/test_common_behaviour.py index 455374c4d68..65520dbfd58 100644 --- a/tests/perf/auto_sheriffing_criteria/test_common_behaviour.py +++ b/tests/perf/auto_sheriffing_criteria/test_common_behaviour.py @@ -2,7 +2,7 @@ import pytest from django.conf import settings -from typing import Callable +from collections.abc import Callable from tests.perf.auto_sheriffing_criteria.conftest import CASSETTES_RECORDING_DATE from treeherder.config.settings import BZ_DATETIME_FORMAT diff --git a/treeherder/etl/perf.py b/treeherder/etl/perf.py index fef40e2a309..8cb3cfb045d 100644 --- a/treeherder/etl/perf.py +++ b/treeherder/etl/perf.py @@ -2,7 +2,6 @@ import logging from datetime import datetime from hashlib import sha1 -from typing import Optional import simplejson as json @@ -119,7 +118,7 @@ def _test_should_alert_based_on( def _test_should_gather_replicates_based_on( - repository: Repository, suite_name: str, replicates: Optional[list] = None + repository: Repository, suite_name: str, replicates: list | None ) -> bool: """ Determine if we should gather/ingest replicates. Currently, it's diff --git a/treeherder/perf/auto_perf_sheriffing/backfill_reports.py b/treeherder/perf/auto_perf_sheriffing/backfill_reports.py index f6e6751812f..2887c250456 100644 --- a/treeherder/perf/auto_perf_sheriffing/backfill_reports.py +++ b/treeherder/perf/auto_perf_sheriffing/backfill_reports.py @@ -1,7 +1,6 @@ import logging from datetime import timedelta, datetime from itertools import zip_longest, groupby -from typing import Optional import simplejson as json from django.db.models import QuerySet, Q, F @@ -87,7 +86,7 @@ def initial_culprit_job(alert): def parent_or_sibling_from( alert_group: list[PerformanceAlert], - ) -> Optional[PerformanceAlert]: + ) -> PerformanceAlert | None: if len(alert_group) == 0: return None diff --git a/treeherder/perf/auto_perf_sheriffing/backfill_tool.py b/treeherder/perf/auto_perf_sheriffing/backfill_tool.py index 34f1d724721..86d391da401 100644 --- a/treeherder/perf/auto_perf_sheriffing/backfill_tool.py +++ b/treeherder/perf/auto_perf_sheriffing/backfill_tool.py @@ -1,7 +1,6 @@ import logging from django.core.exceptions import ObjectDoesNotExist -from typing import Union from treeherder.model.models import Job from treeherder.perf.exceptions import CannotBackfillError @@ -14,7 +13,7 @@ class BackfillTool: def __init__(self, taskcluster_model: TaskclusterModel): self.__taskcluster = taskcluster_model - def backfill_job(self, job: Union[Job, str]) -> str: + def backfill_job(self, job: Job | str) -> str: if not isinstance(job, Job): job = self._fetch_job_by_id(job) diff --git a/treeherder/perf/email.py b/treeherder/perf/email.py index cd41f53bc3e..3229be568be 100644 --- a/treeherder/perf/email.py +++ b/treeherder/perf/email.py @@ -11,8 +11,6 @@ from abc import ABC, abstractmethod import urllib.parse -from typing import Union, Optional - from django.conf import settings from treeherder.perf.models import ( BackfillRecord, @@ -40,7 +38,7 @@ class EmailWriter(ABC): def __init__(self): self._email = Email() - def prepare_new_email(self, must_mention: Union[list[object], object]) -> dict: + def prepare_new_email(self, must_mention: list[object] | object) -> dict: """ Template method """ @@ -192,7 +190,7 @@ def __build_push_range_cell_text(alert: PerformanceAlert) -> str: return f"{repository_name}:{previous_push}:{push}" @staticmethod - def __escape_markdown(text: str) -> Optional[str]: + def __escape_markdown(text: str) -> str | None: """ Mostly copied "Example 2" from https://www.programcreek.com/python/?CodeExample=escape+markdown """ diff --git a/treeherder/perf/models.py b/treeherder/perf/models.py index eda4bfe1d13..a176c5aa6d7 100644 --- a/treeherder/perf/models.py +++ b/treeherder/perf/models.py @@ -1,7 +1,6 @@ import logging from datetime import datetime import json -from typing import Optional from functools import reduce from django.contrib.auth.models import User @@ -521,7 +520,7 @@ class PerformanceAlert(models.Model): manually_created = models.BooleanField(default=False) @property - def initial_culprit_job(self) -> Optional[Job]: + def initial_culprit_job(self) -> Job | None: if hasattr(self, "__initial_culprit_job"): return self.__initial_culprit_job @@ -720,7 +719,7 @@ def platform(self) -> MachinePlatform: return self.alert.series_signature.platform @property - def job_symbol(self) -> Optional[str]: + def job_symbol(self) -> str | None: if not all([self.job_tier, self.job_group, self.job_type]): return None @@ -845,7 +844,7 @@ class Meta: db_table = "performance_settings" -def deepgetattr(obj: object, attr_chain: str) -> Optional[object]: +def deepgetattr(obj: object, attr_chain: str) -> object | None: """Recursively follow an attribute chain to get the final value. @param attr_chain: e.g. 'repository.name', 'job_type', 'record.platform.architecture' etc diff --git a/treeherder/perf/sheriffing_criteria/criteria_tracking.py b/treeherder/perf/sheriffing_criteria/criteria_tracking.py index 79ca745c94d..043c7cde210 100644 --- a/treeherder/perf/sheriffing_criteria/criteria_tracking.py +++ b/treeherder/perf/sheriffing_criteria/criteria_tracking.py @@ -4,7 +4,6 @@ from multiprocessing import cpu_count from multiprocessing.pool import Pool, ThreadPool, AsyncResult import time -from typing import Union from datetime import datetime, timedelta @@ -22,8 +21,8 @@ class CriteriaRecord: Framework: str Suite: str Test: str - EngineerTraction: Union[float, str] - FixRatio: Union[float, str] + EngineerTraction: float | str + FixRatio: float | str TotalAlerts: int LastUpdatedOn: datetime AllowSync: bool