Improved error msg when a symbolic group name is redefined. Added docs

and NEWS.  Bugfix candidate?  That's a dilemma for Anthony <wink>:  /F
did fix a longstanding bug here, but the fix can cause code to raise an
exception that previously worked by accident.
This commit is contained in:
Tim Peters 2001-11-03 19:35:43 +00:00
parent c034b47ef3
commit 7533587d43
3 changed files with 28 additions and 19 deletions

View file

@ -237,7 +237,8 @@ referenced later in the pattern.
\item[\code{(?P<\var{name}>...)}] Similar to regular parentheses, but
the substring matched by the group is accessible via the symbolic group
name \var{name}. Group names must be valid Python identifiers. A
name \var{name}. Group names must be valid Python identifiers, and
each group name must be defined only once within a regular expression. A
symbolic group is also a numbered group, just as if the group were not
named. So the group named 'id' in the example above can also be
referenced as the numbered group 1.

View file

@ -81,8 +81,10 @@ class Pattern:
gid = self.groups
self.groups = gid + 1
if name:
if self.groupdict.has_key(name):
raise error, "can only use each group name once"
ogid = self.groupdict.get(name, None)
if ogid is not None:
raise error, ("redefinition of group name %s as group %d; " +
"was group %d") % (`name`, gid, ogid)
self.groupdict[name] = gid
self.open.append(gid)
return gid

View file

@ -46,6 +46,12 @@ Extension modules
Library
- Symbolic group names in regular expressions must be unique. For
example, the regexp r'(?P<abc>)(?P<abc>)' is not allowed, because a
single name can't mean both "group 1" and "group 2" simultaneously.
Python 2.2 detects this error at regexp compilation time; previously,
the error went undetected, and results were unpredictable.
- Tix exposes more commands through the classes DirSelectBox,
DirSelectDialog, ListNoteBook, Meter, CheckList, and the
methods tix_addbitmapdir, tix_cget, tix_configure, tix_filedialog,