On 1/12/21 11:27 PM, Chris Angelico wrote:
The language can also be defined in an optimization-friendly way,
though. Consider how we got positional-only arguments in Python: first
they existed in C-implemented functions in CPython, even though they
couldn't exist in pure Python code, and then the functionality got
added to the language definition, thus permitting the optimization.

I wouldn't describe positional-only parameters as an "optimization".  They were created to add expressiveness to Python code, not to make Python code faster.  The classic example is the dict constructor: technically, you couldn't implement it correctly in pure Python code, because it had a parameter (the iterable) that could not be a named parameter.  Any name you gave it would preclude passing in that name as a name=value argument.

Parsing positional-only parameters is often faster than parsing named parameters, for obvious reasons.  But this is really small stuff, drowned out by almost any other variation in your code.


Cheers,


/arry