aio-libs / aio-libs/aiohttp

Consider making _RequestContextManager part of the public API

Đang mở
#7,247 2 bình luận 4 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
16.5k
Fork
2.4k
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
212

Mô tả

### Is your feature request related to a problem?

The problem is that `_RequestContextManager` is marked as private via its underscore prefix despite being the return value of methods like `ClientSession.get()`, `ClientSession.post()`, etc.

I understand you mainly intend for people to use these methods as async context managers in which case this type shouldn't be of any concern, but you also made it awaitable on its own and used it like that in many places in the documentation, so clearly there is *some* interface to it beyond its usage as context manager which is considered public.

Having this be a private type causes issues e.g. when writing wrappers around `ClientSession`s that just pass the objects returned by `ClientSession.get()` etc. along: As it is now, one has to either annotate the return type of the wrapper method as `_RequestContextManager`, which is formally wrong, or write a custom type stub for something that has the same signature as `_RequestContextManager`, which can be used as the return type (necessitating an extra `typing.cast()` inside the method).

### Describe the solution you'd like

I would like it if `_RequestContextManager` became `RequestContextManager` and was thereby considered part of aiohttp's public API.

Maybe the name could be changed because it's not *just* a context manager (which in a sense is my whole point - if it was, people could just consider its type `AbstractAsyncContextManager[ClientResponse]` and call it a day).

### Describe alternatives you've considered

1. Leave things as they are and have people who write wrappers come up with their own workarounds.
2. Wait for someone to write a 3rd party package that introduces a workaround, e.g. custom type stubs and instructions how to make them override aiohttp's type hints or wrappers around `aiohttp` that do nothing but change these types.

### Related component

Client

### Additional context

Faintly related: #21 (confusion that might have been averted if this type was public)

### Code of Conduct

- [X] I agree to follow the aio-libs Code of Conduct

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.