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

Add missing type hints for retry.py #3250

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

max-muoto
Copy link
Contributor

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

Add missing type hints for the retry.py module.

redis/retry.py Outdated
backoff,
retries,
supported_errors=(ConnectionError, TimeoutError, socket.timeout),
backoff: AbstractBackoff,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should AbstractBackoff be quoted here, when using if TYPE_CHECKING?

Tbh, it feels cleaner to just import AbstractBackoff always, it should not be a performance penalty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, went ahead and quoted it: 1660336

It would be nicer to quote, just to avoid an unnecessary import which would slow down module init time.

redis/retry.py Outdated
supported_errors=(ConnectionError, TimeoutError, socket.timeout),
backoff: AbstractBackoff,
retries: int,
supported_errors: tuple[type[Exception], ...] = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We support Python 3.8, where this is not yet available. You can use Tuple[Type[Exception], ...] and import them from typing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, good catch!

redis/retry.py Outdated
@@ -24,15 +34,21 @@ def __init__(
self._retries = retries
self._supported_errors = supported_errors

def update_supported_errors(self, specified_errors: list):
def update_supported_errors(
self, specified_errors: Iterable[type[Exception]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about supporting Python 3.8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@max-muoto
Copy link
Contributor Author

@gerzse Comments should be addressed.

@gerzse
Copy link
Collaborator

gerzse commented Jun 14, 2024

@gerzse Comments should be addressed.

Thanks @max-muoto !

Getting picky now, but I run

mypy --python-version=3.8 redis/retry.py tests/test_retry.py tests/test_asyncio/test_retry.py

and it complains about BackoffMock class in the sync tests not being compatible with AbstractBackoff. Inheriting from AbstractBackoff, like in the async test should fix this.

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

2 participants