#21 Kodos displays regex match where python re.search finds None

open
nobody
None
5
2010-04-05
2010-04-05
No

Reproduction:
In the "regular expression pattern" text field, write:
(?:/{0,2}\**\s?todo):?\s*(?P<todo>.+)

In the "Search string" text field, write:
//\todo howdy

Kodos will display a match with:
todo howdy

And will produce the sample code:

import re

# common variables

rawstr = r"""(?:/{0,2}\**\s?todo):?\s*(?P<todo>.+)"""
embedded_rawstr = r"""(?:/{0,2}\**\s?todo):?\s*(?P<todo>.+)"""
matchstr = """//\todo howdy"""

# method 1: using a compile object
compile_obj = re.compile(rawstr)
match_obj = compile_obj.search(matchstr)

# method 2: using search function (w/ external flags)
match_obj = re.search(rawstr, matchstr)

# method 3: using search function (w/ embedded flags)
match_obj = re.search(embedded_rawstr, matchstr)

# Retrieve group(s) from match_obj
all_groups = match_obj.groups()

# Retrieve group(s) by index
group_1 = match_obj.group(1)

# Retrieve group(s) by name
todo = match_obj.group('todo')

Which will result in a python exception when run:
Traceback (most recent call last):
File "kodos_bug.py", line 20, in <module>
all_groups = match_obj.groups()
AttributeError: 'NoneType' object has no attribute 'groups'

Using kodos 2.4.9 (from the ubuntu 9.10 package repository) and python 2.6.4

Discussion


Log in to post a comment.