import sys
import struct
from abc import ABC, abstractmethod
-from typing import Any, Generic, Match, Sequence, TYPE_CHECKING
+from typing import Any, Generic, TYPE_CHECKING
+from collections.abc import Sequence
from . import pq
from . import adapt
}
-def _dump_sub(m: Match[bytes], __map: dict[bytes, bytes] = _dump_repl) -> bytes:
+def _dump_sub(m: re.Match[bytes], __map: dict[bytes, bytes] = _dump_repl) -> bytes:
return __map[m.group(0)]
_load_repl = {v: k for k, v in _dump_repl.items()}
-def _load_sub(m: Match[bytes], __map: dict[bytes, bytes] = _load_repl) -> bytes:
+def _load_sub(m: re.Match[bytes], __map: dict[bytes, bytes] = _load_repl) -> bytes:
return __map[m.group(0)]
from __future__ import annotations
import re
-from typing import Any, Callable, Mapping, Match, NamedTuple
-from typing import Sequence, TYPE_CHECKING
+from typing import Any, Callable, NamedTuple, TYPE_CHECKING
+from collections.abc import Mapping, Sequence
from functools import lru_cache
from . import pq
def _split_query(
query: bytes, encoding: str = "ascii", collapse_double_percent: bool = True
) -> list[QueryPart]:
- parts: list[tuple[bytes, Match[bytes] | None]] = []
+ parts: list[tuple[bytes, re.Match[bytes] | None]] = []
cur = 0
# pairs [(fragment, match], with the last match None
import re
import struct
from math import prod
-from typing import Any, cast, Callable, Pattern
+from typing import Any, cast, Callable
from .. import pq
from .. import errors as e
@cache
-def _get_needs_quotes_regexp(delimiter: bytes) -> Pattern[bytes]:
+def _get_needs_quotes_regexp(delimiter: bytes) -> re.Pattern[bytes]:
"""Return a regexp to recognise when a value needs quotes
from https://www.postgresql.org/docs/current/arrays.html#ARRAYS-IO
data: Buffer,
loader: Loader,
delimiter: bytes = b",",
- __re_unescape: Pattern[bytes] = re.compile(rb"\\(.)"),
+ __re_unescape: re.Pattern[bytes] = re.compile(rb"\\(.)"),
) -> list[Any]:
rv = None
stack: list[Any] = []
@cache
-def _get_array_parse_regexp(delimiter: bytes) -> Pattern[bytes]:
+def _get_array_parse_regexp(delimiter: bytes) -> re.Pattern[bytes]:
"""
Return a regexp to tokenize an array representation into item and brackets
"""
from __future__ import annotations
import re
-from typing import Any, Match
+from typing import Any
import pytest
import psycopg
n = 1
- def s(m: Match[str]) -> str:
+ def s(m: re.Match[str]) -> str:
nonlocal n
rv = f"${n}"
n += 1