Skip to content

Commit

Permalink
Started typing codebase (#451)
Browse files Browse the repository at this point in the history
* Typed serializers

* More typing in serializers and typed compressors

* Typed CacheKey and removed unused Union

* Sorted inputs

* Restored init method of BaseSerializer

* Added type hints for DefaultClient

* Blacked DefaultClient

* isorted imports in DefaultClient

* Update django_redis/serializers/pickle.py

Co-authored-by: Jon Dufresne <[email protected]>

* More typing in default client

* Ignored type of lzma import

* Started typing cache and pool

* Solved some mypy errors and little refactoring especially on tried argument

* black formatted the arguments indentation

* Added some typing HashRing and resolved an error of mypy in DefaultClient

* Removed unusued import in default.py

* Ditched relative imports in client/default.py

* Finally black and isort are happy after merge

* Restored relative imports in client/default.py

* Resolved merge conflict in lz4 and rebased against master

* Added django-stubs to lint dependencies

* Ignoring typing of lz4

* Fixed sentinel typing

* Fixed isort for pool.py

* Many new types and fixed types. Moved # tyep: ignore to setup.cfg

* adjust mypy config

* upload mypy coverage to codecov.io

* set flags on the codecov.io upload

* add minimal codecov.yml configuration

* only upload coverage for mypy lint task

* Typed serializers

* More typing in serializers and typed compressors

* Typed CacheKey and removed unused Union

* Sorted inputs

* Restored init method of BaseSerializer

* Added type hints for DefaultClient

* Blacked DefaultClient

* isorted imports in DefaultClient

* Update django_redis/serializers/pickle.py

Co-authored-by: Jon Dufresne <[email protected]>

* More typing in default client

* Ignored type of lzma import

* Started typing cache and pool

* Solved some mypy errors and little refactoring especially on tried argument

* black formatted the arguments indentation

* Added some typing HashRing and resolved an error of mypy in DefaultClient

* Removed unusued import in default.py

* Ditched relative imports in client/default.py

* Finally black and isort are happy after merge

* Restored relative imports in client/default.py

* Resolved merge conflict in lz4 and rebased against master

* Added django-stubs to lint dependencies

* Ignoring typing of lz4

* Fixed sentinel typing

* Fixed isort for pool.py

* Many new types and fixed types. Moved # tyep: ignore to setup.cfg

* More types in hash ring

* Removed redundant parenthesis

* Fixed Iterator

* Made black happy

* Added more types to hashring

Co-authored-by: Jon Dufresne <[email protected]>
Co-authored-by: Terence D. Honles <[email protected]>
  • Loading branch information
3 people authored Apr 30, 2021
1 parent e5e8342 commit b1a68e0
Show file tree
Hide file tree
Showing 22 changed files with 271 additions and 107 deletions.
14 changes: 14 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
coverage:
status:
project:
default:
target: auto
mypy:
target: auto
flags:
- mypy

tests:
target: auto
flags:
- tests
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
uses: codecov/codecov-action@v1
with:
env_vars: DJANGO,REDIS,PYTHON
flags: tests
env:
DJANGO: ${{ matrix.django-version }}
REDIS: ${{ matrix.redis-version }}
Expand All @@ -105,6 +106,7 @@ jobs:
- 'black'
- 'flake8'
- 'isort'
- 'mypy'

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -132,5 +134,11 @@ jobs:
python -m pip install --upgrade pip
python -m pip install --upgrade tox
- name: Run
- name: Run ${{ matrix.tool }}
run: tox -e ${{ matrix.tool }}

- name: Upload coverage
if: ${{ matrix.tool == 'mypy' }}
uses: codecov/codecov-action@v1
with:
flags: mypy
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ dump.rdb
.venv
.coverage
coverage.xml
cobertura.xml
7 changes: 5 additions & 2 deletions django_redis/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import logging
from typing import Any, Callable, Dict, Optional

from django import VERSION as DJANGO_VERSION
from django.conf import settings
Expand All @@ -13,7 +14,9 @@
CONNECTION_INTERRUPTED = object()


def omit_exception(method=None, return_value=None):
def omit_exception(
method: Optional[Callable] = None, return_value: Optional[Any] = None
):
"""
Simple decorator that intercepts connection
errors and ignores these if settings specify this.
Expand All @@ -38,7 +41,7 @@ def _decorator(self, *args, **kwargs):


class RedisCache(BaseCache):
def __init__(self, server, params):
def __init__(self, server: str, params: Dict[str, Any]) -> None:
super().__init__(params)
self._server = server
self._params = params
Expand Down
Loading

0 comments on commit b1a68e0

Please sign in to comment.