Skip to content
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

re.match ignores optional flags when receiving a compiled regex pattern #46002

Closed
bcorfman mannequin opened this issue Dec 19, 2007 · 2 comments
Closed

re.match ignores optional flags when receiving a compiled regex pattern #46002

bcorfman mannequin opened this issue Dec 19, 2007 · 2 comments
Assignees
Labels
topic-regex type-bug An unexpected behavior, bug, or error

Comments

@bcorfman
Copy link
Mannequin

bcorfman mannequin commented Dec 19, 2007

BPO 1661
Nosy @rhettinger

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:

assignee = 'https://github.com/rhettinger'
closed_at = <Date 2007-12-19.18:14:17.596>
created_at = <Date 2007-12-19.15:40:03.865>
labels = ['expert-regex', 'type-bug']
title = 're.match ignores optional flags when receiving a compiled regex pattern'
updated_at = <Date 2007-12-19.18:14:17.594>
user = 'https://bugs.python.org/bcorfman'

bugs.python.org fields:

activity = <Date 2007-12-19.18:14:17.594>
actor = 'rhettinger'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2007-12-19.18:14:17.596>
closer = 'rhettinger'
components = ['Regular Expressions']
creation = <Date 2007-12-19.15:40:03.865>
creator = 'bcorfman'
dependencies = []
files = []
hgrepos = []
issue_num = 1661
keywords = []
message_count = 2.0
messages = ['58808', '58816']
nosy_count = 2.0
nosy_names = ['rhettinger', 'bcorfman']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1661'
versions = ['Python 2.6']

@bcorfman
Copy link
Mannequin Author

bcorfman mannequin commented Dec 19, 2007

Python's documentation for the re.match function is match(pattern,
string, [flags]) where pattern can be either a regex string or a
compiled regex object. If it's a compiled regex object, then supplying
an optional flag to re.match (in my case, re.IGNORECASE) doesn't work
and, more to the point, fails silently. I think this should throw an
exception if it's not going to work.

See
http://mysite.verizon.net/bcorfman/2007/12/something-i-hate-about-pythons-re.html
for a discussion.

A possible change (proposed by effbot) is below:
Index: re.py
===================================================================

--- re.py       (revision 52330)
+++ re.py       (working copy)
@@ -224,6 +224,7 @@
         return p
     pattern, flags = key
     if isinstance(pattern, _pattern_type):
+        assert not flags
         return pattern
     if not sre_compile.isstring(pattern):
         raise TypeError, "first argument must be string or compiled
pattern"

@bcorfman bcorfman mannequin added topic-regex type-bug An unexpected behavior, bug, or error labels Dec 19, 2007
@rhettinger rhettinger self-assigned this Dec 19, 2007
@rhettinger
Copy link
Contributor

Fixed. See commit 59573.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-regex type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant