|
| 1 | +# CPython source code |
| 2 | + |
| 3 | +This section gives an overview of CPython's code structure and provides |
| 4 | +a summary of file locations for modules and built-ins. |
| 5 | + |
| 6 | + |
| 7 | +## Source code layout |
| 8 | + |
| 9 | +For a Python module, the typical layout is: |
| 10 | + |
| 11 | +* `Lib/<module>.py` |
| 12 | +* `Modules/_<module>.c` (if there's also a C accelerator module) |
| 13 | +* `Lib/test/test_<module>.py` |
| 14 | +* `Doc/library/<module>.rst` |
| 15 | + |
| 16 | +For an extension module, the typical layout is: |
| 17 | + |
| 18 | +* `Modules/<module>module.c` |
| 19 | +* `Lib/test/test_<module>.py` |
| 20 | +* `Doc/library/<module>.rst` |
| 21 | + |
| 22 | +For builtin types, the typical layout is: |
| 23 | + |
| 24 | +* `Objects/<builtin>object.c` |
| 25 | +* `Lib/test/test_<builtin>.py` |
| 26 | +* [`Doc/library/stdtypes.rst`](../Doc/library/stdtypes.rst) |
| 27 | + |
| 28 | +For builtin functions, the typical layout is: |
| 29 | + |
| 30 | +* [`Python/bltinmodule.c`](../Python/bltinmodule.c) |
| 31 | +* [`Lib/test/test_builtin.py`](../Lib/test/test_builtin.py) |
| 32 | +* [`Doc/library/functions.rst`](../Doc/library/functions.rst) |
| 33 | + |
| 34 | +Some exceptions to these layouts are: |
| 35 | + |
| 36 | +* built-in type `int` is at [`Objects/longobject.c`](../Objects/longobject.c) |
| 37 | +* built-in type `str` is at [`Objects/unicodeobject.c`](../Objects/unicodeobject.c) |
| 38 | +* built-in module `sys` is at [`Python/sysmodule.c`](../Python/sysmodule.c) |
| 39 | +* built-in module `marshal` is at [`Python/marshal.c`](../Python/marshal.c) |
| 40 | +* Windows-only module `winreg` is at [`PC/winreg.c`](../PC/winreg.c) |
0 commit comments