Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 6 commits into from

Conversation

willfrey
Copy link
Contributor

@willfrey willfrey commented Jun 5, 2024

Pull Request check-list

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

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?
  • Was the change added to CHANGES file?

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__.

from redis import asyncio # noqa

__all__ = [
"AuthenticationError",
"AuthenticationWrongNumberOfArgsError",
"BlockingConnectionPool",
"BusyLoadingError",
"ChildDeadlockedError",
"Connection",
"ConnectionError",
"ConnectionPool",
"CredentialProvider",
"DataError",
"from_url",
"default_backoff",
"InvalidResponse",
"OutOfMemoryError",
"PubSubError",
"ReadOnlyError",
"Redis",
"RedisCluster",
"RedisError",
"ResponseError",
"Sentinel",
"SentinelConnectionPool",
"SentinelManagedConnection",
"SentinelManagedSSLConnection",
"SSLConnection",
"UsernamePasswordCredentialProvider",
"StrictRedis",
"TimeoutError",
"UnixDomainSocketConnection",
"WatchError",
]

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!

@willfrey willfrey changed the title Mark redis.asyncio as public in top-level \_\_init\_\_.py Mark redis.asyncio as public in top-level __init__.py Jun 5, 2024
@willfrey
Copy link
Contributor Author

I'm closing this PR due to inactivity over the past couple of months. It's a really minor change, so if you want to re-open and merge this at a later time, please feel free!

@willfrey willfrey closed this Aug 12, 2024
@willfrey willfrey deleted the patch-1 branch August 12, 2024 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant