Skip to content

re: 3.11 fixes #7859

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 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 9 additions & 6 deletions stdlib/re.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ if sys.version_info >= (3, 11):
"finditer",
"compile",
"purge",
"template",
"escape",
"error",
"Pattern",
Expand Down Expand Up @@ -126,8 +125,9 @@ class RegexFlag(enum.IntFlag):
VERBOSE = X
U = sre_compile.SRE_FLAG_UNICODE
UNICODE = U
T = sre_compile.SRE_FLAG_TEMPLATE
TEMPLATE = T
if sys.version_info < (3, 11):
T = sre_compile.SRE_FLAG_TEMPLATE
TEMPLATE = T
if sys.version_info >= (3, 11):
NOFLAG: int

Expand All @@ -146,8 +146,9 @@ X = RegexFlag.X
VERBOSE = RegexFlag.VERBOSE
U = RegexFlag.U
UNICODE = RegexFlag.UNICODE
T = RegexFlag.T
TEMPLATE = RegexFlag.TEMPLATE
if sys.version_info < (3, 11):
T = RegexFlag.T
TEMPLATE = RegexFlag.TEMPLATE
if sys.version_info >= (3, 11):
NOFLAG = RegexFlag.NOFLAG
_FlagsType: TypeAlias = int | RegexFlag
Expand Down Expand Up @@ -219,4 +220,6 @@ def subn(
) -> tuple[bytes, int]: ...
def escape(pattern: AnyStr) -> AnyStr: ...
def purge() -> None: ...
def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = ...) -> Pattern[AnyStr]: ...

if sys.version_info < (3, 11):
def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = ...) -> Pattern[AnyStr]: ...
6 changes: 4 additions & 2 deletions stdlib/sre_constants.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ AT_LOCALE: dict[_NamedIntConstant, _NamedIntConstant]
AT_UNICODE: dict[_NamedIntConstant, _NamedIntConstant]
CH_LOCALE: dict[_NamedIntConstant, _NamedIntConstant]
CH_UNICODE: dict[_NamedIntConstant, _NamedIntConstant]
SRE_FLAG_TEMPLATE: int
if sys.version_info < (3, 11):
SRE_FLAG_TEMPLATE: int
SRE_FLAG_IGNORECASE: int
SRE_FLAG_LOCALE: int
SRE_FLAG_MULTILINE: int
Expand All @@ -55,7 +56,8 @@ ASSERT: _NamedIntConstant
ASSERT_NOT: _NamedIntConstant
AT: _NamedIntConstant
BRANCH: _NamedIntConstant
CALL: _NamedIntConstant
if sys.version_info < (3, 11):
CALL: _NamedIntConstant
CATEGORY: _NamedIntConstant
CHARSET: _NamedIntConstant
BIGCHARSET: _NamedIntConstant
Expand Down
6 changes: 5 additions & 1 deletion stdlib/sre_parse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ if sys.version_info >= (3, 7):
TYPE_FLAGS: int
GLOBAL_FLAGS: int

class Verbose(Exception): ...
if sys.version_info < (3, 11):
class Verbose(Exception): ...

class _State:
flags: int
Expand Down Expand Up @@ -87,6 +88,9 @@ class Tokenizer:
def seek(self, index: int) -> None: ...
def error(self, msg: str, offset: int = ...) -> _Error: ...

if sys.version_info >= (3, 11):
def checkgroupname(self, name: str, offset: int, nested: int) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess stubtest will complain come beta2 python/cpython#91792


def fix_flags(src: str | bytes, flags: int) -> int: ...

_TemplateType: TypeAlias = tuple[list[tuple[int, int]], list[str | None]]
Expand Down
11 changes: 0 additions & 11 deletions tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,8 @@ pyexpat.errors.XML_ERROR_RESERVED_PREFIX_XML
pyexpat.errors.XML_ERROR_RESERVED_PREFIX_XMLNS
queue.SimpleQueue.__init__
re.Pattern.scanner # Undocumented and not useful. #6405
re.T
re.TEMPLATE
re.template
shutil.rmtree
socketserver.UDPServer.allow_reuse_port
sre_compile.CALL
sre_compile.SRE_FLAG_TEMPLATE
sre_constants.CALL
sre_constants.SRE_FLAG_TEMPLATE
sre_parse.CALL
sre_parse.SRE_FLAG_TEMPLATE
sre_parse.Tokenizer.checkgroupname
sre_parse.Verbose
string.Template.get_identifiers
string.Template.is_valid
subprocess.getoutput
Expand Down