[Python-bugs-list] [ python-Bugs-764548 ] SRE doesn't use isinstance
SourceForge.net
noreply@sourceforge.net
Wed, 02 Jul 2003 12:47:04 -0700
Bugs item #764548, was opened at 2003-07-02 14:20
Message generated for change (Comment added) made by effbot
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=764548&group_id=5470
Category: Regular Expressions
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Ronald Oussoren (ronaldoussoren)
>Assigned to: Just van Rossum (jvr)
Summary: SRE doesn't use isinstance
Initial Comment:
The following code fails with a TypeError:
#--------------------------------
import re
class MyUnicode(unicode):
pass
val = MyUnicode("foobar")
r = re.compile(val)
#--------------------------------
This is caused by a check in sre.py: it checks if the
type of the pattern is str or unicode, instead of
testing if the value is an instance of those types.
This is not a completely theoretical problem: PyObjC
uses a subclass of unicode to represent Objective-C
strings.
----------------------------------------------------------------------
>Comment By: Fredrik Lundh (effbot)
Date: 2003-07-02 21:47
Message:
Logged In: YES
user_id=38376
"Shall I just go ahead and check it in?"
It would be most excellent if you did.
Cheers /F
----------------------------------------------------------------------
Comment By: Just van Rossum (jvr)
Date: 2003-07-02 20:58
Message:
Logged In: YES
user_id=92689
D'oh, 1.5.2 is so long ago I could've sworn it didn't have
isinstance(). However, 1.5.2 doesn't accept tuples for the second
argument. I've attached a new patch, but it's so easy to still make
it work with 1.5.2 that I didn't bother to break that compatibility ;-
) Shall I just go ahead and check it in?
----------------------------------------------------------------------
Comment By: Fredrik Lundh (effbot)
Date: 2003-07-02 20:43
Message:
Logged In: YES
user_id=38376
Just, note that "isinstance" is supported in 1.5.2 (but
unicode strings aren't).
And I think it's safe to skip 1.5.2 support in SRE;
I suggest changing the "baseline" to 2.1.
If you agree, feel free to assign this item to your-
self, and fix the code.
----------------------------------------------------------------------
Comment By: Just van Rossum (jvr)
Date: 2003-07-02 16:54
Message:
Logged In: YES
user_id=92689
Here's a patch that should fix the problem, while remaining
compatible with 1.5.2. Fredrik, please assign to me if you think
the patch is ok. Preferably before 2.3 final is out ;-)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=764548&group_id=5470