Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find source collections.deque?

Tags:

python

I need to add functionality to a class that inherits to deque, but prefer to see the code in collections.deque to implement a new class final.

>>> from _collections import deque, defaultdict
>>> inspect.getfile(deque)
'/usr/lib/python2.7/collections.pyc'
>>> inspect.getfile(collections)
'/usr/lib/python2.7/collections.pyc'
>>> inspect.getfile(_collections)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/inspect.py", line 403, in getfile
    raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module '_collections' (built-in)> is a built-in module
>>> 

Where can I find the source code of collections.deque? this is source collections, but does not include collections.deque. -> http://hg.python.org/cpython/file/2.7/Lib/collections.py

like image 464
lmokto Avatar asked Dec 30 '13 00:12

lmokto


1 Answers

_collections is a builtin module.

In CPython this module is written in C: https://github.com/python/cpython/blob/main/Modules/_collectionsmodule.c

But there is a pure-python implementation in PyPy: https://bitbucket.org/pypy/pypy/src/default/lib_pypy/_collections.py

like image 102
4 revs, 2 users 93% Avatar answered Oct 20 '22 15:10

4 revs, 2 users 93%