[Python-Dev] type categories -- an example

Jeremy Hylton jeremy@alum.mit.edu
Mon, 19 Aug 2002 18:32:11 -0400

>>>>> "AK" == Andrew Koenig <ark@research.att.com> writes:

  Jeremy> I'd put this at the module level: compiled_re_type =
  Jeremy> type(re.compile(""))

  Jeremy> Then you can use isistance() to test:

  Jeremy> isinstance(re.compile("spam+"), compiled_re_type)

  AK> But is it guaranteed that re.compile will always yield an object
  AK> of the same type?

Hard to say.  I can read the code and see that the current
implementation will always return objects of the same type.  In fact,
it's using type(sre_compile.compile("", 0)) internally to represent
that type.

That's not a guarantee.  Perhaps Fredrik wants to reserve the right to
change this in the future.  It's not unusual for Python modules to be
under-specified in this way.