This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Broken pre.subn() (and pre.sub())
Type: Stage:
Components: Regular Expressions Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: effbot Nosy List: effbot, tuben
Priority: normal Keywords:

Created on 2002-06-17 14:27 by tuben, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (3)
msg11229 - (view) Author: Johan Tufvesson (tuben) Date: 2002-06-17 14:27
The functions pre.subn() and pre.sub() are broken in
Python2.2 and 2.2.1. The following test was done on
SunOS 5.6:

Python 2.2.1 (#1, Jun 13 2002, 12:57:34) 
[GCC 2.95.2 19991024 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for
more information.
>>> import re
>>> re.sub('(a)', '\g<1>', 'bab')
'bab'
>>> import pre as re
>>> re.sub('(a)', '\g<1>', 'bab')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/tools/lib/python2.2/pre.py", line
179, in sub
    return pattern.sub(repl, string, count)
  File "/usr/local/tools/lib/python2.2/pre.py", line
344, in sub
    return self.subn(repl, string, count)[0]
  File "/usr/local/tools/lib/python2.2/pre.py", line
366, in subn
    repl = pcre_expand(_Dummy, repl)
TypeError: 'NoneType' object is not callable

The error has also been reproduced on SunOS5.7 with the
following interpreter:
Python 2.2 (#1, Dec 28 2001, 22:25:04) 
[GCC 2.95.2 19991024 (release)] on sunos5

The error could not be reproduced on SunOS5.6 using
Python2.1.1:
Python 2.1.1 (#5, Sep 10 2001, 13:44:17) 
[GCC 2.95.2 19991024 (release)] on sunos5

NOTE: The example for re.sub() in the Python Library
manual triggers this bug when used with module pre!
msg11230 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2002-06-27 19:15
Logged In: YES 
user_id=38376

someone who didn't understand the code changed an
"except" to "except error", and the test suite doesn't
spend much energy checking that PRE works as it
should... :-(

(as a workaround, change the line after the "pcre_expand"
call to "except:")

</F>
msg11231 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2002-06-27 20:19
Logged In: YES 
user_id=38376

fixed in CVS
History
Date User Action Args
2022-04-10 16:05:25adminsetgithub: 36761
2002-06-17 14:27:33tubencreate