Conversation
.cross_sync/generate.py
Outdated
| self.tree = ast_tree | ||
| self.header = header or "" | ||
|
|
||
| def render(self, with_black=True, save_to_disk: bool = False) -> str: |
There was a problem hiding this comment.
should we default save_to_disk to true?
There was a problem hiding this comment.
I said no, because we also use this function as part of tests later, to compare to make sure the current outputs are up to date. In that case, we'd want to see the output without writing it. But I'm fine either way
There was a problem hiding this comment.
I think a user of the library will want to set this to true, and we can override it for testing, let's make it default to true?
eda59d4 to
54e3007
Compare
| if new_mapping: | ||
| CrossSync.add_mapping(new_mapping, cls) | ||
| if self.async_docstring_format_vars: | ||
| cls.__doc__ = cls.__doc__.format(**self.async_docstring_format_vars) |
There was a problem hiding this comment.
what does this do? why is this only formatting async_docstring? How about sync_docstring?
There was a problem hiding this comment.
CrossSync allows you to add variables into docstrings, and then it will replace them with a different string for sync vs async. This came up because some async methods raise exceptions when run outside of an event loop context, but that doesn't apply to sync versions. So the docstrings are mostly the same, but with an extra little note for async
On the sync side, we can replace the variables when generating the sync file. On the async side, we update the __doc__ attribute of the class as part of the class decoration process. The code itself will have template variables when you read it directly, but docs generators will read from class.__doc__ when generating content, so it will render as expected
PR 1/x for adding the sync surface for the new data client
This class adds ast transformers for converting existing async classes into sync copies.
The conversion works through the following phases:
generate.pyis called with a path, and finds all Python files in all subdirectoriesCrossSyncClassDecoratorHandleris called on each file, looking for any classes decorated with@CrossSync.export_syncCrossSyncMethodDecoratorHandlerto look for any methods annotated with CrossSync decorators (CrossSunc.convert,CrossSync.drop_method,CrossSync.pytest, etc).RmAioFunctionsto strip out any asyncio keywords annotated withCrossSync.rmaio()SymbolReplacerto replaceCrossSyncwithCrossSync._Sync_Implin the codebase, and other user-specified symbol transformatioonsNext PR will add annotations to existing code to guide transformations