From 19c437962c0256138f637e52fab064cb2591811a Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 28 Sep 2024 14:21:42 -0400 Subject: [PATCH] require python 3.10+ --- .pre-commit-config.yaml | 4 ++-- babi/buf.py | 6 +++--- babi/fdict.py | 4 ++-- babi/file.py | 8 ++++---- babi/highlight.py | 13 ++++++------- babi/history.py | 2 +- babi/hl/interface.py | 3 +-- babi/hl/replace.py | 2 +- babi/hl/syntax.py | 2 +- babi/linters/pre_commit.py | 5 ++--- babi/main.py | 2 +- babi/perf.py | 2 +- babi/reg.py | 6 +++--- babi/screen.py | 13 +++++-------- babi/textmate_demo.py | 2 +- babi/theme.py | 2 +- setup.cfg | 2 +- 17 files changed, 36 insertions(+), 42 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bca81f8c..5854121f 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 e8e94f47..94ae6f07 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 0e570911..56970d7a 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 01651547..6a688976 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 50d0bcd5..b3c9d049 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 806d7f02..c602fc4b 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 36b4b6db..88edd1f5 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 5f2c3615..773f4558 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 b12fd8ec..f797f5e3 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 380608b4..8c1c0c88 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 a3874120..525cd3cc 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 9bb2d765..c3c8fe29 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 aa68bac5..fd1272d7 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 60b7a38c..ed317f6f 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 8eb696af..e535d468 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 330db7db..bcbe0f12 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 90d25ba0..7edcb30c 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 =