diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 950061f..b803056 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,6 +8,6 @@ on: jobs: main: - uses: asottile/workflows/.github/workflows/tox.yml@v1.5.0 + uses: asottile/workflows/.github/workflows/tox.yml@v1.6.1 with: - env: '["py38", "py39", "py310"]' + env: '["py310", "py311", "py312"]' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bca81f8..5854121 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: rev: v3.13.0 hooks: - id: reorder-python-imports - args: [--py38-plus, --add-import, 'from __future__ import annotations'] + args: [--py310-plus, --add-import, 'from __future__ import annotations'] - repo: https://github.com/asottile/add-trailing-comma rev: v3.1.0 hooks: @@ -26,7 +26,7 @@ repos: rev: v3.17.0 hooks: - id: pyupgrade - args: [--py38-plus] + args: [--py310-plus] - repo: https://github.com/hhatto/autopep8 rev: v2.3.1 hooks: diff --git a/babi/buf.py b/babi/buf.py index e8e94f4..94ae6f0 100644 --- a/babi/buf.py +++ b/babi/buf.py @@ -3,9 +3,9 @@ import bisect import contextlib import difflib -from typing import Callable -from typing import Generator -from typing import Iterator +from collections.abc import Callable +from collections.abc import Generator +from collections.abc import Iterator from typing import NamedTuple from typing import Protocol diff --git a/babi/fdict.py b/babi/fdict.py index 0e57091..56970d7 100644 --- a/babi/fdict.py +++ b/babi/fdict.py @@ -1,8 +1,8 @@ from __future__ import annotations +from collections.abc import Iterable +from collections.abc import Mapping from typing import Generic -from typing import Iterable -from typing import Mapping from typing import Protocol from typing import TypeVar diff --git a/babi/file.py b/babi/file.py index 0165154..6a68897 100644 --- a/babi/file.py +++ b/babi/file.py @@ -9,15 +9,15 @@ import itertools import os.path import re +from collections.abc import Callable +from collections.abc import Generator +from re import Match +from re import Pattern from typing import Any -from typing import Callable from typing import cast -from typing import Generator from typing import IO from typing import Literal -from typing import Match from typing import NamedTuple -from typing import Pattern from typing import TYPE_CHECKING from typing import TypedDict from typing import TypeVar diff --git a/babi/highlight.py b/babi/highlight.py index 50d0bcd..b3c9d04 100644 --- a/babi/highlight.py +++ b/babi/highlight.py @@ -3,11 +3,10 @@ import functools import json import os.path +from re import Match from typing import Any -from typing import Match from typing import NamedTuple from typing import Protocol -from typing import Tuple from typing import TypeVar from identify.identify import tags_from_filename @@ -22,9 +21,9 @@ from babi.reg import make_regset T = TypeVar('T') -Scope = Tuple[str, ...] -Regions = Tuple['Region', ...] -Captures = Tuple[Tuple[int, 'Rule'], ...] +Scope = tuple[str, ...] +Regions = tuple['Region', ...] +Captures = tuple[tuple[int, 'Rule'], ...] def uniquely_constructed(t: T) -> T: @@ -518,8 +517,8 @@ def search( class Compiler: def __init__(self, grammar: Grammar, grammars: Grammars) -> None: - self._include = functools.lru_cache(maxsize=None)(self._include_) - self._patterns = functools.lru_cache(maxsize=None)(self._patterns_) + self._include = functools.cache(self._include_) + self._patterns = functools.cache(self._patterns_) self.root_scope = grammar.scope_name self._grammars = grammars diff --git a/babi/history.py b/babi/history.py index 806d7f0..c602fc4 100644 --- a/babi/history.py +++ b/babi/history.py @@ -3,7 +3,7 @@ import collections import contextlib import os.path -from typing import Generator +from collections.abc import Generator from babi.user_data import xdg_data diff --git a/babi/hl/interface.py b/babi/hl/interface.py index 36b4b6d..88edd1f 100644 --- a/babi/hl/interface.py +++ b/babi/hl/interface.py @@ -2,7 +2,6 @@ from typing import NamedTuple from typing import Protocol -from typing import Tuple from babi.buf import Buf @@ -13,7 +12,7 @@ class HL(NamedTuple): attr: int -HLs = Tuple[HL, ...] +HLs = tuple[HL, ...] class RegionsMapping(Protocol): diff --git a/babi/hl/replace.py b/babi/hl/replace.py index 5f2c361..773f455 100644 --- a/babi/hl/replace.py +++ b/babi/hl/replace.py @@ -3,7 +3,7 @@ import collections import contextlib import curses -from typing import Generator +from collections.abc import Generator from babi.buf import Buf from babi.hl.interface import HL diff --git a/babi/hl/syntax.py b/babi/hl/syntax.py index b12fd8e..f797f5e 100644 --- a/babi/hl/syntax.py +++ b/babi/hl/syntax.py @@ -3,7 +3,7 @@ import curses import functools import math -from typing import Callable +from collections.abc import Callable from typing import NamedTuple from babi.buf import Buf diff --git a/babi/linters/pre_commit.py b/babi/linters/pre_commit.py index 380608b..8c1c0c8 100644 --- a/babi/linters/pre_commit.py +++ b/babi/linters/pre_commit.py @@ -4,11 +4,10 @@ import os.path import re import subprocess -from typing import Tuple from babi import linting -ErrorsByHook = Tuple[Tuple[str, Tuple[linting.Error, ...]], ...] +ErrorsByHook = tuple[tuple[str, tuple[linting.Error, ...]], ...] HOOK_ID_RE = re.compile('^- hook id: (.*)$') @@ -44,7 +43,7 @@ def _push_current_hook_id() -> None: class PreCommit: def __init__(self) -> None: - self._root = functools.lru_cache(maxsize=None)(self._root_uncached) + self._root = functools.cache(self._root_uncached) def _root_uncached(self, filename: str) -> str: return subprocess.check_output( diff --git a/babi/main.py b/babi/main.py index a387412..525cd3c 100644 --- a/babi/main.py +++ b/babi/main.py @@ -6,7 +6,7 @@ import re import signal import sys -from typing import Sequence +from collections.abc import Sequence from babi.buf import Buf from babi.file import File diff --git a/babi/perf.py b/babi/perf.py index 9bb2d76..c3c8fe2 100644 --- a/babi/perf.py +++ b/babi/perf.py @@ -3,7 +3,7 @@ import contextlib import cProfile import time -from typing import Generator +from collections.abc import Generator class Perf: diff --git a/babi/reg.py b/babi/reg.py index aa68bac..fd1272d 100644 --- a/babi/reg.py +++ b/babi/reg.py @@ -2,7 +2,7 @@ import functools import re -from typing import Match +from re import Match import onigurumacffi @@ -78,6 +78,6 @@ def expand_escaped(match: Match[str], s: str) -> str: return _BACKREF_RE.sub(lambda m: f'{m[1]}{re.escape(match[int(m[2])])}', s) -make_reg = functools.lru_cache(maxsize=None)(_Reg) -make_regset = functools.lru_cache(maxsize=None)(_RegSet) +make_reg = functools.cache(_Reg) +make_regset = functools.cache(_RegSet) ERR_REG = make_reg('$ ^') diff --git a/babi/screen.py b/babi/screen.py index 60b7a38..ed317f6 100644 --- a/babi/screen.py +++ b/babi/screen.py @@ -11,11 +11,11 @@ import sre_parse import subprocess import sys +from collections.abc import Callable +from collections.abc import Generator +from re import Pattern from types import FrameType -from typing import Callable -from typing import Generator from typing import NamedTuple -from typing import Pattern from babi import linting from babi.color_manager import ColorManager @@ -856,12 +856,9 @@ def sigusr1_handler(signum: int, frame: FrameType | None) -> None: def _init_screen() -> curses._CursesWindow: # set the escape delay so curses does not pause waiting for sequences - if ( - sys.version_info >= (3, 9) and - hasattr(curses, 'set_escdelay') - ): # pragma: >=3.9 cover + if hasattr(curses, 'set_escdelay'): curses.set_escdelay(25) - else: # pragma: <3.9 cover + else: # pragma: no cover # specific ncurses versions os.environ.setdefault('ESCDELAY', '25') stdscr = curses.initscr() diff --git a/babi/textmate_demo.py b/babi/textmate_demo.py index 8eb696a..e535d46 100644 --- a/babi/textmate_demo.py +++ b/babi/textmate_demo.py @@ -1,7 +1,7 @@ from __future__ import annotations import argparse -from typing import Sequence +from collections.abc import Sequence from babi.highlight import Compiler from babi.highlight import Grammars diff --git a/babi/theme.py b/babi/theme.py index 330db7d..bcbe0f1 100644 --- a/babi/theme.py +++ b/babi/theme.py @@ -81,7 +81,7 @@ class Theme: def __init__(self, default: Style, rules: TrieNode) -> None: self.default = default self.rules = rules - self.select = functools.lru_cache(maxsize=None)(self._select) + self.select = functools.cache(self._select) def _select(self, scope: tuple[str, ...]) -> Style: if not scope: diff --git a/setup.cfg b/setup.cfg index 90d25ba..7edcb30 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,7 +25,7 @@ install_requires = identify onigurumacffi>=0.0.18 windows-curses!=2.3.1;sys_platform=="win32" -python_requires = >=3.8 +python_requires = >=3.10 [options.packages.find] exclude =