Added feature to utilize Python syntax for field comments in schema#245
Added feature to utilize Python syntax for field comments in schema#245rohankalbag wants to merge 3 commits intomicrosoft:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
|
Thanks for the PR on this - I'm not so sure that I think that regular expressions are the right approach on this one, since they can have unrelated modifications in source code. Nor do I feel entirely comfortable The idea of replacing the source text and re-exec-ing is one I hadnt thought of - I don't know if it's the right one in general though. When I was originally thinking about how this could work, the idea I had was to use the ast module to accurately identify the appropriate attribute, and the tokenize modules to grab the subsequent comment (though |
|
Thanks for your valuable suggestions @DanielRosenwasser. Have implemented a more robust This implementation now utilizes Have tested it on the example used earlier through another implementation script Again, for the |
|
I'm sorry, but in the end I feel that this approach is too brittle to build into TypeChat itself. Maybe it could be turned into a CLI tool that does a one-time conversion of a schema with comments to a schema with Annotated...Doc... |
|
Thanks @gvanrossum for your inputs. As suggested by you, I have separated the source code transformation from the TypeChat src. Instead a utility for the one-time-conversion exposing a user friendly CLI has been created in In addition to this, I noticed that previously I hadn't handled the fields being enclosed by Few python field commented schema examples have been added in python3 python_comment_handler.py -i examples/commented_restaurant_schema.py -o transformed_schema.py -d |
…nstead of verbose Annotated[Doc()]-based comment style. Currently implemented for examples/math
…e robust field comment handling
…parate CLI utility for schema pythonic comment handling
|
@DanielRosenwasser @gvanrossum, does the above proposed solution implement the required feature and address issue #242, kindly suggest changes if any and approve the PR |
Attempt at resolving #242, added feature to utilize Python comment syntax instead of currently supported verbose
Annotated[Doc()]-based comment style. The feature is currently implemented forexamples/mathbut can be extended to other examples as the new_convert_pythonic_comments_to_annotated_docsmethod is added totypechat.TypeChatJsonTranslator.The feature as suggested, attempts to scan the source code using regular expressions and inserts
Annotated[Doc()]for the corresponding commented schema field (_convert_pythonic_comments_to_annotated_docsmethod), the original pythonic comments are maintained since they are harmless, but can be removed further if needed.Also added a simple example schema in
examples/math(schema_with_comments.py) and a simple implementation scriptpythonic_comment_handling.pyshowing POC. If thedebugflag is set to True, the schema file before and after processing can be seenFor example for the
schema_with_comments.pyexample, the following debug output can be obtained by runningpythonic_comment_handling.py@gvanrossum @DanielRosenwasser