[Python-Dev] SF patch 864863: Bisect C implementation (original) (raw)
Samuele Pedroni pedronis at bluewin.ch
Fri Jan 2 10:31:28 EST 2004
- Previous message: [Python-Dev] SF patch 864863: Bisect C implementation
- Next message: [Python-Dev] SF patch 864863: Bisect C implementation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 15:47 02.01.2004 +0100, Samuele Pedroni wrote:
import heapq # import likely the C code test(heapq) # or heapq could be a global heapq = test.support.getpurepythonversion(heapq)
oops, that should have been test_support
test(heapq)
here's a tentative minimally tested(*) version of get_pure_python_version:
def get_pure_python_version(mod,bltin_mod_name=None): DUMMY = object() mod_name = mod.name if bltin_mod_name is None: bltin_mod_name = '_'+mod_name import inspect,sys,new pure_py_ver = new.module('pure-python-'+mod_name) # ? saved_bltin_mod = sys.modules.get(bltin_mod_name,DUMMY)
import _ should fail momentarily
sys.modules[bltin_mod_name] = None # or an empty module execfile(inspect.getsourcefile(mod),pure_py_ver.dict)
if saved_bltin_mod is DUMMY: del sys.modules[bltin_mod_name] else: sys.modules[bltin_mod_name] = saved_bltin_mod
return pure_py_ver
we could also detect the case were there's no builtin version, which means that the first test likely already tested just the pure Python version.
*: tested with:
<array2.py> class array(object): def init(*args,**kws): pass
def repr(self): return ""
try: from array import array except ImportError: pass </array2.py>
import array2 ppy = get_pure_python_version(array2)
- Previous message: [Python-Dev] SF patch 864863: Bisect C implementation
- Next message: [Python-Dev] SF patch 864863: Bisect C implementation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]