Skip to content

Should await asyncpg.create_pool() return Pool instead of None | Pool #120

@sbdchd

Description

@sbdchd

Thank you for the library!

After setting this up I found that my connection pool logic is being flagged

essentially I have:

connection_pool: asyncpg.Pool[asyncpg.Record]

def on_startup() -> None:
    global connection_pool
    connection_pool = await asyncpg.create_pool()

and I get an error:

Incompatible types in assignment (expression has type "Optional[Pool[Record]]", variable has type "Pool[Record]")  [assignment] mypy(error)

looking at Asyncpg's pool:

https://github.com/MagicStack/asyncpg/blob/40b16ea65f8b634a392e7e5b6509ee7dda45c4cd/asyncpg/pool.py#L978-L979

I think technically it can return None but it seems unlikely to happen for most use cases (maybe?)

so while Pool | None represents a possible case, I think it would be okay if it didn't include it in the types for better ergonomics

What do you think?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions