[Python-Dev] SF patch 864863: Bisect C implementation

Guido van Rossum guido at python.org
Fri Jan 2 10:59:41 EST 2004


> I think that something like:
> 
> <heapq.py>
> heapq python code...
> 
> try:
>    from _heapq import * # or list the names explicitly
> except ImportError:
>    pass
> </heapq.py>
> 
> can be made to work.

I like this too.

> The tricky part is more in test_heapq, but I think it can be rewritten in 
> some form like:
> 
> import heapq # import likely the C code
> test(heapq) # or heapq could be a global
> heapq = test.support.get_pure_python_version(heapq)
> test(heapq)
> 
> or some variation.

Note that you could force the _heapq import to fail by putting an
explicit None in sys.modules, like so:

  import heapq
  ...test the C impl...
  sys.modules['_heapq'] = None
  reload(heapq) # Now 'from _heapq import ...' will fail
  ...test the Python impl...
  # Restore the default situation
  del sys.modules['_heapq']
  reload(heapq)

I wish cStringIO and cPickle would go away, but unfortunately the
Python versions have features that the C code don't have.  Hopefully
the use of new-style classes can avoid this issue for new module pairs.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list