Skip to content

Commit

Permalink
Merge pull request #355 from asottile/310-plus
Browse files Browse the repository at this point in the history
require python 3.10+
  • Loading branch information
asottile authored Sep 28, 2024
2 parents f397186 + 93a508c commit c10759c
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]'
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions babi/buf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions babi/fdict.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions babi/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions babi/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: type[T]) -> type[T]:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion babi/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions babi/hl/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing import NamedTuple
from typing import Protocol
from typing import Tuple

from babi.buf import Buf

Expand All @@ -13,7 +12,7 @@ class HL(NamedTuple):
attr: int


HLs = Tuple[HL, ...]
HLs = tuple[HL, ...]


class RegionsMapping(Protocol):
Expand Down
2 changes: 1 addition & 1 deletion babi/hl/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion babi/hl/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions babi/linters/pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: (.*)$')

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion babi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion babi/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import contextlib
import cProfile
import time
from typing import Generator
from collections.abc import Generator


class Perf:
Expand Down
6 changes: 3 additions & 3 deletions babi/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import functools
import re
from typing import Match
from re import Match

import onigurumacffi

Expand Down Expand Up @@ -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('$ ^')
13 changes: 5 additions & 8 deletions babi/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion babi/textmate_demo.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion babi/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit c10759c

Please sign in to comment.