zpoint /CPython-Internals

Dive into CPython internals, trying to illustrate every detail of CPython implementation

★ 5,091⑂ 477👁 336⑃ 23● 45▤ 0
CCreated 2019-04-15
5,091
stars
+0+0+7
477
forks
336
watchers
23
prs
45
issues
0
releases
–
discussions

README

Cpython Internals

 English
 한국어
 如果你需要接收更新通知, 点击右上角的 Watch, 当有文章更新时会在 issue 发布相关标题和链接
 如果有任何链接无法打开请自行搭梯子O(∩_∩)O

这个仓库是笔者分析 cpython 源码的时候做的记录/博客

笔者将尝试尽可能的讲清楚 cpython 底层实现的细节

shell script
 基于 3.8.0a0 版本
cd cpython
git reset --hard ab54b9a130c88f708077c2ef6c4963b632c132b3



这里的内容适用于有过 python 编程经验并且对解释器的实现感兴趣的同学, 如果你需要的的是入门到进阶之类的学习资料, 请参考 awesome-python-books


 目录

 基本对象
 模块
 库
 解释器相关
 扩展
 学习资料
 参与贡献

 授权


 基本对象
- [x] dict
- [x] long/int
- [x] unicode/str
- [x] set
- [x] list(timsort)
- [x] tuple
- [x] bytes
- [x] bytearray(buffer protocol)
- [x] float
- [x] func(user-defined method)
- [x] method(builtin method)
- [x] iter
- [x] gen(generator/coroutine/async generator)
- [x] class(bound method/classmethod/staticmethod)
- [x] complex
- [x] enum
- [x] type(mro/metaclass/类/实例的创建过程)

 模块

 - [ ] io
 	- [x] fileio
 - [x] pickle

 库

 - [x] re(正则)
 - [ ] asyncio

 解释器相关

 - [x] gil(全局解释器锁)
 - [x] gc(垃圾回收机制)
 - [x] memory management(内存管理机制)
 - [x] descr(访问(类/实例)属性时发生了什么/__get__/__getattribute__/__getattr__)
 - [x] exception(异常处理机制)
 - [x] module(import实现机制)
 - [x] frame
 - [x] code
 - [x] slots/__slots__(属性在类/实例创建时是如何初始化的)
 - [x] thread(线程)
 - [x] PyObject(基础篇/概述)

 扩展

 - [x] C API(python 性能分析和 C 扩展)
 - [ ] Cython(C extension)
 - [x] Boost C++ libaries (C\+\+ extension)
 - [x] C++ 扩展
 	- [x] 写 NumPy 扩展
 	- [x] 绕过 GIL

 语法

编译阶段

 [x] 从语法/元语法到DFA
 [x] 从 CST 到 AST
 [x] 从 AST 到 字节码


 学习资料

以下的资料笔者遵循先阅读后推荐的原则

 CPython internals - Interpreter and source code overview(油管视频)
  
  
 rushter(blog/eng)
 YET ANOTHER PYTHON INTERNALS BLOG(blog/eng)
 Junnplus(blog/中文)
 manjusaka(blog/中文)
 aoik-Python's compiler series(blog/eng)

 参与贡献

欢迎所有形式的贡献

 提交一个 pull request
   如果你想分享任何你知道的相关知识
    发布一篇文章
   更正技术性错误
   更正语法性错误
   翻译
   其他情况, 不限于上述
 提交一个 issue
   任何建议
   任何问题
   更正错误
   其他情况, 不限于上述

 授权

Snapshot: 2026-11-04T14:00:00Z · Data license Apache-2.0 · JSON