Skip to content

Commit fea7290

Browse files
bpo-31369: include RegexFlag in re.__all__ (GH-30279)
* added RegexFlag to re.__all__; added RegexFlag.NOFLAG Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent bf95ff9 commit fea7290

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Doc/library/re.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,11 @@ form.
637637
programs that use only a few regular expressions at a time needn't worry
638638
about compiling regular expressions.
639639

640+
.. class:: RegexFlag
641+
642+
An :class:`enum.IntFlag` class containing the regex options listed below.
643+
644+
.. versionadded:: 3.11 - added to ``__all__``
640645

641646
.. data:: A
642647
ASCII
@@ -710,6 +715,17 @@ form.
710715
string and immediately before the newline (if any) at the end of the string.
711716
Corresponds to the inline flag ``(?m)``.
712717

718+
.. data:: NOFLAG
719+
720+
Indicates no flag being applied, the value is ``0``. This flag may be used
721+
as a default value for a function keyword argument or as a base value that
722+
will be conditionally ORed with other flags. Example of use as a default
723+
value::
724+
725+
def myfunc(text, flag=re.NOFLAG):
726+
return re.match(text, flag)
727+
728+
.. versionadded:: 3.11
713729

714730
.. data:: S
715731
DOTALL

Lib/re.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@
137137
"findall", "finditer", "compile", "purge", "template", "escape",
138138
"error", "Pattern", "Match", "A", "I", "L", "M", "S", "X", "U",
139139
"ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
140-
"UNICODE",
140+
"UNICODE", "NOFLAG", "RegexFlag",
141141
]
142142

143143
__version__ = "2.2.1"
144144

145145
@enum.global_enum
146146
@enum._simple_enum(enum.IntFlag, boundary=enum.KEEP)
147147
class RegexFlag:
148+
NOFLAG = 0
148149
ASCII = A = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
149150
IGNORECASE = I = sre_compile.SRE_FLAG_IGNORECASE # ignore case
150151
LOCALE = L = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add :class:`~re.RegexFlag` to ``re.__all__`` and documented it. Add
2+
:data:`~re.RegexFlag.NOFLAG` to indicate no flags being set.

0 commit comments

Comments
 (0)