classification
Title: Add an explicit re.NOFLAGS flag value to the re module
Type: Stage:
Components: Library (Lib), Regular Expressions Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eli.bendersky, eric.araujo, eric.smith, ezio.melotti, pitrou, rhettinger, terry.reedy
Priority: normal Keywords:

Created on 2011-11-11 19:39 by eli.bendersky, last changed 2011-11-13 00:05 by rhettinger. This issue is now closed.

Messages (9)
msg147443 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-11-11 19:39
The flags 're' accept are numeric underneath, and the current value of "no flags" is just 0, which is also specified in the documentation as the default value. However, using raw numeric values is not a good programming practice. 

The suggestion is to add a simple re.NOFLAGS constant to the 're' module with the value of 0, and use it in the documentation instead of plain 0. It's a simple change that won't break anything and may provide better readability for some code, as well as remove the need for plain integer references in the documentation.

See also issues #11957 and #12875.

Adding to nosy people taking part in discussion of the aforementioned issue. If you're not interested, please remove yourself - I apologize in advance.
msg147444 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2011-11-11 20:25
Since the flags are OR'd together, I don't see what other value the "no flags" parameter could have, other than zero. That said, I don't feel strongly about it, and if it helps readability I'm not opposed.
msg147448 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-11-11 22:35
As Eric, I don't really think it's useful, and it might actually be confusing (people will start wondering if there's a difference between 0 and NOFLAGS).
msg147451 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-11-11 22:59
I think a proper solution would be fixing #11957.  Adding a NOFLAGS alias for 0 would help fixing #12875, but I don't think it will be useful/use otherwise.
msg147458 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-11-12 03:23
Antoine, what's the outcome of people wondering about the difference? I don't see what's bad about it, it's not as if people are writing (or supposed to write) code that does arithmetic on these flag values. Their only usage is to:

1. Provide no flags
2. Provide a single flag
3. Provide a few flags ORed together

The "OR" (which makes no mathematical sense in this case) is bad enough, but why not provide an easy fix for (1), making it explicit instead of implicit. I think we sometimes forget that not everyone who picks up Python is an old C dog, familiar with these tricks. To newbies for whom Python is the first language, these flags aren't very intuitive to use, I imagine.
msg147460 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-11-12 03:51
If you want to provide no flags, I think it's easier to provide no flags, rather than having to learn some NOFLAGS constant value that can be used to make the fact that you are passing no flags more explicit than it already is.
I might agree that ORing flags might not be the best API ever, but that a separate problem.  So in my opinion there's nothing to fix about 1.
msg147505 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-11-12 15:41
I had too the need to find out the value to pass when there are no flags, so a mention of 0 in the doc would have been enough for me.  -0 on a new constant.
msg147515 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-11-12 18:13
I think we have enough < 0 to reject the issue. Closing.
msg147536 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-11-13 00:05
Thank you for closing this.  I think it would only add clutter to a module that is already puts readers into information overload.
History
Date User Action Args
2011-11-13 00:05:12rhettingersetnosy: + rhettinger
messages: + msg147536
2011-11-12 18:13:58eli.benderskysetstatus: open -> closed
resolution: rejected
messages: + msg147515
2011-11-12 15:41:01eric.araujosetmessages: + msg147505
2011-11-12 03:51:47ezio.melottisetmessages: + msg147460
2011-11-12 03:23:48eli.benderskysetmessages: + msg147458
2011-11-11 22:59:11ezio.melottisetmessages: + msg147451
2011-11-11 22:35:49pitrousetnosy: + pitrou
messages: + msg147448
2011-11-11 20:25:22eric.smithsetmessages: + msg147444
2011-11-11 19:39:15eli.benderskycreate