Skip to content

Commit 6a7c201

Browse files
Michael0x2asrittau
authored andcommitted
Update sre_parse module for Python 3.8 (#3412)
It seems in Python 3.8, the 'Pattern' object in the (undocumented?) sre_parse module was renamed to 'State', along with a few associated parameters.
1 parent 72ff7b9 commit 6a7c201

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

stdlib/3/sre_parse.pyi

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from typing import (
44
Any, Dict, FrozenSet, Iterable, List, Match,
55
Optional, Pattern as _Pattern, Tuple, Union
66
)
7+
import sys
78
from sre_constants import _NamedIntConstant as NIC, error as _Error
89

910
SPECIAL_CHARS: str
@@ -20,7 +21,7 @@ GLOBAL_FLAGS: int
2021

2122
class Verbose(Exception): ...
2223

23-
class Pattern:
24+
class _State:
2425
flags: int
2526
groupdict: Dict[str, int]
2627
groupwidths: List[Optional[int]]
@@ -33,6 +34,11 @@ class Pattern:
3334
def checkgroup(self, gid: int) -> bool: ...
3435
def checklookbehindgroup(self, gid: int, source: Tokenizer) -> None: ...
3536

37+
if sys.version_info >= (3, 8):
38+
State = _State
39+
else:
40+
Pattern = _State
41+
3642

3743
_OpSubpatternType = Tuple[Optional[int], int, int, SubPattern]
3844
_OpGroupRefExistsType = Tuple[int, SubPattern, SubPattern]
@@ -43,10 +49,16 @@ _CodeType = Tuple[NIC, _AvType]
4349

4450

4551
class SubPattern:
46-
pattern: Pattern
4752
data: List[_CodeType]
4853
width: Optional[int]
49-
def __init__(self, pattern: Pattern, data: List[_CodeType] = ...) -> None: ...
54+
55+
if sys.version_info >= (3, 8):
56+
state: State
57+
def __init__(self, state: State, data: List[_CodeType] = ...) -> None: ...
58+
else:
59+
pattern: Pattern
60+
def __init__(self, pattern: Pattern, data: List[_CodeType] = ...) -> None: ...
61+
5062
def dump(self, level: int = ...) -> None: ...
5163
def __len__(self) -> int: ...
5264
def __delitem__(self, index: Union[int, slice]) -> None: ...
@@ -75,7 +87,11 @@ class Tokenizer:
7587
def error(self, msg: str, offset: int = ...) -> _Error: ...
7688

7789
def fix_flags(src: Union[str, bytes], flag: int) -> int: ...
78-
def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ...
7990
_TemplateType = Tuple[List[Tuple[int, int]], List[str]]
80-
def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ...
91+
if sys.version_info >= (3, 8):
92+
def parse(str: str, flags: int = ..., state: State = ...) -> SubPattern: ...
93+
def parse_template(source: str, state: _Pattern[Any]) -> _TemplateType: ...
94+
else:
95+
def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ...
96+
def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ...
8197
def expand_template(template: _TemplateType, match: Match[Any]) -> str: ...

0 commit comments

Comments
 (0)