Pro Python (Modernized Knowledge Base) 🐍✨
Author: Marty Alchin | Scope: Foundational Python OOP + Modern Python 3.10–3.13+ Bridges | Chapters: 12
🧭 How to Use This Skill
- General Architectural Guidance: Query core Python OOP principles, MRO resolution, or decorator mechanics.
- Topic-Specific Retrieval: Ask about
decorators,metaclasses,__init_subclass__,protocols,descriptors,caching, orMRO; the relevant chapter file is pulled on-demand. - Direct Chapter Inspection: Request specific chapters (e.g.
ch04for Classes/MRO,ch11for Declarative CSV Framework,ch12for Modern Python 3.10–3.13 Bridge).
🧠 Core Frameworks & Mental Models
- Zen of Python (Ch 1): 19 design aphorisms (
import this, PEP 20) used as an engineering checklist. Key principles: "Errors should never pass silently", "In the face of ambiguity, refuse the temptation to guess", and "Simple is better than complex". - The Samurai Principle: Functions must raise explicit exceptions rather than returning ambiguous sentinels (e.g.
None) on failure whenNonecould be a legitimate return value. - Closures, Decorators & Type Preservation (Ch 3 & 12): Optional-argument decorator pattern (
func=None, keyword-only options) combined withfunctools.wrapsandtyping.ParamSpecfor complete runtime and static type preservation. - Method Resolution Order & Cooperative
super()(Ch 4): C3 linearization flattens multiple-inheritance graphs.super()resolves dynamically against the instance's full runtime MRO, not the defining class's parent chain in isolation. - Class Customization: Metaclasses vs
__init_subclass__(Ch 4 & 12): Use__init_subclass__(PEP 487) for clean, zero-metaclass subclass registries; reserve customtypemetaclasses for class namespace interception (__prepare__) and declarative attribute transformation. - Protocols over Inheritance (Ch 5 & 12): Combine runtime dunder implementations (
__iter__,__enter__/__exit__) with structural static subtyping (typing.Protocol+@runtime_checkable). - Object Identity,
__dict__, & Self-Caching (Ch 6 & 12): Understand identity vs value; replace manual__dict__caching patterns with@functools.cached_propertyto avoid closure memory leaks. - Explicit Encoding Discipline (Ch 7 & 12): Strict distinction between agnostic
bytestransport andstrUnicode; UTF-8 default standard throughout. - Declarative Framework Architecture (Ch 11 & 12): Build declarative models when configuration is known in advance with many instances. Modernize with
@dataclass(slots=True)andtyping.Annotated. - Modern Build Systems (Ch 10 & 12): Replace deprecated
setup.py/MANIFEST.inworkflows with standard declarativepyproject.toml(PEP 517/518/621).
📚 Chapter Index
| Chapter | Title | Core Frameworks & Concepts |
|---|---|---|
| ch01 | Principles and Philosophy | Zen of Python, DRY, Samurai Principle, Pareto & Robustness Principles |
| ch02 | Advanced Basics | try/except/else/finally, Exception Chaining, Context Managers (with), Generators |
| ch03 | Functions | *args/**kwargs, Closures, Optional-Arg Decorators, functools.partial |
| ch04 | Classes & Metaclasses | Inheritance, C3 Linearization, super(), Metaclasses, __prepare__(), Plugin Mounts |
| ch05 | Common Protocols | Operator Overloading, Comparison Protocols (__eq__ + __ne__), Iterables |
| ch06 | Object Management | Identity/Type/Value, Borg Pattern, Reference Counting, GC, Caching Properties |
| ch07 | Strings & Encodings | bytes vs str, struct binary packing, Unicode Encodings, UTF-8 |
| ch08 | Documentation | Naming discipline, Docstring conventions, reStructuredText, Sphinx |
| ch09 | Testing | doctest vs unittest.TestCase, Assertion specificity (assertEqual vs assertTrue) |
| ch10 | Distribution & Packaging | Licensing (MIT/BSD/LGPL/GPL), Packaging history, PyPI standards |
| ch11 | Sheets CSV Framework | Capstone Declarative Framework, Metaclass field registration, Instantiation ordering |
| ch12 | Modern Python Bridge (3.10–3.13+) | __init_subclass__, typing.Protocol, @functools.cached_property, ParamSpec, @dataclass(slots=True), match/case, pyproject.toml |
🗂️ Supporting References
- cheatsheet.md — Actionable decision rules, thresholds, smells, and anti-patterns.
- patterns.md — Architectural design patterns with implementation recipes and trade-offs.
- glossary.md — Definitive cross-indexed terminology dictionary.