31.05.19 11:46, Petr Viktorin пише:
PEP 570 (Positional-Only Parameters) changed the signatures of PyCode_New() and types.CodeType(), adding a new argument for "posargcount". Our policy for such changes seems to be fragmented tribal knowledge. I'm writing to check if my understanding is reasonable, so I can apply it and document it explicitly.
There is a surprisingly large ecosystem of tools that create code objects. The expectation seems to be that these tools will need to be adapted for each minor version of Python.
I have a related proposition. Yesterday I have reported two bugs (and Pablo quickly fixed them) related to handling positional-only arguments. These bugs were occurred due to subtle changing the meaning of co_argcount. When we make some existing parameters positional-only, we do not add new arguments, but mark existing parameters. But co_argcount now means the only number of positional-or-keyword parameters. Most code which used co_argcount needs now to be changed to use co_posonlyargcount+co_argcount.
I propose to make co_argcount meaning the number of positional parameters (i.e. positional-only + positional-or-keyword). This would remove the need of changing the code that uses co_argcount.
As for the code object constructor, I propose to make posonlyargcount an optional parameter (default 0) added after existing parameters. PyCode_New() can be kept unchanged, but we can add new PyCode_New2() or PyCode_NewEx() with different signature.