Loading topic
type(obj) returns the class of obj. Here you will use the three-argument form6 min readsuper(), and write simple decorators. It also assumes you know what **kwargs does. By the end you will be able to list, in order, every step Python takes between the word class and the name being bound in your modul6 min readsuper() in methods, and use **kwargs. It also assumes you know that a class is an object and that type(name, bases, namespace) builds one. You don't need to know metaclasses yet. __init_subclass__ exists so that ma6 min readsuper(), and write functions that take **kwargs. It also assumes you know the earlier chapter's __init_subclass__ hook, which runs on a parent class each time a subclass is defined. Here you will see how the extra keyword ar5 min readsuper(). It also assumes you have seen the descriptor protocol (__get__, __set__) at least once. The earlier chapters covered what a class statement does and how __init_subclass__ hooks into subclass creation. Here you will see h6 min read@deco above a def means f = deco(f), and have seen __init_subclass__ in the earlier chapters. A class decorator uses the same idea on a class. For many jobs it is the lightest tool you can pick, because it needs no metaclass 5 min readtype passed with metaclass=). It also assumes you know what a class statement does: it runs the body in a namespace, then calls the metaclass. You should be comfortable with super() and **kwargs.5 min readclass statement becomes a call to a metaclass, and that you have written a basic metaclass with __new__. It covers __prepare__, the one hook that runs before the class body does.5 min readsuper(). It also assumes you know that a class statement ends in a call to a metaclass, as covered in the earlier chapters on type() and writing a first metaclass. Here you will learn how Python decides which metaclass to use, why that decision5 min readclass statement becomes a call to type, and that you have seen __init_subclass__, __set_name__, class decorators and a basic metaclass. Here you will compare them. The goal is a repeatable way to pick the lightest tool that solves a problem, and to recogni6 min read