4.14 Using a “self converter” Argument Clinic automatically adds a “self” parameter for you using a default converter. It automatically sets the $_{type}$of this parameter to the “pointer to an instance” you specified when you declared the type. However, you can override Argument Clinic’s converter and specify one yourself. Just add your own self parameter as the first parameter in a block, and ensure that its converter is an instance of self_converter or a subclass thereof. What’s the point? This lets you override the type of self , or give it a different default name. How do you specify the custom type you want to cast self to? If you only have one or two functions with the same type for self , you can directly use Argument Clinic’s existing self converter, passing in the type you want to use as the$_{type}$parameter: /*[clinic input] _pickle.Pickler.dump self: self(type="PicklerObject *") obj: object / Write a pickled representation of the given object to the open file. [clinic start generated code]*/ /*[python input] class PicklerObject_converter(self_converter): type = "PicklerObject *" [python start generated code]*/ /*[clinic input] _pickle.Pickler.dump self: PicklerObject obj: object / Write a pickled representation of the given object to the open file. [clinic start generated code]*/ On the other hand, if you have a lot of functions that will use the same type for$_{self}$, it’s best to create your own converter, subclassing$_{self_converter}$ but overwriting the$_{type}$member: As we hinted at in the previous section… you can write your own converters! A converter is simply a Python class that inherits from$_{CConverter}$. The main purpose of a custom converter is if you have a parameter using the$_{O&}$ format unit—parsing this parameter means calling a$_{PyArg_ParseTuple()}$ “converter function”. Your converter class should be named$_{*something*_converter}$ . If the name follows this convention, then your converter class will be automatically registered with Argument Clinic; its name will be the name of your class with the$_{_converter}$ suffix stripped off. (This is accomplished with a metaclass.) You shouldn’t subclass CConverter.__init__ . Instead, you should write a converter_init() func- tion. converter_init() always accepts a $_{self}$parameter; after that, all additional parameters must be keyword-only. Any arguments passed in to the converter in Argument Clinic will be passed along to your converter_init() . There are some additional members of$_{CConverter}$you may wish to specify in your subclass. Here’s the current list: 17 4.15 Writing a custom converter