Skip to content

bpo-31369: include RegexFlag in re.__all__ #30279

Merged
ethanfurman merged 8 commits into
python:mainfrom
akulakov:31369-Add-RegexFlag-to-__all__
Feb 5, 2022
Merged

bpo-31369: include RegexFlag in re.__all__ #30279
ethanfurman merged 8 commits into
python:mainfrom
akulakov:31369-Add-RegexFlag-to-__all__

Conversation

@akulakov

@akulakov akulakov commented Dec 27, 2021

Copy link
Copy Markdown
Contributor

Comment thread Misc/NEWS.d/next/Library/2021-12-27-18-28-44.bpo-31369.b9yM94.rst Outdated
Comment thread Doc/library/re.rst Outdated
Comment thread Doc/library/re.rst Outdated

.. data:: NOFLAG

Indicates no flag being applied, the value is ``0``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similarly, explain when this is useful and add versionadded.

@akulakov akulakov Jan 20, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can be used for example as a default value for a function parameter, and also as a base value that will later conditionally be ORed with other flags. But this explanation would be confusing to many readers without code examples.

An example as follows may be enough:

def myfunc(text, flag=re.NOFLAG):
    return re.match(text, flag)

What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! I think that's a useful example.

@merwok merwok Feb 10, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When was it added? Edit: found #72269 this added the enum, this PR here actually added NOFLAG despite its title

It seems that the discussion in #57594 was ignored, plus the naming is slightly stange (no flags reads better than no flag)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not ignored, missed. It took place 11 years prior. We can certainly add a NOFLAGS name now, and make NOFLAG be an alias.

Comment thread Lib/re.py Outdated
"error", "Pattern", "Match", "A", "I", "L", "M", "S", "X", "U",
"ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
"UNICODE",
"UNICODE", "RegexFlag",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should also add NOFLAG.

@JelleZijlstra

Copy link
Copy Markdown
Member

@ethanfurman would you like to look at this as it's enum-related?

@bdice

bdice commented Feb 4, 2022

Copy link
Copy Markdown

Thanks! I was just looking into this and was puzzled why a NOFLAG (or similar) object didn't exist. Happy to see this PR. 😄

On a related note, I noticed that the type of re.compile("").flags is int and not re.RegexFlag as I expected. I might file an issue for this.

Comment thread Doc/library/re.rst Outdated

.. class:: RegexFlag

An :class:`~enum.Enum` class containing the regex options listed below.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does the tilde in ~enum.Enum mean?

Also, it should be enum.IntFlag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The tilde creates a link with only the last element visible, i.e. Enum here, but since it should be IntFlag, I also removed the tilde as IntFlag is less known (though reader can still hover over shortened name to see where it links of course).

Comment thread Doc/library/re.rst Outdated

An :class:`~enum.Enum` class containing the regex options listed below.

.. versionadded:: 3.6 (documented in 3.11)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps .. versionchanged:: added to all in 3.11

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Comment thread Doc/library/re.rst Outdated
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing a parenthesis, so lets change to:

.. versionadded:: 3.11 - added to ``__all__``

@clinton21obeng

clinton21obeng commented Feb 5, 2022 via email

Copy link
Copy Markdown

@akulakov

akulakov commented Feb 5, 2022

Copy link
Copy Markdown
Contributor Author

@ethanfurman thanks for reviewing!

@akulakov akulakov deleted the 31369-Add-RegexFlag-to-__all__ branch February 5, 2022 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants