Argument-Clinic / cpython

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

Params should render themselves #16

Closed erlend-aasland closed 1 year ago

erlend-aasland commented 1 year ago

Based off of python/cpython#107623

erlend-aasland commented 1 year ago

I think this is pretty neat, @AlexWaygood: fa29529c311696973b517ecd5f2c43cf613dd4e5

erlend-aasland commented 1 year ago

This looks good, but I think we should go further. format_docstring() itself also looks like it should probably be a method on Function objects rather than a method on the DSLParser. It doesn't reference any state on the DSLParser, except for attributes on self.function. (This has implications for python#107623!)

Yes, that was my plan. I figured applying this change to Parameter was a nice start, since it makes for a small proof-of-concept PR.

So, instead of self.function.docstring = self.format_docstring() in the DSLParser.do_post_block_processing_cleanup() method, it would just be self.function.format_docstring() -- the Function object would know how to format its own docstring, instead of the DSLParser object reaching in and modifying the state of the Function object.

I'm not sure yet how to refactor the generation phase. I have a proof-of-concept branch locally (I might have pushed it here, I don't remember, and I don't intend to find out before finishing writing this :) ) where I ended up with something like this in render_function():

    template_dict['docstring'] = f.render_docstring()
erlend-aasland commented 1 year ago

See gh-107790