[Python-checkins] bpo-31369: include ``RegexFlag`` in ``re.__all__`` (GH-30279)

ethanfurman webhook-mailer at python.org
Fri Feb 4 22:54:34 EST 2022


https://github.com/python/cpython/commit/fea7290a0ecee09bbce571d4d10f5881b7ea3485
commit: fea7290a0ecee09bbce571d4d10f5881b7ea3485
branch: main
author: andrei kulakov <andrei.avk at gmail.com>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2022-02-04T19:54:28-08:00
summary:

bpo-31369: include ``RegexFlag`` in ``re.__all__`` (GH-30279)

* added RegexFlag to re.__all__; added RegexFlag.NOFLAG

Co-authored-by: Jelle Zijlstra <jelle.zijlstra at gmail.com>

files:
A Misc/NEWS.d/next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst
M Doc/library/re.rst
M Lib/re.py

diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index b12ce4b9744f9..8d62e3bf4d8d8 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -637,6 +637,11 @@ form.
       programs that use only a few regular expressions at a time needn't worry
       about compiling regular expressions.
 
+.. class:: RegexFlag
+
+   An :class:`enum.IntFlag` class containing the regex options listed below.
+
+   .. versionadded:: 3.11 - added to ``__all__``
 
 .. data:: A
           ASCII
@@ -710,6 +715,17 @@ form.
    string and immediately before the newline (if any) at the end of the string.
    Corresponds to the inline flag ``(?m)``.
 
+.. data:: NOFLAG
+
+   Indicates no flag being applied, the value is ``0``.  This flag may be used
+   as a default value for a function keyword argument or as a base value that
+   will be conditionally ORed with other flags.  Example of use as a default
+   value::
+
+      def myfunc(text, flag=re.NOFLAG):
+          return re.match(text, flag)
+
+   .. versionadded:: 3.11
 
 .. data:: S
           DOTALL
diff --git a/Lib/re.py b/Lib/re.py
index a7ab9b3706748..e9a745dc581a6 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -137,7 +137,7 @@
     "findall", "finditer", "compile", "purge", "template", "escape",
     "error", "Pattern", "Match", "A", "I", "L", "M", "S", "X", "U",
     "ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
-    "UNICODE",
+    "UNICODE", "NOFLAG", "RegexFlag",
 ]
 
 __version__ = "2.2.1"
@@ -145,6 +145,7 @@
 @enum.global_enum
 @enum._simple_enum(enum.IntFlag, boundary=enum.KEEP)
 class RegexFlag:
+    NOFLAG = 0
     ASCII = A = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
     IGNORECASE = I = sre_compile.SRE_FLAG_IGNORECASE # ignore case
     LOCALE = L = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
diff --git a/Misc/NEWS.d/next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst b/Misc/NEWS.d/next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst
new file mode 100644
index 0000000000000..2bb9e62de1f40
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst
@@ -0,0 +1,2 @@
+Add :class:`~re.RegexFlag` to ``re.__all__`` and documented it. Add
+:data:`~re.RegexFlag.NOFLAG` to indicate no flags being set.



More information about the Python-checkins mailing list