diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dfcd050 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv/ +.idea/ diff --git a/src/re2-stubs/__init__.pyi b/src/re2-stubs/__init__.pyi index 2915770..c4747da 100644 --- a/src/re2-stubs/__init__.pyi +++ b/src/re2-stubs/__init__.pyi @@ -1,4 +1,4 @@ -from typing import AnyStr, Generic, Iterator, Literal, TypeVar, overload +from typing import AnyStr, Generic, Iterator, Literal, TypeVar, overload, Callable # References: # - https://github.com/google/re2/blob/main/re2/re2.h and @@ -99,7 +99,7 @@ def subn( @overload def sub( pattern: _Regexp[str] | str, - repl: str, + repl: str | Callable[[_Match[str]], str], text: str, count: int = 0, options: Options | None = None, @@ -107,7 +107,7 @@ def sub( @overload def sub( pattern: _Regexp[bytes] | bytes, - repl: bytes, + repl: bytes | Callable[[_Match[bytes]], bytes], text: bytes, count: int = 0, options: Options | None = None, @@ -185,10 +185,18 @@ class _Regexp(Generic[AnyStr]): self: _Regexp[bytes], repl: bytes, text: bytes, count: int = 0 ) -> tuple[bytes, int]: ... @overload - def sub(self: _Regexp[str], repl: str, text: str, count: int = 0) -> str: ... + def sub( + self: _Regexp[str], + repl: str | Callable[[_Match[str]], str], + text: str, + count: int = 0, + ) -> str: ... @overload def sub( - self: _Regexp[bytes], repl: bytes, text: bytes, count: int = 0 + self: _Regexp[bytes], + repl: bytes | Callable[[_Match[bytes]], bytes], + text: bytes, + count: int = 0, ) -> bytes: ... @property def pattern(self) -> AnyStr: ...