Skip to content

make async with < 3.10 compatible#11

Open
jacobbednarz wants to merge 4 commits intomainfrom
make-async-lt-3.10-compatible
Open

make async with < 3.10 compatible#11
jacobbednarz wants to merge 4 commits intomainfrom
make-async-lt-3.10-compatible

Conversation

@jacobbednarz
Copy link

With the commit builder, the SDK uses parenthesized async with syntax.
Example:

async with (
      httpx.AsyncClient() as client,
      client.stream(...) as response,
  ):

This syntax is only valid in Python 3.10+. However, pyproject.toml
declared requires-python >= 3.9.

So on Python 3.9, the entire commit module would fail to
import with a SyntaxError at startup making it completely unusable
despite the package claiming 3.9 support.

Updating this syntax allows it to be compatible all the way back to 3.1.


Alternatively, if we'd rather push 3.10+ we can also update the
pyproject.toml to reflect that instead.

With the `commit` builder, the SDK uses parenthesized `async with` syntax.
Example:

```
async with (
      httpx.AsyncClient() as client,
      client.stream(...) as response,
  ):
```

This syntax is only valid in Python 3.10+. However, `pyproject.toml`
declared `requires-python >= 3.9`.

So on Python 3.9, the entire `commit` module would fail to
import with a `SyntaxError` at startup making it completely unusable
despite the package claiming 3.9 support.

Updating this syntax allows it to be compatible all the way back to 3.1.
@jacobbednarz jacobbednarz requested a review from fat March 3, 2026 03:14
@jacobbednarz
Copy link
Author

i suspect this break came from the ruff check

$ uv run ruff check pierre_storage

SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
   --> pierre_storage/commit.py:392:9
    |
390 |           }
391 |
392 | /         async with httpx.AsyncClient() as client:
393 | |             async with client.stream(
394 | |                 "POST",
395 | |                 self.url,
396 | |                 headers=headers,
397 | |                 content=self._build_request_body(metadata),
398 | |                 timeout=180.0,
399 | |             ) as response:
    | |__________________________^
400 |                   if not response.is_success:
401 |                       error_info = await _parse_commit_error(response, "createCommit")
    |
help: Combine `with` statements

SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements
   --> pierre_storage/commit.py:492:5
    |
490 |       url = f"{base_url.rstrip('/')}/api/v{api_version}/repos/diff-commit"
491 |
492 | /     async with httpx.AsyncClient() as client:
493 | |         async with client.stream(
494 | |             "POST",
495 | |             url,
496 | |             headers=headers,
497 | |             content=request_stream(),
498 | |             timeout=180.0,
499 | |         ) as response:
    | |______________________^
500 |               if not response.is_success:
501 |                   error_info = await _parse_commit_error(response, "createCommitFromDiff")
    |
help: Combine `with` statements

Found 2 errors.
[*] 2 fixable with the `--fix` option.

will see what we have do do in order to prevent regressing again.

Enabling SIM117 wants to simplify the context management however, it
breaks compatibility on < 3.10 for the `async with` usage.
Copy link
Contributor

@imownbey imownbey left a comment

Choose a reason for hiding this comment

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

Assuming it’s backwards compatible with the old sdk methods sounds fire

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.

3 participants