跳到主要内容

12 篇文档带有标签「python」

查看所有标签

AOP

Python 的切面实践:装饰器在定义时如何把函数替换成包装,上下文管理器如何保证配对释放,元类与类装饰器如何介入类创建,以及 functools.wraps、叠加顺序与猴子补丁带来的可观测性与一致性代价。

Async

Python 的异步模型:asyncio 事件循环如何调度协程与任务,TaskGroup 如何实现结构化并发,取消、超时与背压的语义边界,to_thread 如何隔离阻塞调用,以及 GIL 之下异步能解决与不能解决什么。

Concept

Python 的工程心智模型:动态强类型与鸭子类型如何决定接口,CPython 如何把源码编译成字节码、用引用计数加分代 GC 管理对象,GIL 如何限定并行,以及打包分发为何成为主要成本。

Concurrency

The GIL, threads, processes and asyncio: which execution model fits which load, how cancellation propagates, and where blocking calls and missing backpressure break a service.

Ecosystem: Dataframes

pandas and Polars: columnar memory, vectorized expressions, lazy plans and streaming, join and null semantics, and the point where a single machine stops being enough.

Ecosystem: Scripting Workflow

Turning a notebook into a parameterized and testable script: arguments and config, logging and exit codes, atomic writes, idempotent runs, validation and scheduling.

Error

Python 的错误处理:异常对象如何沿栈展开并匹配 handler,try/except/else/finally 与 with 的执行顺序,raise from 如何建立根因链,3.11 的异常组如何聚合并发失败,以及捕获、翻译与清理的边界。

Functions

Argument binding, closures and decorators, generators, context managers, the exception contract, and the gradual type system that documents all of them.

OOP

Python 的面向对象:类如何由类体执行与元类共同创建,属性查找为何先描述符后实例字典,C3 线性化如何决定 MRO 与 super 的走向,以及 dataclass、Protocol、ABC 与组合在动态分派下的分工与边界。

Syntax

Python 的语法面:35 个关键字如何划出语句边界,缩进为何是语法而不是风格,推导式、装饰器、海象运算符与 match 各自的求值规则,以及 3.8 / 3.10 / 3.11 / 3.12 的版本门槛。

Toolchain: Modules and Packaging

The import system, the src layout, pyproject build backends, wheels and sdists, and the environment and lock tools that make a resolution reproducible.

Type

How CPython compiles and executes a module, how names bind to objects, how reference counting and the cyclic GC decide a lifetime, and how protocols decide identity, equality and attribute access.