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

Fix "retry_on_error" type annotation #446

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

armicron
Copy link

When a list of classes (not instances) is assigned to RedisSettings.retry_on_error, mypy finds an error:

$ make mypy
mypy arq
arq/poc_annotations.py:5: error: List item 0 has incompatible type "type[ConnectionError]"; expected "Exception"  [list-item]
Found 1 error in 1 file (checked 13 source files)
make: *** [Makefile:46: mypy] Error 1

Redis library for the similar parameter has the type annotation Optional[List[Type[Exception]]] (source)

How to reproduce:
create a file arq/poc_annotations.py

from arq.connections import RedisSettings
from redis.exceptions import ConnectionError


settings = RedisSettings(retry_on_error=[ConnectionError])

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.47%. Comparing base (94cd878) to head (ae148a0).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #446      +/-   ##
==========================================
+ Coverage   96.27%   96.47%   +0.19%     
==========================================
  Files          11       11              
  Lines        1074     1078       +4     
  Branches      209      190      -19     
==========================================
+ Hits         1034     1040       +6     
  Misses         19       19              
+ Partials       21       19       -2     
Files Coverage Δ
arq/connections.py 89.93% <100.00%> (-0.13%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1315583...ae148a0. Read the comment docs.

@ivorpeles
Copy link

Ran into this as well, would really like to see this merged. Can further confirm that if you pass in instances mypy is satisfied but my code breaks.

Even in the test code for arq the correct types are passed, even though this isn't detected by CI:
https://github.com/samuelcolvin/arq/blob/1315583f170512fc63622af0200a2855e057a58d/tests/conftest.py#L58

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.

2 participants