4.3 Converting functions using PyArg_UnpackTuple 4.4 Optional Groups 10 To convert a function parsing its arguments with$_{PyArg_UnpackTuple()}$ , simply write out all the arguments, specifying each as an$_{object}$. You may specify the$_{type}$argument to cast the type as appropriate. All arguments should be marked positional-only (add a / on a line by itself after the last argument). Currently the generated code will use$_{PyArg_ParseTuple()}$ , but this will change soon. Some legacy functions have a tricky approach to parsing their arguments: they count the number of positional argu- ments, then use a switch statement to call one of several different PyArg_ParseTuple() calls depending on how many positional arguments there are. (These functions cannot accept keyword-only arguments.) This approach was used to simulate optional arguments back before$_{PyArg_ParseTupleAndKeywords()}$ was created. While functions using this approach can often be converted to use PyArg_ParseTupleAndKeywords() , optional arguments, and default values, it’s not always possible. Some of these legacy functions have behaviors PyArg_ParseTupleAndKeywords() doesn’t directly support. The most obvious example is the builtin func- tion range() , which has an optional argument on the left side of its required argument! Another example is curses.window.addch() , which has a group of two arguments that must always be specified together. (The arguments are called x and y ; if you call the function passing in x , you must also pass in y —and if you don’t pass in $_{x}$you may not pass in$_{y}$ either.) In any case, the goal of Argument Clinic is to support argument parsing for all existing CPython builtins without changing their semantics. Therefore Argument Clinic supports this alternate approach to parsing, using what are called optional groups . Optional groups are groups of arguments that must all be passed in together. They can be to the left or the right of the required arguments. They can only be used with positional-only parameters. Note: Optional groups are only intended for use when converting functions that make multiple calls to PyArg_ParseTuple() ! Functions that use any other approach for parsing arguments should almost never be converted to Argument Clinic using optional groups. Functions using optional groups currently cannot have accu- rate signatures in Python, because Python just doesn’t understand the concept. Please avoid using optional groups wherever possible. To specify an optional group, add a$_{[}$ on a line by itself before the parameters you wish to group together, and a$_{]}$ on a line by itself after these parameters. As an example, here’s how$_{curses.window.addch}$ uses optional groups to make the first two parameters and the last parameter optional: /*[clinic input] curses.window.addch [ x: int X-coordinate. y: int Y-coordinate. ] ch: object Character to add. [ attr: long Attributes for the character. ] / ...