文章目录一、dataclass + Structural Pattern Matching(3.10+)最基础的玩法经典 ADT 用法(Rust `enum` 那味儿)嵌套 + guard 才是杀手锏一个容易踩的二、`__slots__` 在 CPython 里的内存布局默认(无 slots)实例长什么样有 `__slots__` 之后发生了什么属性访问为啥也快继承链的细节(容易翻车)weakref 的小坑两段放一起的选型建议两个都讲,一个偏写法层(dataclass + match 做 ADT),一个偏底层(CPython 里__slots__到底改了啥)。一、dataclass + Structural Pattern Matching(3.10+)PEP 634–636 引入的match/case不是简单的 switch——它能解构(destructure)+ 类型检查 + 抓字段一步到位,和dataclass是天作之合。最基础的玩法fromdataclassesimportdataclass@dataclassclassPoint:x