[Python-Dev] type categories -- an example
Tue, 20 Aug 2002 10:00:20 -0400
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=
it acts like a compiled regular expression, and therefore supports that=20
interface. So, the real solution would be to have re assert that interfac=
whatever the compiler returns so that you can check for it, something lik=
# It's a regex
Where ISre is the compiled regular expression interface object. If the=20
implementation varies the test would still work. Even if the interface=20
varied, the test would work (but it might break other stuff).