
On Monday 19 August 2002 06:45 pm, Andrew Koenig wrote:
Jeremy> Hard to say. I can read the code and see that the current Jeremy> implementation will always return objects of the same type. Jeremy> In fact, it's using type(sre_compile.compile("", 0)) Jeremy> internally to represent that type.
Jeremy> That's not a guarantee. Perhaps Fredrik wants to reserve the Jeremy> right to change this in the future. It's not unusual for Jeremy> Python modules to be under-specified in this way.
The real point is that this is an example of why a uniform way of checking for such types would be nice. I shouldn't have to read the source to figure out how to tell if something is a compiled regular expression.
In general you wouldn't care whether is was a sre_foo or an sre_bar, just if it acts like a compiled regular expression, and therefore supports that interface. So, the real solution would be to have re assert that interface on whatever the compiler returns so that you can check for it, something like: if ISre.isImplementedBy(unknown_ob): # It's a regex Where ISre is the compiled regular expression interface object. If the implementation varies the test would still work. Even if the interface varied, the test would work (but it might break other stuff). -Casey