Added stub for sre_parse and sre_constants(py3) (#1502)

* Added stub for sre_parse(py3)

* Fixed return type of SubPattern.__getitem__

* Typo

* Fix for issue related to error class

* Added stub for sre_constants(py3)

* Added missing import
This commit is contained in:
Ashwini Chaudhary
2017-08-02 03:08:49 +05:30
committed by Matthias Kramm
parent 01a0c51acf
commit baea852b62
2 changed files with 121 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
# Source: https://github.com/python/cpython/blob/master/Lib/sre_constants.py
from typing import Any, Dict, List, Optional, Union
MAGIC = ... # type: int
class error(Exception):
msg = ... # type: str
pattern = ... # type: Optional[Union[str, bytes]]
pos = ... # type: Optional[int]
lineno = ... # type: int
colno = ... # type: int
def __init__(self, msg: str, pattern: Union[str, bytes] = ..., pos: int = ...) -> None: ...
class _NamedIntConstant(int):
name = ... # type: Any
def __new__(cls, value: int, name: str): ...
MAXREPEAT = ... # type: _NamedIntConstant
OPCODES = ... # type: List[_NamedIntConstant]
ATCODES = ... # type: List[_NamedIntConstant]
CHCODES = ... # type: List[_NamedIntConstant]
OP_IGNORE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant]
AT_MULTILINE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant]
AT_LOCALE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant]
AT_UNICODE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant]
CH_LOCALE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant]
CH_UNICODE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant]
SRE_FLAG_TEMPLATE = ... # type: int
SRE_FLAG_IGNORECASE = ... # type: int
SRE_FLAG_LOCALE = ... # type: int
SRE_FLAG_MULTILINE = ... # type: int
SRE_FLAG_DOTALL = ... # type: int
SRE_FLAG_UNICODE = ... # type: int
SRE_FLAG_VERBOSE = ... # type: int
SRE_FLAG_DEBUG = ... # type: int
SRE_FLAG_ASCII = ... # type: int
SRE_INFO_PREFIX = ... # type: int
SRE_INFO_LITERAL = ... # type: int
SRE_INFO_CHARSET = ... # type: int

81
stdlib/3/sre_parse.pyi Normal file
View File

@@ -0,0 +1,81 @@
# Source: https://github.com/python/cpython/blob/master/Lib/sre_parse.py
from typing import (
Any, Dict, FrozenSet, Iterable, List, Match,
Optional, Pattern as _Pattern, Tuple, Union
)
from sre_constants import _NamedIntConstant as NIC, error as _Error
SPECIAL_CHARS = ... # type: str
REPEAT_CHARS = ... # type: str
DIGITS = ... # type: FrozenSet[str]
OCTDIGITS = ... # type: FrozenSet[str]
HEXDIGITS = ... # type: FrozenSet[str]
ASCIILETTERS = ... # type: FrozenSet[str]
WHITESPACE = ... # type: FrozenSet[str]
ESCAPES = ... # type: Dict[str, Tuple[NIC, int]]
CATEGORIES = ... # type: Dict[str, Union[Tuple[NIC, NIC], Tuple[NIC, List[Tuple[NIC, NIC]]]]]
FLAGS = ... # type: Dict[str, int]
GLOBAL_FLAGS = ... # type: int
class Verbose(Exception): ...
class Pattern:
flags = ... # type: int
groupdict = ... # type: Dict[str, int]
groupwidths = ... # type: List[Optional[int]]
lookbehindgroups = ... # type: Optional[int]
def __init__(self) -> None: ...
@property
def groups(self) -> int: ...
def opengroup(self, name: str = ...) -> int: ...
def closegroup(self, gid: int, p: SubPattern) -> None: ...
def checkgroup(self, gid: int) -> bool: ...
def checklookbehindgroup(self, gid: int, source: Tokenizer) -> None: ...
_OpSubpatternType = Tuple[Optional[int], int, int, SubPattern]
_OpGroupRefExistsType = Tuple[int, SubPattern, SubPattern]
_OpInType = List[Tuple[NIC, int]]
_OpBranchType = Tuple[None, List[SubPattern]]
_AvType = Union[_OpInType, _OpBranchType, Iterable[SubPattern], _OpGroupRefExistsType, _OpSubpatternType]
_CodeType = Tuple[NIC, _AvType]
class SubPattern:
pattern = ... # type: Pattern
data = ... # type: List[_CodeType]
width = ... # type: Optional[int]
def __init__(self, pattern: Pattern, data: List[_CodeType] = ...) -> None: ...
def dump(self, level: int = ...) -> None: ...
def __len__(self) -> int: ...
def __delitem__(self, index: Union[int, slice]) -> None: ...
def __getitem__(self, index: Union[int, slice]) -> Union[SubPattern, _CodeType]: ...
def __setitem__(self, index: Union[int, slice], code: _CodeType) -> None: ...
def insert(self, index: int, code: _CodeType) -> None: ...
def append(self, code: _CodeType) -> None: ...
def getwidth(self) -> int: ...
class Tokenizer:
istext = ... # type: bool
string = ... # type: Any
decoded_string = ... # type: str
index = ... # type: int
next = ... # type: Optional[str]
def __init__(self, string: Any) -> None: ...
def match(self, char: str) -> bool: ...
def get(self) -> Optional[str]: ...
def getwhile(self, n: int, charset: Iterable[str]) -> str: ...
def getuntil(self, terminator: str) -> str: ...
@property
def pos(self) -> int: ...
def tell(self) -> int: ...
def seek(self, index: int) -> None: ...
def error(self, msg: str, offset: int = ...) -> _Error: ...
def fix_flags(src: Union[str, bytes], flag: int) -> int: ...
def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ...
_TemplateType = Tuple[List[Tuple[int, int]], List[str]]
def parse_template(source: str, pattern: _Pattern) -> _TemplateType: ...
def expand_template(template: _TemplateType, match: Match) -> str: ...