Skip to main content

All in one retry and aioretry decorators

Project description

KaioRetry

PyPI version Supported Python Version License PyPI - Downloads

Pylint Static Quality Github Action Mypy Static Quality Github Action Pylint Static Quality Github Action Documentation Status

KaioRetry is (yet another) retry decorator implementation, which is clearly inspired by the original retry module and is actually backward compatible with it.

Basic usage

Transparently perform retries on failures:

from kaioretry import retry, aioretry


@retry(exceptions=ValueError, tries=2)
def some_func(...):
    ...


@aioretry(exceptions=(ValueError, SomeOtherError), tries=-1, delay=1)
async def some_coroutine(...):
    ...

Documentation

If you care to read more, a more lengthy documentation is available on readthedocs.

Known Issues

Pylint

Pylint, it seems, is not really good a detecting decorators that change function signatures, and kaioretry defines and uses a lot of decorators (relatively speaking).

This means that such basic code:

from kaioretry import aioretry

@aioretry(exceptions=ZeroDivisionError)
async def func(x, y):
    return x / y

Will trigger the following pylint errors:

E1120: No value for argument 'retry_obj' in function call (no-value-for-parameter)

According to pylint documentation, the only way to widely work around this issue is to use the signature-mutators feature of pylint. This can be done either on the command line:

pylint --signature-mutators=kaioretry._make_decorator

Or through pylint configuration file:

# The TYPECHECK section accepts a signature-mutators directive.
[TYPECHECK]

# List of decorators that change the signature of a decorated function.
signature-mutators=kaioretry._make_decorator

(Of course, you can inline a # pylint: disable=no-value-for-parameter comment on all aioretry() and retry() call lines, and it can be good enough to disable a one-time warning, but repeating that line can be tedious. The signature-mutators directive will globally disable the signature-checking for aioretry() and retry() calls, so this can be easier depending of your own usage of kaioretry.)

Mypy and functions generated by kaioretry.aioretry

Mypy may incorrectly infer the type of an aioretry-decorated function as def (*Any, **Any) -> Any if the original function:

  1. is a coroutine and
  2. has a returned type hinted as Any and/or if parameters are hinted as Any.

If the original function is fully annotated as non-Any, the resulting decorated function annotations should be correctly inferred (according to kaioretry test).

It is unclear to me right now, if the kaioretry.aioretry function type hints are incorrect or if it is an issue with either mypy or cpython. Or both. Or all 3. Go figure.

Any information on that matter would be greatly appreciated. I've spent weeks trying to track down this issue. And while walking down this path has allowed me to fix some other (rather unrelated) type-hinting boo-boos from my part, this very specific issue is still puzzling me.

Feedback welcome.

Always.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaioretry-1.1.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kaioretry-1.1.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file kaioretry-1.1.0.tar.gz.

File metadata

  • Download URL: kaioretry-1.1.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/6.12.9-200.fc41.x86_64

File hashes

Hashes for kaioretry-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d493795fa785bb78bf56d8ca03246afcb7a0204d7f08cfe9986d4071f26728d1
MD5 ca91138461e84080dfd51e064f021bab
BLAKE2b-256 1175ca95bae46df083d49603d501838cbe93480b66855cd261633e415047f2a1

See more details on using hashes here.

File details

Details for the file kaioretry-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: kaioretry-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/6.12.9-200.fc41.x86_64

File hashes

Hashes for kaioretry-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db8ae72fb4e6d0c1520fca0477db3a00142586cd4c603f74afe9630d3d0c6f6f
MD5 067641bf6f9388dd84cb3d58f725f8e1
BLAKE2b-256 2b4f9344389ff7a35de36cd9cf8d80ebb7610bd265b3fad14590e8f4041f6e95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page