-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert a warning about flags not at the start of the regular expression into error #91222
Comments
This warning was introduced in 3.6. The reason is that in most other regular expression implementations global inline flags in the middle of the expression have different semantic: they affect only the part of the expression after the flag. But in Python they affect the whole expression. It caused confusion and was a source of bugs. After 5 releases it is a time to convert this warning into error. In future we can allow global inline flags in the middle of the expression with different semantic. It is safer if one or more intermediate versions will raise an error. |
Misplaced inline flags are no longer allowed in Python 3.11: python/cpython#91222
For the record here's some brokenness this caused: |
@jrmuizel Could you report this in a new issue mentioning this issue, please? I suspect almost nobody reads already closed entries. |
Is it worth filing a new issue even though both of those uses have already been fixed upstream? |
My bad. I've thought you linked to some extra issues similar to this but found by third-party projects that use Python. |
This comment was marked as abuse.
This comment was marked as abuse.
3.11 requires global flags at the start (bpo-47066). See python/cpython#91222
3.11 requires global flags at the start (bpo-47066). See python/cpython#91222
#TIL if the intent was to only apply the flag to a subset of the regex, e.g.:
You can use the following:
See the It would be great if this was mentioned on https://docs.python.org/3/whatsnew/3.11.html#porting-to-python-3-11 as I have "migrated" dozens of files running into this issue where the original intent was to only apply the flag to a subset (especially when you concatenate regexes together), but I only learned about this today. (I hope this comment can at least help some when they click the Also, there is no mention of the word "global" on https://docs.python.org/3/library/re.html, as it seems ideal if that could mention "global" v.s. "local" inline flags. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: