Metaprogramming in Python
summary
Shows practical Python 3.4 metaprogramming tools: decorators, metaclasses and a bit on descriptors. Demonstrates using functools.wraps and inspect.signature to implement annotation-based runtime type checks, a parametrizable decorator built with functools.partial and nonlocal to toggle behavior, and a metaclass that overrides __prepare__ to return an OrderedDict to enforce attribute-before-method order; includes live examples, notes on complexity, and a small metaclass-based perf-testing framework.
AI-written summary · about
chapters (18)
- 0:00Introduction
- 1:09What is metaprogramming
- 3:14Functions as objects
- 3:57Basic decorators
- 5:48Metadata maintenance
- 8:19Decorator chaining
- 9:22Generic function types
- 11:28Python 3 type hints
- 14:22Type validation decorator
- 17:12Optional args decorators
- 19:22Avoiding parentheses
- 21:11Runtime decorator changes
- 23:42Metaprogramming warning
- 24:25Metaclasses intro
- 26:13Metaclasses and type
- 27:44Custom metaclass
- 29:09Attribute order control
- 31:35Q&A
related talks
29mMetaprogramming with Decorators, Metaclasses, and Dynamic Code Generation
30mThe Wizardry of Metaprogramming
21mEnhancing Decorators with Type Annotations: Techniques and Best Practices
02h 15mAll about decorators
01h 10mIt's Pythons All The Way Down: Python Types & Metaclasses Made Simple
02h 21mIntroduction to Decorators: Power Up Your Python Code
21mMeta: Enabling Programming Languages to Learn from the Crowd
02h 32mIntroduction to Decorators: Power UP Your Python Code
