More pyugrade to 3.9

This commit is contained in:
Kovid Goyal
2024-08-05 10:59:50 +05:30
parent a35f7e060b
commit 2b3f2258ff
12 changed files with 88 additions and 110 deletions

View File

@@ -9,6 +9,7 @@ import subprocess
import sys
import time
import unittest
from collections.abc import Generator, Iterator, Sequence
from contextlib import contextmanager
from functools import lru_cache
from tempfile import TemporaryDirectory
@@ -16,15 +17,8 @@ from threading import Thread
from typing import (
Any,
Callable,
Dict,
Generator,
Iterator,
List,
NoReturn,
Optional,
Sequence,
Set,
Tuple,
)
from . import BaseTest
@@ -68,7 +62,7 @@ def find_all_tests(package: str = '', excludes: Sequence[str] = ('main', 'gr'))
def filter_tests(suite: unittest.TestSuite, test_ok: Callable[[unittest.TestCase], bool]) -> unittest.TestSuite:
ans = unittest.TestSuite()
added: Set[unittest.TestCase] = set()
added: set[unittest.TestCase] = set()
for test in itertests(suite):
if test_ok(test) and test not in added:
ans.addTest(test)
@@ -124,8 +118,8 @@ def run_cli(suite: unittest.TestSuite, verbosity: int = 4) -> bool:
return result.wasSuccessful()
def find_testable_go_packages() -> Tuple[Set[str], Dict[str, List[str]]]:
test_functions: Dict[str, List[str]] = {}
def find_testable_go_packages() -> tuple[set[str], dict[str, list[str]]]:
test_functions: dict[str, list[str]] = {}
ans = set()
base = os.getcwd()
pat = re.compile(r'^func Test([A-Z]\w+)', re.MULTILINE)
@@ -148,7 +142,7 @@ def go_exe() -> str:
class GoProc(Thread):
def __init__(self, cmd: List[str]):
def __init__(self, cmd: list[str]):
super().__init__(name='GoProc')
from kitty.constants import kitty_exe
env = os.environ.copy()
@@ -182,7 +176,7 @@ class GoProc(Thread):
return self.stdout.decode('utf-8', 'replace'), self.proc.returncode
def run_go(packages: Set[str], names: str) -> GoProc:
def run_go(packages: set[str], names: str) -> GoProc:
go = go_exe()
go_pkg_args = [f'kitty/{x}' for x in packages]
cmd = [go, 'test', '-v']
@@ -193,7 +187,7 @@ def run_go(packages: Set[str], names: str) -> GoProc:
def reduce_go_pkgs(module: str, names: Sequence[str]) -> Set[str]:
def reduce_go_pkgs(module: str, names: Sequence[str]) -> set[str]:
if not go_exe():
raise SystemExit('go executable not found, current path: ' + repr(os.environ.get('PATH', '')))
go_packages, go_functions = find_testable_go_packages()