Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# `blocking-http-call-in-async-function` (`ASYNC210`)

```toml
lint.select = ["ASYNC210"]
```

## Generic request functions

The generic `requests.request` and `httpx.request` functions block just like the method-specific
helpers such as `get`. Imported aliases have the same behavior.

```py
import httpx
import requests
from httpx import request as httpx_request
from requests import request as requests_request

async def fetch(url):
requests.get(url) # error: [blocking-http-call-in-async-function]
requests.request("GET", url) # error: [blocking-http-call-in-async-function]
requests_request("GET", url) # error: [blocking-http-call-in-async-function]
httpx.get(url) # error: [blocking-http-call-in-async-function]
httpx.request("GET", url) # error: [blocking-http-call-in-async-function]
httpx_request("GET", url) # error: [blocking-http-call-in-async-function]
```

## Synchronous functions

The rule only checks calls in async contexts.

```py
import httpx
import requests

def fetch(url):
requests.request("GET", url)
httpx.request("GET", url)
```

## Shadowed module names

Parameters named `requests` and `httpx` do not refer to the imported libraries.

```py
import httpx
import requests

async def custom_client(requests, httpx, url):
requests.request("GET", url)
httpx.request("GET", url)
```

## Requests dispatched to a worker thread

Passing the request functions to `asyncio.to_thread` does not block the event loop.

```py
import asyncio
import httpx
import requests

async def fetch_in_thread(url):
await asyncio.to_thread(requests.request, "GET", url)
await asyncio.to_thread(httpx.request, "GET", url)
```
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ fn is_blocking_http_call(qualified_name: &QualifiedName) -> bool {
| ["urllib3", "request"]
| [
"httpx" | "requests",
"get"
"request"
| "get"
| "post"
| "delete"
| "patch"
Expand Down
Loading