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
A followup to the issue presented in #6953, I'm running into mypy errors when implementing a cache using the mechanism as defined in the cachetools documentation.
Argument "timer" to "TLRUCache" has incompatible type "Callable[[Optional[tzinfo]], datetime]"; expected "Callable[[], float]"
Workaround:
We can use time.monotonic instead of datetime.now, but:
- the example in the docs use datetime.now
- datetime.now is arguably more familiar to most developers
I've have a similar problem with the ttl variable. Maybe my own incompetance but I couldn't get my tests with freezegun working with time.monotonic. Made the switch and can write the tests no problem but currently haven't to supress lint warnings for using timedelta instead of float.
Activity
Akuli commentedon Aug 1, 2022
Arguably
time.monotonic()would be better for some applications, becausedatetime.now()can go backwards. But I agree that both should be supported.michaeljpeake commentedon Apr 18, 2023
I've have a similar problem with the
ttlvariable. Maybe my own incompetance but I couldn't get my tests with freezegun working withtime.monotonic. Made the switch and can write the tests no problem but currently haven't to supress lint warnings for usingtimedeltainstead of float.