Closed erlend-aasland closed 1 year ago
I think this is pretty neat, @AlexWaygood: fa29529c311696973b517ecd5f2c43cf613dd4e5
This looks good, but I think we should go further.
format_docstring()
itself also looks like it should probably be a method onFunction
objects rather than a method on theDSLParser
. It doesn't reference any state on theDSLParser
, except for attributes onself.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 theDSLParser.do_post_block_processing_cleanup()
method, it would just beself.function.format_docstring()
-- theFunction
object would know how to format its own docstring, instead of theDSLParser
object reaching in and modifying the state of theFunction
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()
See gh-107790
Based off of python/cpython#107623