how to determine for using c extension or not ?

Terry Reedy tjreedy at
Mon Aug 3 20:11:27 CEST 2015

On 8/3/2015 9:08 AM, umedoblock wrote:

Posting three times under two different names is not polite.  Please to 
not  repeat.

> I use bisect module.
> bisect module developer give us c extension as _bisect.

We call that a C accelerator.

> If Python3.3 use _bisect, _bisect override his functions in

An accelerator may override either some or all functions.
In this case, Lib/ ends with

     from _bisect import *
except ImportError:

For CPython, I expect that all 4 similar functions (and two synonyms) 
get replaced.

> now, I use id() function to determine for using c extension or not.

You should not care.  If you think there is an undocumented difference 
in behavior, ask here if it is a bug.

I expect that that test/ runs the same tests on both 
versions.  We have a test helper function for such situations.  It 
blocks the import of the accelerator so that the Python version can be 

>>>> import bisect
>>>> id(bisect.bisect)
> 139679893708880
>>>> import _bisect
>>>> id(_bisect.bisect)
> 139679893708880
> they return 139679893708880 as id.
> so i believe that i use c extension.

The bisect and _bisect modules are different objects.  Since they and 
their global namespace exist simultaneously, then yes, the above says 
that both have the name 'bisect' bound to the C-coded built-in version.

Terry Jan Reedy

More information about the Python-list mailing list