Skip to content

Commit

Permalink
Add flake8 to linters and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
grantjenks committed Aug 23, 2020
1 parent 4497cfc commit 8e0f545
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
6 changes: 4 additions & 2 deletions diskcache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"""

from .core import Cache, Disk, EmptyDirWarning, JSONDisk, UnknownFileWarning, Timeout
from .core import (
Cache, Disk, EmptyDirWarning, JSONDisk, UnknownFileWarning, Timeout
)
from .core import DEFAULT_SETTINGS, ENOVAL, EVICTION_POLICY, UNKNOWN
from .fanout import FanoutCache
from .persistent import Deque, Index
Expand Down Expand Up @@ -37,7 +39,7 @@
]

try:
from .djangocache import DjangoCache # pylint: disable=wrong-import-position
from .djangocache import DjangoCache # noqa
__all__.append('DjangoCache')
except Exception: # pylint: disable=broad-except
# Django not installed or not setup so ignore.
Expand Down
22 changes: 15 additions & 7 deletions diskcache/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@
import pickletools
import sqlite3
import struct
import sys
import tempfile
import threading
import time
import warnings
import zlib


def full_name(func):
"Return full name of `func` by adding the module and function name."
return func.__module__ + '.' + func.__qualname__


try:
WindowsError
except NameError:
class WindowsError(Exception):
"Windows error place-holder on platforms without support."


class Constant(tuple):
"Pretty display of immutable constant."
def __new__(cls, name):
Expand All @@ -39,6 +41,7 @@ def __new__(cls, name):
def __repr__(self):
return '%s' % self[0]


DBNAME = 'cache.db'
ENOVAL = Constant('ENOVAL')
UNKNOWN = Constant('UNKNOWN')
Expand Down Expand Up @@ -133,7 +136,7 @@ def hash(self, key):
if type_disk_key is sqlite3.Binary:
return zlib.adler32(disk_key) & mask
elif type_disk_key is str:
return zlib.adler32(disk_key.encode('utf-8')) & mask # pylint: disable=no-member
return zlib.adler32(disk_key.encode('utf-8')) & mask # noqa
elif type_disk_key is int:
return disk_key % mask
else:
Expand Down Expand Up @@ -1056,7 +1059,9 @@ def incr(self, key, delta=1, default=0, retry=False):
raise KeyError(key)

value = default + delta
columns = (None, None) + self._disk.store(value, False, key=key)
columns = (
(None, None) + self._disk.store(value, False, key=key)
)
self._row_insert(db_key, raw, now, columns)
self._cull(now, sql, cleanup)
return value
Expand All @@ -1068,7 +1073,9 @@ def incr(self, key, delta=1, default=0, retry=False):
raise KeyError(key)

value = default + delta
columns = (None, None) + self._disk.store(value, False, key=key)
columns = (
(None, None) + self._disk.store(value, False, key=key)
)
self._row_update(rowid, now, columns)
self._cull(now, sql, cleanup)
cleanup(filename)
Expand Down Expand Up @@ -1184,7 +1191,7 @@ def get(self, key, default=None, read=False, expire_time=False, tag=False,
return default

(rowid, db_expire_time, db_tag,
mode, filename, db_value), = rows
mode, filename, db_value), = rows # noqa: E127

try:
value = self._disk.fetch(mode, filename, db_value, read)
Expand Down Expand Up @@ -1269,7 +1276,7 @@ def __contains__(self, key):
return bool(rows)


def pop(self, key, default=None, expire_time=False, tag=False, retry=False):
def pop(self, key, default=None, expire_time=False, tag=False, retry=False): # noqa: E501
"""Remove corresponding item for `key` from cache and return value.
If `key` is missing, return `default`.
Expand Down Expand Up @@ -2341,7 +2348,8 @@ def close(self):

def __enter__(self):
# Create connection in thread.
connection = self._con # pylint: disable=unused-variable
# pylint: disable=unused-variable
connection = self._con # noqa
return self


Expand Down
3 changes: 1 addition & 2 deletions diskcache/fanout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import operator
import os.path as op
import sqlite3
import sys
import tempfile
import time

Expand Down Expand Up @@ -290,7 +289,7 @@ def __contains__(self, key):
return key in shard


def pop(self, key, default=None, expire_time=False, tag=False, retry=False):
def pop(self, key, default=None, expire_time=False, tag=False, retry=False): # noqa: E501
"""Remove corresponding item for `key` from cache and return value.
If `key` is missing, return `default`.
Expand Down
5 changes: 3 additions & 2 deletions diskcache/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ def __setitem__(self, index, value):
:raises IndexError: if index out of range
"""
set_value = lambda key: self._cache.__setitem__(key, value)
self._index(index, set_value)
def _set_value(key):
return self._cache.__setitem__(key, value)
self._index(index, _set_value)


def __delitem__(self, index):
Expand Down
7 changes: 5 additions & 2 deletions diskcache/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import math
import os
import random
import sys
import threading
import time

Expand Down Expand Up @@ -82,7 +81,11 @@ def acquire(self):
"Acquire lock using spin-lock algorithm."
while True:
added = self._cache.add(
self._key, None, expire=self._expire, tag=self._tag, retry=True,
self._key,
None,
expire=self._expire,
tag=self._tag,
retry=True,
)
if added:
break
Expand Down
13 changes: 11 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ deps=
pytest-django
pytest-xdist
commands=python -m pytest
setenv =
setenv=
DJANGO_SETTINGS_MODULE=tests.settings
PYTHONPATH={toxinidir}

Expand All @@ -27,8 +27,17 @@ testpaths=docs diskcache tests
[testenv:pylint]
deps=
django==2.2.*
flake8
pylint
commands=pylint diskcache
commands=
flake8 diskcache
pylint diskcache

[doc8]
ignore=D000

[flake8]
ignore=
E124
E303
W503

0 comments on commit 8e0f545

Please sign in to comment.