Skip to content

Commit

Permalink
test type annotations with mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
terencehonles committed Sep 3, 2024
1 parent d5e55ab commit ec0a85a
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 182 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,25 @@ jobs:
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
fail_ci_if_error: false
fail_ci_if_error: false

mypy:
runs-on: ubuntu-latest
name: Type check

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.7
uses: actions/[email protected]
with:
python-version: "3.7"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Run Test
run: |
hatch run test:typing
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,38 @@ include = [
dependencies = [
"black",
"coverage",
"mypy",
"packaging",
"psutil",
"pytest",
"pytest-cov",
"ruff",
"tox",
"types-greenlet",
"types-redis",
]
[tool.hatch.envs.test.scripts]
cov = "pytest --cov=rq --cov-config=.coveragerc --cov-report=xml {args:tests}"
typing = "mypy --enable-incomplete-feature=Unpack rq"

[tool.black]
line-length = 120
target-version = ["py38"]
skip-string-normalization = true

[tool.mypy]
allow_redefinition = true
pretty = true
show_error_codes = true
show_error_context = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true

[[tool.mypy.overrides]]
module = "setproctitle.*"
ignore_missing_imports = true

[tool.ruff]
# Set what ruff should check for.
# See https://beta.ruff.rs/docs/rules/ for a list of rules.
Expand Down
4 changes: 2 additions & 2 deletions rq/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def worker_pool(
setup_loghandlers_from_args(verbose, quiet, date_format, log_format)

if serializer:
serializer_class: Type[DefaultSerializer] = import_attribute(serializer)
serializer_class: Type[DefaultSerializer] = import_attribute(serializer) # type: ignore[assignment]
else:
serializer_class = DefaultSerializer

Expand All @@ -479,7 +479,7 @@ def worker_pool(
logging_level = None

pool = WorkerPool(
queue_names,
queue_names, # type: ignore[arg-type]
connection=cli_config.connection,
num_workers=num_workers,
serializer=serializer_class,
Expand Down
2 changes: 1 addition & 1 deletion rq/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def parse_payload(payload: Dict[Any, Any]) -> Dict[Any, Any]:
Args:
payload (dict): Parses the payload dict.
"""
return json.loads(payload.get('data').decode())
return json.loads(payload['data'].decode())


def send_shutdown_command(connection: 'Redis', worker_name: str):
Expand Down
2 changes: 1 addition & 1 deletion rq/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Group:
REDIS_GROUP_NAME_PREFIX = 'rq:group:'
REDIS_GROUP_KEY = 'rq:groups'

def __init__(self, connection: Redis, name: str = None):
def __init__(self, connection: Redis, name: Optional[str] = None):
self.name = name if name else str(uuid4().hex)
self.connection = connection
self.key = '{0}{1}'.format(self.REDIS_GROUP_NAME_PREFIX, self.name)
Expand Down
Loading

0 comments on commit ec0a85a

Please sign in to comment.