[New-bugs-announce] [issue12146] Possible bug in 're' documentation example

Eli Bendersky report at bugs.python.org
Sun May 22 05:43:35 CEST 2011

New submission from Eli Bendersky <eliben at gmail.com>:

>From the docs maillist, by Herman L. Jackson:



When running the tokenize example at the bottom of http://docs.python.org/py3k/library/re.html#match-objects
I received the following error:

   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "<stdin>", line 23, in tokenize
   NameError: global name 'val' is not defined

The problem is that val is never assigned to before this line:

   if typ == 'ID' and val in keywords:

Here is a suggested rewrite of the that section:

   elif typ != 'SKIP':
       val = mo.group(typ)
       if typ == 'ID' and val in keywords:
           typ = val
       yield Token(typ, val, line, mo.start()-line_start)

Attached is a complete working example.

assignee: eli.bendersky
components: Documentation
files: tokenize.py
keywords: easy
messages: 136501
nosy: eli.bendersky
priority: normal
severity: normal
stage: needs patch
status: open
title: Possible bug in 're' documentation example
type: behavior
versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file22056/tokenize.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list