Argument-Clinic / cpython

The Python programming language
https://www.python.org/
Other
1 stars 0 forks source link

Refactor `output_templates` #25

Open erlend-aasland opened 1 year ago

erlend-aasland commented 1 year ago

Fairly early in output_templates(), we've got this comment:

        # we have to set these things before we're done:
        #    
        # docstring_prototype
        # docstring_definition
        # impl_prototype
        # methoddef_define
        # parser_prototype
        # parser_definition
        # impl_definition
        # cpp_if
        # cpp_endif
        # methoddef_ifndef

Post this comment, there are a few large blocks of code where most of these "fields" are set; these blocks depend on the type of call:

  1. no args -- METH_NOARGS
  2. one positional arg -- METH_O
  3. optional groups
  4. positional only args
  5. methods/funcs with keyword args

Post these cases, most of the "fields" are set and there follows some fairly complex "post-processing" code (produce deprecation warnings, process some of the templates, and there's also some special handling for new/init methods.

We should try to refactor the five major cases in some kind of way. Perhaps a "builder class" that holds the required fields is the best approach. Perhaps "builder class" helpers for rendering Limited API fields and Internal API fields would be useful.