Skip to content

asyncio#599

Draft
faretek1 wants to merge 37 commits into
mainfrom
asyncio
Draft

asyncio#599
faretek1 wants to merge 37 commits into
mainfrom
asyncio

Conversation

@faretek1
Copy link
Copy Markdown
Collaborator

@faretek1 faretek1 commented May 7, 2026

Solves issue #438

Any asyncio development should be made as a PR into the asyncio branch. Once the asyncio implementation is satisfactory, this PR will be finally made ready for review and merged. Avoid pushing to asyncio directly

Changes

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.py in tests/

@faretek1 faretek1 linked an issue May 7, 2026 that may be closed by this pull request
@faretek1
Copy link
Copy Markdown
Collaborator Author

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

@TheCommCraft
Copy link
Copy Markdown
Collaborator

Sorry for the weird implementation of comments, the ast library does not support comment creation :/

@TheCommCraft
Copy link
Copy Markdown
Collaborator

the current failure is not because of mccabe complexity

@TheCommCraft
Copy link
Copy Markdown
Collaborator

I might rewrite the comment thingy with libcst or something

@TheCommCraft

This comment was marked as off-topic.

Comment thread codegen/features.md
Comment on lines +9 to +15
## 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.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)#line2

In 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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I need to rewrite this part. It sets all assignments to the variable to False in the sync path and nothing else.

Comment thread codegen/features.md
Comment thread codegen/features.md
Comment on lines +42 to +67
### `"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
```
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to satisfy language servers/type checkers when they check your imports?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should probably clarify that

Comment thread codegen/pyproject.toml
Comment on lines +1 to +7
[project]
name = "codegen"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12.12"
dependencies = ["ruff", "libcst"]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project directory should probably be added to Dependabot

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@faretek1
Copy link
Copy Markdown
Collaborator Author

faretek1 commented May 22, 2026

Not sure if this is helpful, but there is a way to use typeddicts for kwargs using typing.Unpack[]

@TheCommCraft
Copy link
Copy Markdown
Collaborator

The site directory is currently mostly unimplemented.

@TheCommCraft
Copy link
Copy Markdown
Collaborator

Not sure if this is helpful, but there is a way to use typeddicts for kwargs using typing.Unpack[]

I am aware but the typeddicts for requests' request methods are not exposed.

@faretek1
Copy link
Copy Markdown
Collaborator Author

faretek1 commented May 22, 2026

The site directory is currently mostly unimplemented.

Is the codegen system good enough that implementationof e.g.Session, User` is now ready to be done? If so, I can help with the 'menial tasks' if you can show me the intended ways to use the codegen by making a start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio

2 participants