8000 Update sre_parse module for Python 3.8 by Michael0x2a · Pull Request #3412 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Update sre_parse module for Python 3.8 #3412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update sre_parse module for Python 3.8
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. For example, try taking the diff of:

- https://github.com/python/cpython/blob/3.7/Lib/sre_parse.py
- https://github.com/python/cpython/blob/3.8/Lib/sre_parse.py
  • Loading branch information
Michael0x2a committed Oct 28, 2019
commit 70da38d28d8ee5a454cd966ee1c07161cb86cc15
26 changes: 21 additions & 5 deletions stdlib/3/sre_parse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from typing import (
Any, Dict, FrozenSet, Iterable, List, Match,
Optional, Pattern as _Pattern, Tuple, Union
)
import sys
from sre_constants import _NamedIntConstant as NIC, error as _Error

SPECIAL_CHARS: str
Expand All @@ -20,7 +21,7 @@ GLOBAL_FLAGS: int

class Verbose(Exception): ...

class Pattern:
class _State:
flags: int
groupdict: Dict[str, int]
groupwidths: List[Optional[int]]
Expand All @@ -33,6 +34,11 @@ class Pattern:
def checkgroup(self, gid: int) -> bool: ...
def checklookbehindgroup(self, gid: int, source: Tokenizer) -> None: ...

if sys.version_info >= (3, 8):
State = _State
else:
Pattern = _State


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


class SubPattern:
pattern: Pattern
data: List[_CodeType]
width: Optional[int]
def __init__(self, pattern: Pattern, data: List[_CodeType] = ...) -> None: ...

if sys.version_info >= (3, 8):
state: State
def __init__(self, state: State, data: List[_CodeType] = ...) -> None: ...
else:
pattern: Pattern
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: ...
Expand Down Expand Up @@ -75,7 +87,11 @@ class Tokenizer:
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[Any]) -> _TemplateType: ...
if sys.version_info >= (3, 8):
def parse(str: str, flags: int = ..., state: State = ...) -> SubPattern: ...
def parse_template(source: str, state: _Pattern[Any]) -> _TemplateType: ...
else:
def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ...
def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ...
def expand_template(template: _TemplateType, match: Match[Any]) -> str: ...
0