# based on: https://github.com/python/typeshed/blob/master/stdlib/3/re.pyi

from re import RegexFlag
from typing import (
    List, Iterator, overload, Callable, Tuple,
    Match, Pattern, Any, Optional, Union
)

_FlagsType = Union[int, RegexFlag]
_Str = Union[bytes, memoryview]

class _RevPattern:
    def search(self, string: _Str, pos: int = ..., endpos: int = ...) -> Optional[Match[bytes]]: ...
    def match(self, string: _Str, pos: int = ..., endpos: int = ...) -> Optional[Match[bytes]]: ...
    def fullmatch(self, string: _Str, pos: int = ..., endpos: int = ...) -> Optional[Match[bytes]]: ...
    def split(self, string: _Str, maxsplit: int = ...) -> List[bytes]: ...
    def findall(self, string: _Str, pos: int = ..., endpos: int = ...) -> List[Any]: ...
    def finditer(self, string: _Str, pos: int = ..., endpos: int = ...) -> Iterator[Match[bytes]]: ...
    @overload
    def sub(self, repl: bytes, string: _Str, count: int = ...) -> bytes: ...
    @overload
    def sub(self, repl: Callable[[Match[bytes]], bytes], string: _Str, count: int = ...) -> bytes: ...
    @overload
    def subn(self, repl: bytes, string: _Str, count: int = ...) -> Tuple[bytes, int]: ...
    @overload
    def subn(self, repl: Callable[[Match[bytes]], bytes], string: _Str, count: int = ...) -> Tuple[bytes, int]: ...

@overload
def compile(pattern: bytes, flags: _FlagsType = ...) -> _RevPattern: ...
@overload
def compile(pattern: Pattern[bytes], flags: _FlagsType = ...) -> _RevPattern: ...
