Skip to content

Conversation

@enzo-santos
Copy link

This PR adds typing support to filecache, turning it into a type-safe library.

It is type-checked using mypy:

$ python -m mypy --version
mypy 1.6.0 (compiled: yes)
$ python -m mypy filecache
Success: no issues found in 3 source files

It also passes all tests:

$ python -m filecache.test.test_filecache
\filecache\filecache\test\test_filecache.py:5: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
  import imp
erasing \filecache\filecache\test\stub_for_test.py.cache.bak
erasing \filecache\filecache\test\stub_for_test.py.cache.dat
erasing \filecache\filecache\test\stub_for_test.py.cache.dir
erasing \filecache\filecache\test\test_filecache.py.cache.bak
erasing \filecache\filecache\test\test_filecache.py.cache.dat
erasing \filecache\filecache\test\test_filecache.py.cache.dir
erasing \filecache\_lt_string_gt_.cache.bak
erasing \filecache\_lt_string_gt_.cache.dat
erasing \filecache\_lt_string_gt_.cache.dir
.........
----------------------------------------------------------------------
Ran 9 tests in 0.807s

OK

This implementation transfers all the caching logic into the CachedFileCacheCallable class, which is callable and acts like a function. This makes the filecache decorator a lot more clean.

The typing implementation is based on https://github.com/maxfischer2781/asyncstdlib/blob/master/asyncstdlib/_lrucache.pyi. It makes the filecache decorator type-check on both plain functions and methods.

Feel free to change as desired, specially variable naming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant