Conversation
i really dont know how this should be done
598 asyncio codegen
|
should we disable the mccabe complexity check again? It promotes smaller functions as a principle of "clean code" but I'm not sure if it's actually helpful to make it a grounded requirement for the whole codebase. idk |
|
Sorry for the weird implementation of comments, the ast library does not support comment creation :/ |
|
the current failure is not because of mccabe complexity |
|
I might rewrite the comment thingy with libcst or something |
This comment was marked as off-topic.
This comment was marked as off-topic.
| ## Dynamic checking | ||
|
|
||
| You can declare a variable `IS_ASYNC` like so (recommended to be in global scope): | ||
| ```python | ||
| IS_ASYNC = True | ||
| ``` | ||
| It will be `True` in the async code and `False` in the sync code. This can be used to check dynamically where you currently are. |
There was a problem hiding this comment.
I don't quite understand. If I set it to True like in the example, will the codegen change its value? So the IS_ASYNC = True is only a placeholder for valid syntax? So I could do something like this:
IS_ASYNC = True#line1
print(IS_ASYNC)#line2In the sync impl, this would actually print False, and in the async impl it prints True?
Does the replace the value on line1 with True/False or does it replace the usage of it on line2?
There was a problem hiding this comment.
Ok, I need to rewrite this part. It sets all assignments to the variable to False in the sync path and nothing else.
| ### `"IS_PRE_CODEGEN"` | ||
|
|
||
| If you use exactly `"IS_PRE_CODEGEN"` as a condition (and nothing else) in an if, if else or if elif else statement, only paths with it being false will be included in the async and sync code. | ||
|
|
||
| Example: | ||
|
|
||
| ```python | ||
| if "IS_PRE_CODEGEN": | ||
| import requests | ||
| import aiohttp | ||
| else: | ||
| if "IS_ASYNC": | ||
| import aiohttp | ||
| else: | ||
| import requests | ||
| ``` | ||
|
|
||
| Codegen will turn this into (respectively async and sync): | ||
|
|
||
| ```python | ||
| import aiohttp | ||
| ``` | ||
| and | ||
| ```python | ||
| import requests | ||
| ``` |
There was a problem hiding this comment.
Is this to satisfy language servers/type checkers when they check your imports?
There was a problem hiding this comment.
Yes, I should probably clarify that
| [project] | ||
| name = "codegen" | ||
| version = "0.1.0" | ||
| description = "Add your description here" | ||
| readme = "README.md" | ||
| requires-python = ">=3.12.12" | ||
| dependencies = ["ruff", "libcst"] |
There was a problem hiding this comment.
This project directory should probably be added to Dependabot
|
Not sure if this is helpful, but there is a way to use typeddicts for kwargs using |
|
The site directory is currently mostly unimplemented. |
I am aware but the typeddicts for requests' request methods are not exposed. |
Is the codegen system good enough that implementation |
partial core implementation of session.py
Solves issue #438
Any asyncio development should be made as a PR into the
asynciobranch. Once the asyncio implementation is satisfactory, this PR will be finally made ready for review and merged. Avoid pushing toasynciodirectlyChanges
This PR will (would?) implement an architectural change to scratchattach which allows for an single async implementation with codegen or some other method to generate a synchronous api for general use.
Tests
Currently none. Probably will use names like
test_async_whatever.pyintests/