Consider making _RequestContextManager part of the public API
- 主要语言
- Python
- 星标
- 16.5k
- 派生
- 2.4k
- 平均合并
- 17 小时 22 分钟
- 30 天内合并 PR
- 212
描述
### 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
贡献指南
评估
这个 Issue 还没有评估数据。