MagicStack / MagicStack/asyncpg
Value yielded by PoolAcquireContext is mistyped by IDEs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.1k
- Forks
- 468
- PR merge metrics
- No merged PRs in 30d
Description
- asyncpg version: 0.21.0
- PostgreSQL version: 12.5
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: No - Python version: 3.9.1
- Platform: Windows 10
- Do you use pgbouncer?: No
- Did you install asyncpg with pip?: Yes
- If you built asyncpg locally, which version of Cython did you use?: N/A
- Can the issue be reproduced under both asyncio and
uvloop?: N/A
Using PyCharm Professional 2020.2 by JetBrains, the typing of conn is interpreted incorrectly in the following expression:
pool = await asyncpg.create_pool('postgres://...')
async with pool.acquire() as conn:
await conn.execute(...)
Expected: asyncpg.Connection
Observed: typing.Any
Suggested remedy: Explicitly type PoolAcquireContext.connection as typing.Optional[Connection] and/or explicitly type PoolAcquireContext.pool as Pool.
Caveat: The suggestions above will break compatibility with Python 3.4, which reached end of life in March 2019.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the PoolAcquireContext type definitions and reproduce the pool.acquire() example in PyCharm to inspect the inferred type of conn. Compare the annotations for connection and pool with the stated expected asyncpg.Connection type, while checking the Python 3.4 compatibility caveat. Done means the IDE infers conn correctly without dropping supported compatibility.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100