Skip to content

README "Resource Management" snippet is not valid Python: empty with bodies raise IndentationError #589

Description

@rajarshidattapy

Summary

The Resource Management code sample in README.md and README-PYPI.md cannot be run as
printed. Both with blocks in it contain only a comment, so the snippet is a syntax error.
README-PYPI.md is the readme in pyproject.toml, so this is also the project description
rendered on PyPI.

Steps to reproduce

Copy the snippet under ## Resource Management (README.md:297-321) into a file and run it, or:

python - <<'EOF'
import ast, re
code = re.search(r"```python\n(.*?)```",
                 open("README.md", encoding="utf-8").read()[
                     open("README.md", encoding="utf-8").read().find("## Resource Management"):],
                 re.S).group(1)
ast.parse(code)
EOF

Actual behavior

IndentationError: expected an indented block after 'with' statement on line 5 (line 15)

Both halves of the snippet are affected — the sync block at README.md:302 and the async block
at README.md:314:

def main():

    with OpenRouter(
        http_referer="<value>",
        x_open_router_title="<value>",
        x_open_router_categories="<value>",
        api_key=os.getenv("OPENROUTER_API_KEY", ""),
    ) as open_router:
        # Rest of application here...


# Or when using async:
async def amain():

    async with OpenRouter(
        ...
    ) as open_router:
        # Rest of application here...

A comment is not a statement, so neither with body is valid. README-PYPI.md carries a
byte-identical copy at the same line numbers.

Scope

I parsed every runnable Python snippet across README.md, README-PYPI.md, USAGE.md,
docs/overview.mdx, and docs/sdks/**/README.mdx — 119 blocks that import from openrouter.
This is the only one that fails to parse, and it fails in both READMEs. Everything else is
clean.

Fix

Adding pass after each comment makes the snippet parse — confirmed locally.

One thing to check before hand-editing: the block sits between Speakeasy's section markers,

<!-- Start Resource Management [resource-management] -->
...
<!-- End Resource Management [resource-management] -->

which is how the generator locates and replaces that section, so an edit made directly in the
README may not survive the next regeneration. README.md and README-PYPI.md are not listed
as managed files in .speakeasy/gen.lock (USAGE.md and pyproject.toml are) and are not in
.genignore either, so it is worth confirming which way it behaves — if the section is
regenerated, the fix belongs in the generator template rather than in this repo.

Environment

  • openrouter 1.1.23 (main @ cb401a8)
  • Python 3.13.6
  • Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions