You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please add type information to the library (mypy) #202
As this is a library, it would prove very useful to start adding type information to it, so we can rely on it.
# mypy
error: Skipping analyzing 'diskcache': found module but no type hints or library stubs
I personally prefer inline type instead of stubs but that would require bumping minimal python to required to 3.6 in order to be practical to implement (should not be an issue considering it already reached EOL).
How would you type the “key” and “value” parameters in the API? I think they would have to be Any which would pretty well defeat the type checker. There may be a flexible solution using generics but that also likely makes some assumptions.
Until PEP 585 becomes the minimum version (Python 3.9), I’d prefer for typing to remain in stub files. The typing imports and annotation are otherwise a bit verbose and distracting.
I’m not eager to add types myself but I wouldn’t oppose someone creating type stubs in a typeshed like diskcache-typing. It may be a nice way to get started.
I'm fine with someone contributing type stubs to a separate project (e.g. typing-diskcache) but I'm not planning to add types myself anytime soon (nor do I want to support them in this package if someone were to add them).
Activity
grantjenks commentedon Apr 13, 2021
How would you type the “key” and “value” parameters in the API? I think they would have to be Any which would pretty well defeat the type checker. There may be a flexible solution using generics but that also likely makes some assumptions.
Until PEP 585 becomes the minimum version (Python 3.9), I’d prefer for typing to remain in stub files. The typing imports and annotation are otherwise a bit verbose and distracting.
I’m not eager to add types myself but I wouldn’t oppose someone creating type stubs in a typeshed like diskcache-typing. It may be a nice way to get started.
grantjenks commentedon Apr 13, 2021
Related question: how important is typing in your workflow? Is it a feature that you’d pay for?
grantjenks commentedon Sep 14, 2021
I'm fine with someone contributing type stubs to a separate project (e.g. typing-diskcache) but I'm not planning to add types myself anytime soon (nor do I want to support them in this package if someone were to add them).
johnraz commentedon Nov 18, 2022
@grantjenks considering the increasing adoption of typing in Python, would you be open to re-open this (pun intended 😝 ) ?
Thanks 🙂
phi-friday commentedon Mar 16, 2024
I created
diskcache-stubs.It's still incomplete, but it works.
CNSeniorious000 commentedon Nov 29, 2024
Hi @phi-friday, aftering reviewing
diskcache-stubs, I found it didn't support generic typing like this:So I did some static typing and committed them in a separated package
diskcache2:Now this works:
Type Narrowing
I worked really hard into flattening the overloads for functions like
Cache.get()andCache.pull(). Look at these type narrowing results!!