Skip to content

Commit ab1484d

Browse files
committed
Blue fixes (mostly docstring triple quotes)
1 parent a2e461a commit ab1484d

25 files changed

+80
-92
lines changed

diskcache/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
=======================
44
55
The :doc:`tutorial` provides a helpful walkthrough of most methods.
6-
76
"""
87

98
from .core import (

diskcache/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"Command line interface to disk cache."
1+
"""Command line interface to disk cache."""

diskcache/core.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Core disk and file backed cache API.
2-
32
"""
43

54
import codecs
@@ -22,12 +21,12 @@
2221

2322

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

2827

2928
class Constant(tuple):
30-
"Pretty display of immutable constant."
29+
"""Pretty display of immutable constant."""
3130

3231
def __new__(cls, name):
3332
return tuple.__new__(cls, (name,))
@@ -102,7 +101,7 @@ def __repr__(self):
102101

103102

104103
class Disk:
105-
"Cache key and value serialization for SQLite database and files."
104+
"""Cache key and value serialization for SQLite database and files."""
106105

107106
def __init__(self, directory, min_file_size=0, pickle_protocol=0):
108107
"""Initialize disk instance.
@@ -333,7 +332,7 @@ def remove(self, file_path):
333332

334333

335334
class JSONDisk(Disk):
336-
"Cache key and value using JSON serialization with zlib compression."
335+
"""Cache key and value using JSON serialization with zlib compression."""
337336

338337
def __init__(self, directory, compress_level=1, **kwargs):
339338
"""Initialize JSON disk instance.
@@ -374,15 +373,15 @@ def fetch(self, mode, filename, value, read):
374373

375374

376375
class Timeout(Exception):
377-
"Database timeout expired."
376+
"""Database timeout expired."""
378377

379378

380379
class UnknownFileWarning(UserWarning):
381-
"Warning used by Cache.check for unknown files."
380+
"""Warning used by Cache.check for unknown files."""
382381

383382

384383
class EmptyDirWarning(UserWarning):
385-
"Warning used by Cache.check for empty directories."
384+
"""Warning used by Cache.check for empty directories."""
386385

387386

388387
def args_to_key(base, args, kwargs, typed):
@@ -414,7 +413,7 @@ def args_to_key(base, args, kwargs, typed):
414413

415414

416415
class Cache:
417-
"Disk and file backed cache."
416+
"""Disk and file backed cache."""
418417

419418
def __init__(self, directory=None, timeout=60, disk=Disk, **settings):
420419
"""Initialize cache instance.
@@ -1859,12 +1858,12 @@ def memoize(self, name=None, typed=False, expire=None, tag=None):
18591858
raise TypeError('name cannot be callable')
18601859

18611860
def decorator(func):
1862-
"Decorator created by memoize() for callable `func`."
1861+
"""Decorator created by memoize() for callable `func`."""
18631862
base = (full_name(func),) if name is None else (name,)
18641863

18651864
@ft.wraps(func)
18661865
def wrapper(*args, **kwargs):
1867-
"Wrapper for callable to cache arguments and return values."
1866+
"""Wrapper for callable to cache arguments and return values."""
18681867
key = wrapper.__cache_key__(*args, **kwargs)
18691868
result = self.get(key, default=ENOVAL, retry=True)
18701869

@@ -1876,7 +1875,7 @@ def wrapper(*args, **kwargs):
18761875
return result
18771876

18781877
def __cache_key__(*args, **kwargs):
1879-
"Make key for cache given function arguments."
1878+
"""Make key for cache given function arguments."""
18801879
return args_to_key(base, args, kwargs, typed)
18811880

18821881
wrapper.__cache_key__ = __cache_key__
@@ -2291,13 +2290,13 @@ def _iter(self, ascending=True):
22912290
yield _disk_get(key, raw)
22922291

22932292
def __iter__(self):
2294-
"Iterate keys in cache including expired items."
2293+
"""Iterate keys in cache including expired items."""
22952294
iterator = self._iter()
22962295
next(iterator)
22972296
return iterator
22982297

22992298
def __reversed__(self):
2300-
"Reverse iterate keys in cache including expired items."
2299+
"""Reverse iterate keys in cache including expired items."""
23012300
iterator = self._iter(ascending=False)
23022301
next(iterator)
23032302
return iterator
@@ -2355,7 +2354,7 @@ def __exit__(self, *exception):
23552354
self.close()
23562355

23572356
def __len__(self):
2358-
"Count of items in cache including expired items."
2357+
"""Count of items in cache including expired items."""
23592358
return self.reset('count')
23602359

23612360
def __getstate__(self):

diskcache/djangocache.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"Django-compatible disk and file backed cache."
1+
"""Django-compatible disk and file backed cache."""
22

33
from functools import wraps
44

@@ -15,7 +15,7 @@
1515

1616

1717
class DjangoCache(BaseCache):
18-
"Django-compatible disk and file backed cache."
18+
"""Django-compatible disk and file backed cache."""
1919

2020
def __init__(self, directory, params):
2121
"""Initialize DjangoCache instance.
@@ -344,11 +344,11 @@ def cull(self):
344344
return self._cache.cull()
345345

346346
def clear(self):
347-
"Remove *all* values from the cache at once."
347+
"""Remove *all* values from the cache at once."""
348348
return self._cache.clear()
349349

350350
def close(self, **kwargs):
351-
"Close the cache connection."
351+
"""Close the cache connection."""
352352
# pylint: disable=unused-argument
353353
self._cache.close()
354354

@@ -415,12 +415,12 @@ def memoize(
415415
raise TypeError('name cannot be callable')
416416

417417
def decorator(func):
418-
"Decorator created by memoize() for callable `func`."
418+
"""Decorator created by memoize() for callable `func`."""
419419
base = (full_name(func),) if name is None else (name,)
420420

421421
@wraps(func)
422422
def wrapper(*args, **kwargs):
423-
"Wrapper for callable to cache arguments and return values."
423+
"""Wrapper for callable to cache arguments and return values."""
424424
key = wrapper.__cache_key__(*args, **kwargs)
425425
result = self.get(key, ENOVAL, version, retry=True)
426426

@@ -444,7 +444,7 @@ def wrapper(*args, **kwargs):
444444
return result
445445

446446
def __cache_key__(*args, **kwargs):
447-
"Make key for cache given function arguments."
447+
"""Make key for cache given function arguments."""
448448
return args_to_key(base, args, kwargs, typed)
449449

450450
wrapper.__cache_key__ = __cache_key__

diskcache/fanout.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"Fanout cache automatically shards keys and values."
1+
"""Fanout cache automatically shards keys and values."""
22

33
import contextlib as cl
44
import functools
@@ -14,7 +14,7 @@
1414

1515

1616
class FanoutCache:
17-
"Cache that shards keys and values."
17+
"""Cache that shards keys and values."""
1818

1919
def __init__(
2020
self, directory=None, shards=8, timeout=0.010, disk=Disk, **settings
@@ -512,7 +512,7 @@ def volume(self):
512512
return sum(shard.volume() for shard in self._shards)
513513

514514
def close(self):
515-
"Close database connection."
515+
"""Close database connection."""
516516
for shard in self._shards:
517517
shard.close()
518518
self._caches.clear()
@@ -532,17 +532,17 @@ def __setstate__(self, state):
532532
self.__init__(*state)
533533

534534
def __iter__(self):
535-
"Iterate keys in cache including expired items."
535+
"""Iterate keys in cache including expired items."""
536536
iterators = (iter(shard) for shard in self._shards)
537537
return it.chain.from_iterable(iterators)
538538

539539
def __reversed__(self):
540-
"Reverse iterate keys in cache including expired items."
540+
"""Reverse iterate keys in cache including expired items."""
541541
iterators = (reversed(shard) for shard in reversed(self._shards))
542542
return it.chain.from_iterable(iterators)
543543

544544
def __len__(self):
545-
"Count of items in cache including expired items."
545+
"""Count of items in cache including expired items."""
546546
return sum(len(shard) for shard in self._shards)
547547

548548
def reset(self, key, value=ENOVAL):

diskcache/persistent.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Persistent Data Types
2-
32
"""
43

54
import operator as op
@@ -18,10 +17,10 @@
1817

1918

2019
def _make_compare(seq_op, doc):
21-
"Make compare method with Sequence semantics."
20+
"""Make compare method with Sequence semantics."""
2221

2322
def compare(self, that):
24-
"Compare method for deque and sequence."
23+
"""Compare method for deque and sequence."""
2524
if not isinstance(that, Sequence):
2625
return NotImplemented
2726

@@ -117,12 +116,12 @@ def fromcache(cls, cache, iterable=()):
117116

118117
@property
119118
def cache(self):
120-
"Cache used by deque."
119+
"""Cache used by deque."""
121120
return self._cache
122121

123122
@property
124123
def directory(self):
125-
"Directory path where deque is stored."
124+
"""Directory path where deque is stored."""
126125
return self._cache.directory
127126

128127
def _index(self, index, func):
@@ -699,12 +698,12 @@ def fromcache(cls, cache, *args, **kwargs):
699698

700699
@property
701700
def cache(self):
702-
"Cache used by index."
701+
"""Cache used by index."""
703702
return self._cache
704703

705704
@property
706705
def directory(self):
707-
"Directory path where items are stored."
706+
"""Directory path where items are stored."""
708707
return self._cache.directory
709708

710709
def __getitem__(self, key):

diskcache/recipes.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Disk Cache Recipes
2-
32
"""
43

54
import functools
@@ -40,7 +39,7 @@ def __init__(self, cache, key, expire=None, tag=None):
4039
self._tag = tag
4140

4241
def add(self, value):
43-
"Add `value` to average."
42+
"""Add `value` to average."""
4443
with self._cache.transact(retry=True):
4544
total, count = self._cache.get(self._key, default=(0.0, 0))
4645
total += value
@@ -53,12 +52,12 @@ def add(self, value):
5352
)
5453

5554
def get(self):
56-
"Get current average or return `None` if count equals zero."
55+
"""Get current average or return `None` if count equals zero."""
5756
total, count = self._cache.get(self._key, default=(0.0, 0), retry=True)
5857
return None if count == 0 else total / count
5958

6059
def pop(self):
61-
"Return current average and delete key."
60+
"""Return current average and delete key."""
6261
total, count = self._cache.pop(self._key, default=(0.0, 0), retry=True)
6362
return None if count == 0 else total / count
6463

@@ -83,7 +82,7 @@ def __init__(self, cache, key, expire=None, tag=None):
8382
self._tag = tag
8483

8584
def acquire(self):
86-
"Acquire lock using spin-lock algorithm."
85+
"""Acquire lock using spin-lock algorithm."""
8786
while True:
8887
added = self._cache.add(
8988
self._key,
@@ -97,11 +96,11 @@ def acquire(self):
9796
time.sleep(0.001)
9897

9998
def release(self):
100-
"Release lock by deleting key."
99+
"""Release lock by deleting key."""
101100
self._cache.delete(self._key, retry=True)
102101

103102
def locked(self):
104-
"Return true if the lock is acquired."
103+
"""Return true if the lock is acquired."""
105104
return self._key in self._cache
106105

107106
def __enter__(self):
@@ -137,7 +136,7 @@ def __init__(self, cache, key, expire=None, tag=None):
137136
self._tag = tag
138137

139138
def acquire(self):
140-
"Acquire lock by incrementing count using spin-lock algorithm."
139+
"""Acquire lock by incrementing count using spin-lock algorithm."""
141140
pid = os.getpid()
142141
tid = threading.get_ident()
143142
pid_tid = '{}-{}'.format(pid, tid)
@@ -156,7 +155,7 @@ def acquire(self):
156155
time.sleep(0.001)
157156

158157
def release(self):
159-
"Release lock by decrementing count."
158+
"""Release lock by decrementing count."""
160159
pid = os.getpid()
161160
tid = threading.get_ident()
162161
pid_tid = '{}-{}'.format(pid, tid)
@@ -206,7 +205,7 @@ def __init__(self, cache, key, value=1, expire=None, tag=None):
206205
self._tag = tag
207206

208207
def acquire(self):
209-
"Acquire semaphore by decrementing value using spin-lock algorithm."
208+
"""Acquire semaphore by decrementing value using spin-lock algorithm."""
210209
while True:
211210
with self._cache.transact(retry=True):
212211
value = self._cache.get(self._key, default=self._value)
@@ -221,7 +220,7 @@ def acquire(self):
221220
time.sleep(0.001)
222221

223222
def release(self):
224-
"Release semaphore by incrementing value."
223+
"""Release semaphore by incrementing value."""
225224
with self._cache.transact(retry=True):
226225
value = self._cache.get(self._key, default=self._value)
227226
assert self._value > value, 'cannot release un-acquired semaphore'
@@ -396,19 +395,19 @@ def memoize_stampede(cache, expire, name=None, typed=False, tag=None, beta=1):
396395
"""
397396
# Caution: Nearly identical code exists in Cache.memoize
398397
def decorator(func):
399-
"Decorator created by memoize call for callable."
398+
"""Decorator created by memoize call for callable."""
400399
base = (full_name(func),) if name is None else (name,)
401400

402401
def timer(*args, **kwargs):
403-
"Time execution of `func` and return result and time delta."
402+
"""Time execution of `func` and return result and time delta."""
404403
start = time.time()
405404
result = func(*args, **kwargs)
406405
delta = time.time() - start
407406
return result, delta
408407

409408
@functools.wraps(func)
410409
def wrapper(*args, **kwargs):
411-
"Wrapper for callable to cache arguments and return values."
410+
"""Wrapper for callable to cache arguments and return values."""
412411
key = wrapper.__cache_key__(*args, **kwargs)
413412
pair, expire_time = cache.get(
414413
key,
@@ -459,7 +458,7 @@ def recompute():
459458
return pair[0]
460459

461460
def __cache_key__(*args, **kwargs):
462-
"Make key for cache given function arguments."
461+
"""Make key for cache given function arguments."""
463462
return args_to_key(base, args, kwargs, typed)
464463

465464
wrapper.__cache_key__ = __cache_key__

0 commit comments

Comments
 (0)