mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
c034b47ef3
commit
7533587d43
3 changed files with 28 additions and 19 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue