From e513df403682f8cb76d9bd1b48cf12c0c20bcd64 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Mon, 27 Dec 2021 18:26:27 -0500 Subject: [PATCH 1/8] added RegexFlag to re.__all__; added RegexFlag.NOFLAG --- Doc/library/re.rst | 6 ++++++ Lib/re.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst index b12ce4b9744f94..0a0e62031c1bb2 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -637,6 +637,9 @@ form. programs that use only a few regular expressions at a time needn't worry about compiling regular expressions. +.. class:: RegexFlag + + An :class:`~enum.Enum` class containing the regex options listed below. .. data:: A ASCII @@ -710,6 +713,9 @@ 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``. .. data:: S DOTALL diff --git a/Lib/re.py b/Lib/re.py index ea41217ce08c2d..f1145a805fc138 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", "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 From cf6a00e18824c51cf30f08eefa429046fcf54cc0 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Mon, 27 Dec 2021 18:28:52 -0500 Subject: [PATCH 2/8] added news entry --- .../next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst 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 00000000000000..d202979099d99a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst @@ -0,0 +1,2 @@ +Added :class:`~re.RegexFlag` to ``re.__all__`` and documented it. Added +:data:`~re.RegexFlag.NOFLAG` to indicate no flags being set. From fe74940eed330c0a718c45a1bc964c734c985cfa Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Mon, 27 Dec 2021 18:31:11 -0500 Subject: [PATCH 3/8] add a comma --- Lib/re.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/re.py b/Lib/re.py index f1145a805fc138..1c21865750d4f5 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", "RegexFlag" + "UNICODE", "RegexFlag", ] __version__ = "2.2.1" From dbe2094c2819897be9d288790ebc403f53c7591b Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 20 Jan 2022 01:31:31 -0500 Subject: [PATCH 4/8] added versionadded tags and added NOFLAG to __all__ --- Doc/library/re.rst | 4 ++++ Lib/re.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 0a0e62031c1bb2..8643d0af0f69a6 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -641,6 +641,8 @@ form. An :class:`~enum.Enum` class containing the regex options listed below. + .. versionadded:: 3.6 (documented in 3.11) + .. data:: A ASCII @@ -717,6 +719,8 @@ form. Indicates no flag being applied, the value is ``0``. + .. versionadded:: 3.11 + .. data:: S DOTALL diff --git a/Lib/re.py b/Lib/re.py index 1c21865750d4f5..bc6bfb342e56b7 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", "RegexFlag", + "UNICODE", "NOFLAG", "RegexFlag", ] __version__ = "2.2.1" From de7fc51c12f123b28ca7bd3fa5b509137e814c7b Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 20 Jan 2022 01:35:56 -0500 Subject: [PATCH 5/8] add example for NOFLAG --- Doc/library/re.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 8643d0af0f69a6..dbb78c6e2a5261 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -717,7 +717,13 @@ form. .. data:: NOFLAG - Indicates no flag being applied, the value is ``0``. + 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 From e410e0d8ac59fe11571e3594dd50ae7965755dd3 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Thu, 20 Jan 2022 01:36:19 -0500 Subject: [PATCH 6/8] Update Misc/NEWS.d/next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst Co-authored-by: Jelle Zijlstra --- .../next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index d202979099d99a..2bb9e62de1f40e 100644 --- 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 @@ -1,2 +1,2 @@ -Added :class:`~re.RegexFlag` to ``re.__all__`` and documented it. Added +Add :class:`~re.RegexFlag` to ``re.__all__`` and documented it. Add :data:`~re.RegexFlag.NOFLAG` to indicate no flags being set. From b9bd6a5a8b33d70d5c6348b06aca024151a33b43 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Fri, 4 Feb 2022 17:22:15 -0500 Subject: [PATCH 7/8] update per comments --- Doc/library/re.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst index dbb78c6e2a5261..8f1477f8743694 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -639,9 +639,9 @@ form. .. class:: RegexFlag - An :class:`~enum.Enum` class containing the regex options listed below. + An :class:`enum.IntFlag` class containing the regex options listed below. - .. versionadded:: 3.6 (documented in 3.11) + .. versionadded:: added to ``__all__`` in 3.11) .. data:: A ASCII From e145b52e2cc21ffc095c63d78d0bfcd805ef38cb Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Fri, 4 Feb 2022 20:54:45 -0500 Subject: [PATCH 8/8] update versionadded --- Doc/library/re.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 8f1477f8743694..8d62e3bf4d8d83 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -641,7 +641,7 @@ form. An :class:`enum.IntFlag` class containing the regex options listed below. - .. versionadded:: added to ``__all__`` in 3.11) + .. versionadded:: 3.11 - added to ``__all__`` .. data:: A ASCII