From 66e451e81fb0222431c05c70ac5ae988735ac937 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 19 Oct 2024 19:27:01 +0200 Subject: [PATCH 1/2] pre-commit: Migrate pyupgrade to Python >=3.9 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 242efbc..3e9f4f0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: rev: v3.18.0 hooks: - id: pyupgrade - args: ['--py38-plus'] + args: ['--py39-plus'] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 From 718bb6b3056900ba5b6fd9d6ec896ed1725036b3 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 19 Oct 2024 19:28:22 +0200 Subject: [PATCH 2/2] Migrate type annotations to Python >=3.9 --- binary_gentoo/internal/cli/tests/test_build.py | 5 ++--- binary_gentoo/internal/cli/tests/test_clean.py | 3 +-- binary_gentoo/internal/cli/tests/test_tree_sync.py | 3 +-- binary_gentoo/internal/cli/tree_diff.py | 7 +++---- binary_gentoo/internal/priority_queue.py | 5 ++--- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/binary_gentoo/internal/cli/tests/test_build.py b/binary_gentoo/internal/cli/tests/test_build.py index eaaf4ca..56e0896 100644 --- a/binary_gentoo/internal/cli/tests/test_build.py +++ b/binary_gentoo/internal/cli/tests/test_build.py @@ -5,7 +5,6 @@ from io import StringIO from tempfile import TemporaryDirectory from textwrap import dedent -from typing import List from unittest import TestCase from unittest.mock import call, patch @@ -17,7 +16,7 @@ @dataclass class RunRecord: - call_args_list: List["call"] + call_args_list: list["call"] class ClassifyEmergeTargetTest(TestCase): @@ -86,7 +85,7 @@ def test_portagq_interaction(self): class MainTest(TestCase): @staticmethod - def _run_gentoo_build_with_subprocess_mocked(argv_extra: List[str] = None) -> RunRecord: + def _run_gentoo_build_with_subprocess_mocked(argv_extra: list[str] = None) -> RunRecord: if argv_extra is None: argv_extra = [] diff --git a/binary_gentoo/internal/cli/tests/test_clean.py b/binary_gentoo/internal/cli/tests/test_clean.py index 16c7bb5..4fd5500 100644 --- a/binary_gentoo/internal/cli/tests/test_clean.py +++ b/binary_gentoo/internal/cli/tests/test_clean.py @@ -5,7 +5,6 @@ from io import StringIO from itertools import product from tempfile import TemporaryDirectory -from typing import List from unittest import TestCase from unittest.mock import call, patch @@ -19,7 +18,7 @@ class RunRecord: temp_distdir: str temp_pkgdir: str temp_portdir: str - call_args_list: List["call"] + call_args_list: list["call"] class MainTest(TestCase): diff --git a/binary_gentoo/internal/cli/tests/test_tree_sync.py b/binary_gentoo/internal/cli/tests/test_tree_sync.py index b3ca23a..7655a70 100644 --- a/binary_gentoo/internal/cli/tests/test_tree_sync.py +++ b/binary_gentoo/internal/cli/tests/test_tree_sync.py @@ -5,7 +5,6 @@ from io import StringIO from subprocess import call from tempfile import TemporaryDirectory -from typing import List from unittest import TestCase from unittest.mock import patch @@ -16,7 +15,7 @@ @dataclass class RunRecord: - call_args_list: List["call"] + call_args_list: list["call"] class MainTest(TestCase): diff --git a/binary_gentoo/internal/cli/tree_diff.py b/binary_gentoo/internal/cli/tree_diff.py index 076251f..dd2ddfa 100644 --- a/binary_gentoo/internal/cli/tree_diff.py +++ b/binary_gentoo/internal/cli/tree_diff.py @@ -6,7 +6,6 @@ import re import sys from argparse import ArgumentParser -from typing import Set from ..reporter import announce_and_check_output, exception_reporting from ._distro import HOST_IS_GENTOO @@ -16,8 +15,8 @@ _filename_9999_pattern = re.compile(r'9999(-r[0-9]+)?\.ebuild$') -def _replace_special_keywords_for_ebuild(accept_keywords: Set[str], - ebuild_keywords: Set[str]) -> Set[str]: +def _replace_special_keywords_for_ebuild(accept_keywords: set[str], + ebuild_keywords: set[str]) -> set[str]: effective_keywords = set(accept_keywords) if '**' in effective_keywords: effective_keywords.remove('**') @@ -31,7 +30,7 @@ def _replace_special_keywords_for_ebuild(accept_keywords: Set[str], return effective_keywords -def _get_relevant_keywords_set_for(ebuild_filepath: str, accept_keywords: Set[str]) -> Set[str]: +def _get_relevant_keywords_set_for(ebuild_filepath: str, accept_keywords: set[str]) -> set[str]: with open(ebuild_filepath) as ifile: ebuild_content = ifile.read() diff --git a/binary_gentoo/internal/priority_queue.py b/binary_gentoo/internal/priority_queue.py index 5137178..85e9686 100644 --- a/binary_gentoo/internal/priority_queue.py +++ b/binary_gentoo/internal/priority_queue.py @@ -5,7 +5,6 @@ import json import os from contextlib import suppress -from typing import List, Set from .json_formatter import dump_json_for_humans @@ -22,7 +21,7 @@ def _push_to_min_heap(self, prority: float, atom: str): heapq.heappush(self._min_heap, item) self._push_count += 1 - def _remove_from_min_heap(self, atoms: Set[str]) -> Set[str]: + def _remove_from_min_heap(self, atoms: set[str]) -> set[str]: items = [] removed_atoms = set() @@ -52,7 +51,7 @@ def push(self, priority: float, atom: str): self._priority_of[atom] = priority self._push_to_min_heap(priority, atom) - def drop(self, atoms: List[str]): + def drop(self, atoms: list[str]): for atom in atoms: if atom not in self._priority_of: raise IndexError(f'Atom {atom!r} not currently in the queue')