Skip to content

Docs: fix the target extension examples - #3861

Open
mmporong wants to merge 1 commit into
encode:masterfrom
mmporong:docs-extensions-target-examples
Open

mmporong wants to merge 1 commit into
encode:masterfrom
mmporong:docs-extensions-target-examples

Conversation

@mmporong

Copy link
Copy Markdown

Summary

The two code examples for the "target" request extension in docs/advanced/extensions.md fail when run as written.

  • They pass extensions= to the top-level httpx.get() and httpx.request() functions. Those functions (httpx/_api.py) do not take an extensions argument; only the Client methods do. Both examples raise TypeError before any request is sent.
  • The text above the second example says it builds a server-wide OPTIONS * request, but the example comment and call use CONNECT.

This PR switches both examples to client = httpx.Client() + client.get(...) / client.request(...), the same style the other examples on that page already use, and changes the second example to OPTIONS.

How I checked it: I extracted the two python blocks of the "target" section verbatim, replaced only the URL with a local TCP server, executed them with httpx 1.0.0 (installed from master), and recorded the request line the server received.

Before:

block 1: TypeError: get() got an unexpected keyword argument 'extensions'
block 2: TypeError: request() got an unexpected keyword argument 'extensions'

After:

block 1: status=200 request-line='GET /test^path HTTP/1.1'
block 2: status=200 request-line='OPTIONS * HTTP/1.1'

No other page under docs/ passes extensions= to the top-level API.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

The top-level httpx.get() and httpx.request() functions do not accept an
extensions argument, so both examples raised TypeError. Use a Client, as
the other examples on the page do, and send OPTIONS * to match the text
describing server-wide OPTIONS * requests.

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant