Import problems with cachetools.keys, is "keys" missing in __init__.py
Closed this issue · 1 comments
timrichardson commented
there is an example in the docs https://cachetools.readthedocs.io/en/stable/
from cachetools.keys import hashkey
from threading import Lock
cache = LRUCache(maxsize=32)
lock = Lock()
@cached(cache, key=hashkey, lock=lock)
def get_pep(num):
'Retrieve text of a Python Enhancement Proposal'
url = 'http://www.python.org/dev/peps/pep-%04d/' % num
with urllib.request.urlopen(url) as s:
return s.read()
but the import line from cachetools.keys import hashkey
throws a linting error in my IDE.
I am not very well versed in python modules, but I wonder if __init__.py
should have "keys" in __all__
, which is currently:
"""Extensible memoizing collections and decorators."""
from .cache import Cache
from .decorators import cached, cachedmethod
from .lfu import LFUCache
from .lru import LRUCache
from .rr import RRCache
from .ttl import TTLCache
__all__ = (
'Cache',
'LFUCache',
'LRUCache',
'RRCache',
'TTLCache',
'cached',
'cachedmethod'
)
__version__ = '4.1.1'
tkem commented
@timrichardson: Sorry for the delay. I don't know about your IDE, but running python3
from cachetools.keys import hashkey
does not show any errors for me.
cachetools.keys
is a separate sub-module and should be imported as such, mostly for future extensions.
__all__
is used for from cachetools import *
, and probably has nothing to do with your issue.