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
_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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With