redis / redis-py

Redis Python client
MIT License
12.4k stars 2.48k forks source link

Mark redis.asyncio as public in top-level __init__.py #3263

Open willfrey opened 4 weeks ago

willfrey commented 4 weeks ago

Pull Request check-list

Please make sure to review and check all of these items:

NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.

Description of change

The top-level __init__.py file for the package imports the asyncio sub-package (not confused with the standard library asyncio) but does not explicitly mark it as public in __all__.

https://github.com/redis/redis-py/blob/0d47d6527a10fb70f8fcfdf8df69ae3b11ec92ef/redis/__init__.py#L3 https://github.com/redis/redis-py/blob/0d47d6527a10fb70f8fcfdf8df69ae3b11ec92ef/redis/__init__.py#L58-L89

If you just import redis with the intent to use redis.asyncio, Mypy doesn't seem to care but Pyright certainly does. Pyright will treat this as an unknown symbol, which turns off a lot of developer quality-of-life features in VSCode.

import redis

# Pyright will 
r = redis.asyncio.Redis()  # reportAttributeAccessIssue:  "asyncio" is not a known attribute of module "redis" 

I did notice that there's a bare # noqa directive for the from redis import asyncio line but since it's bare, I'm not sure exactly what the directive is silencing. I considered it might be the fact that it's not re-exported but I thought it might also be because that import will shadow the standard library asyncio library and imports can get weird when you have module name collisions with the standard library.

Anyways, those are a lot of words explaining a one-line change that will save 8 characters by only needing to import redis instead of redis.asyncio every time.

If this wasn't the intent of including the from redis import asyncio line in the top-level __init__.py, feel free to close this without merging!

Thanks!