Skip to content
Merged
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
23 changes: 17 additions & 6 deletions stdlib/re.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import enum
import sre_compile
import sre_constants
import sys
from _typeshed import ReadableBuffer
from collections.abc import Callable, Iterator, Mapping
Expand All @@ -21,7 +22,6 @@ __all__ = [
"finditer",
"compile",
"purge",
"template",
"escape",
"error",
"A",
Expand All @@ -41,10 +41,17 @@ __all__ = [
"Match",
"Pattern",
]
if sys.version_info < (3, 13):
__all__ += ["template"]

if sys.version_info >= (3, 11):
__all__ += ["NOFLAG", "RegexFlag"]

if sys.version_info >= (3, 13):
__all__ += ["PatternError"]

PatternError = sre_constants.error

_T = TypeVar("_T")

@final
Expand Down Expand Up @@ -198,8 +205,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, 13):
T = sre_compile.SRE_FLAG_TEMPLATE
TEMPLATE = T
if sys.version_info >= (3, 11):
NOFLAG = 0

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

if sys.version_info < (3, 13):
def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = 0) -> Pattern[AnyStr]: ...